plot_augment

wield.control.fitting.SISO.plots.plot_augment

This is a pytest module needing documentation

pytest-html report

Functions

angle_cutter(F_Hz, data[, deg, semiroll])

This is a pytest needing documentation

plot_augment_data(self[, ax_mag, ax_phase, ...])

This is a pytest needing documentation

plot_augment_fit(self, ax_mag, ax_phase, ...)

This is a pytest needing documentation

plot_augment_residuals(self, ax_mag, ...[, ...])

This is a pytest needing documentation

plot_augment_zp(self, ax)

This is a pytest needing documentation

Details

angle_cutter(F_Hz, data, deg=False, semiroll=False)[source][github]

This is a pytest needing documentation

code
 1def angle_cutter(
 2    F_Hz,
 3    data,
 4    deg=False,
 5    semiroll=False,
 6):
 7    F_Hz, data = domain_sort(F_Hz, data)
 8    ang = np.angle(data)
 9
10    above = ang > np.pi / 2
11    below = ang < -np.pi / 2
12    jumps = (above[:-1] & below[1:]) | (below[:-1] & above[1:])
13
14    jump_locs = np.nonzero(jumps)[0]
15
16    if semiroll:
17        for idx1, idx2 in zip(jump_locs[:-1] + 1, jump_locs[1:]):
18            if np.all(above[idx1:idx2]):
19                ang[idx1:idx2] -= np.pi
20            elif np.all(below[idx1:idx2]):
21                ang[idx1:idx2] += np.pi
22            else:
23                # it is crossing, do nothing
24                pass
25
26    ins_locs = jump_locs + 1
27    ins_F_Hz = (F_Hz[jump_locs] + F_Hz[jump_locs]) / 2
28    F_Hz = np.insert(F_Hz, ins_locs, ins_F_Hz)
29    if deg:
30        ang = ang * 180 / np.pi
31    ang = np.insert(ang, ins_locs, np.nan)
32    return (F_Hz, ang)
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.fitting.SISO.plots.plot_augment.angle_cutter

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

plot_augment_data(self, ax_mag=None, ax_phase=None, data_list=[], with_error=True, label=(<function argscan>, 'UNSPECIFIED'), markersize=3, marker='.', linestyle='', residuals=False, **kwargs)[source][github]

This is a pytest needing documentation

code
  1def plot_augment_data(
  2    self,
  3    ax_mag=None,
  4    ax_phase=None,
  5    data_list=[],
  6    with_error=True,
  7    label=args.UNSPEC,
  8    markersize=3,
  9    marker=".",
 10    linestyle="",
 11    residuals=False,
 12    **kwargs
 13):
 14    label_default = args.argscan(label, self.label_data, "data")
 15
 16    def plot(fitter, label=None, db_ref=None, color=None, **kwargs):
 17        if label is None:
 18            label = label_default
 19        db = Bunch()
 20        db.rep = fitter
 21
 22        if color is None and db_ref is not None:
 23            color = db_ref.mline.get_color()
 24
 25        if marker is not None:
 26            kwargs["marker"] = marker
 27        if markersize is not None:
 28            kwargs["markersize"] = markersize
 29        if linestyle is not None:
 30            kwargs["linestyle"] = linestyle
 31
 32        f = fitter.F_Hz
 33        if not residuals:
 34            h = fitter.data
 35        else:
 36            h = fitter.data / fitter.xfer_fit
 37        if with_error:
 38            W = 0.001 + fitter.W
 39            select = f > 0
 40            if not residuals:
 41                db.min_data_err_lim = np.min(abs(h)) * max(1 / 3, np.min(1 / (1 + 1 / W)))
 42                db.max_data_err_lim = np.max(abs(h)) * min(3, np.max((1 + 1 / W)))
 43            else:
 44                db.min_data_err_lim = np.min(abs(h)) / 1.01
 45                db.max_data_err_lim = np.max(abs(h)) * 1.01
 46            if ax_mag:
 47                # ax_mag.fill_between(
 48                #    fitter.F_Hz[select],
 49                #    np.maximum((abs(h) / (1 + 1 / W))[select], np.min(abs(h)) / 100),
 50                #    np.minimum((abs(h) * (1 + 1 / W))[select], np.max(abs(h)) * 100),
 51                #    color = color,
 52                #    alpha = .2,
 53                #    **kwargs
 54                # )
 55                abs_h = abs(h)
 56                ax_mag.errorbar(
 57                    fitter.F_Hz[select],
 58                    abs_h[select],
 59                    yerr=(
 60                        abs_h[select]
 61                        - np.maximum(
 62                            (abs_h / (1 + 1 / W))[select], np.min(abs_h[select]) / 100
 63                        ),
 64                        np.minimum(
 65                            (abs_h * (1 + 1 / W))[select], np.max(abs_h[select]) * 100
 66                        )
 67                        - abs_h[select],
 68                    ),
 69                    color=color,
 70                    label=label,
 71                    **kwargs
 72                )
 73            if ax_phase:
 74                angle_h = np.angle(h, deg=True)
 75                ax_phase.errorbar(
 76                    f[select],
 77                    angle_h[select],
 78                    (
 79                        angle_h[select]
 80                        - np.maximum((angle_h - 180 / np.pi / W)[select], -180),
 81                        np.minimum((angle_h + 180 / np.pi / W)[select], 180)
 82                        - angle_h[select],
 83                    ),
 84                    color=color,
 85                    label=label,
 86                    **kwargs
 87                )
 88                # ax_phase.fill_between(
 89                #    f[select],
 90                #    np.minimum((np.angle(h, deg = True) + 180/np.pi / W)[select], 180),
 91                #    np.maximum((np.angle(h, deg = True) - 180/np.pi / W)[select], -180),
 92                #    color = color,
 93                #    alpha = .2,
 94                #    **kwargs
 95                # )
 96        else:
 97            if ax_mag:
 98                db.mline = ax_mag.plot(
 99                    fitter.F_Hz, abs(h), label=label, **kwargs
100                )[0]
101
102                if color is None:
103                    color = db.mline.get_color()
104
105            if ax_phase:
106                _f, _h = angle_cutter(fitter.F_Hz, h, deg=True)
107                db.pline = ax_phase.semilogx(
108                    _f, _h, label=label, color=color, **kwargs
109                )[0]
110
111            if not residuals:
112                db.min_data_err_lim = np.min(abs(h)) / 1.2
113                db.max_data_err_lim = np.max(abs(h)) * 1.2
114            else:
115                db.min_data_err_lim = np.min(abs(h)) / 1.01
116                db.max_data_err_lim = np.max(abs(h)) * 1.01
117
118        midpt = (np.max(fitter.F_Hz) - np.min(fitter.F_Hz)) / 2
119        if np.count_nonzero(fitter.F_Hz < midpt) < 0.65 * len(fitter.F_Hz):
120            db.scale_log = False
121        else:
122            db.scale_log = True
123
124        db.maxF_Hz = max(f)
125        db.minF_Hz = min(f)
126        select = f > 0
127        db.minF_HzNZ = min(f[select])
128        if not residuals:
129            ax_mag.set_yscale('log_zoom')
130        else:
131            ax_mag.set_yscale('log_zoom')
132
133        data_list.append(db)
134        return db
135
136    return plot
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.fitting.SISO.plots.plot_augment.plot_augment_data

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

plot_augment_fit(self, ax_mag, ax_phase, fit_list, with_error=False, F_Hz=None, residuals=False, label=(<function argscan>, 'UNSPECIFIED'))[source][github]

This is a pytest needing documentation

code
  1def plot_augment_fit(
  2    self,
  3    ax_mag,
  4    ax_phase,
  5    fit_list,
  6    with_error=False,
  7    F_Hz=None,
  8    residuals=False,
  9    label=args.UNSPEC,
 10):
 11    label_default = args.argscan(
 12        label, self.label_fit, "fit ({nP}P, {nZ}Z, Rsq ={Rsq:.3e})"
 13    )
 14
 15    def plot(fitter, label=None, db_ref=None, color=None, **kwargs):
 16        if label is None:
 17            label = label_default
 18        label = label.format(
 19            nP=len(fitter.ZPKrep.poles),
 20            nZ=len(fitter.ZPKrep.zeros),
 21            Rsq=fitter.residuals_average,
 22        )
 23
 24        if color is None and db_ref is not None:
 25            color = db_ref.mline.get_color()
 26
 27        if F_Hz is not None:
 28            f = F_Hz
 29            h = fitter.xfer_eval(f)
 30        else:
 31            h = fitter.xfer_fit
 32            f = fitter.F_Hz
 33        if residuals:
 34            h[:] = 1
 35        db = Bunch()
 36
 37        db.mline = ax_mag.plot(f, abs(h), label=label, color=color, **kwargs)[0]
 38
 39        if color is None:
 40            color = db.mline.get_color()
 41
 42        if ax_phase:
 43
 44            _f, _h = angle_cutter(f, h, deg=True)
 45            db.pline = ax_phase.semilogx(_f, _h, label=label, color=color, **kwargs)
 46
 47        if with_error and isinstance(fitter, fitters_ZPK.MultiReprFilterZ):
 48            select = f > 0
 49            ax_mag.fill_between(
 50                f[select],
 51                np.maximum(
 52                    (abs(h) / (1 + fitter.xfer_fit_error.mag_rel2))[select],
 53                    np.min(abs(h)) / 10,
 54                ),
 55                np.minimum(
 56                    (abs(h) * (1 + fitter.xfer_fit_error.mag_rel2))[select],
 57                    np.max(abs(h)) * 10,
 58                ),
 59                color=db.mline.get_color(),
 60                alpha=0.3,
 61            )
 62            if ax_phase:
 63                ax_phase.fill_between(
 64                    f[select],
 65                    np.minimum(
 66                        (
 67                            np.angle(h, deg=True)
 68                            + 180 / np.pi * fitter.xfer_fit_error.phase
 69                        )[select],
 70                        180,
 71                    ),
 72                    np.maximum(
 73                        (
 74                            np.angle(h, deg=True)
 75                            - 180 / np.pi * fitter.xfer_fit_error.phase
 76                        )[select],
 77                        -180,
 78                    ),
 79                    color=db.pline[0].get_color(),
 80                    alpha=0.3,
 81                )
 82
 83                if not residuals:
 84                    db.min_fit_err_lim = np.min(abs(h)) * max(
 85                        1 / 3, np.min(1 / (1 + fitter.xfer_fit_error.mag_rel2)[select])
 86                    )
 87                    db.max_fit_err_lim = np.max(abs(h)) * min(
 88                        3, np.min((1 + fitter.xfer_fit_error.mag_rel2)[select])
 89                    )
 90                else:
 91                    db.min_fit_err_lim = np.min(abs(h)) / 1.01
 92                    db.max_fit_err_lim = np.max(abs(h)) * 1.01
 93        else:
 94            if not residuals:
 95                db.min_fit_err_lim = np.min(abs(h)) / 1.2
 96                db.max_fit_err_lim = np.max(abs(h)) * 1.2
 97            else:
 98                db.min_fit_err_lim = np.min(abs(h)) / 1.01
 99                db.max_fit_err_lim = np.max(abs(h)) * 1.01
100        db.median_fit_lim = np.median(abs(h))
101
102        midpt = (np.max(fitter.F_Hz) - np.min(fitter.F_Hz)) / 2
103        if np.count_nonzero(fitter.F_Hz < midpt) < 0.65 * len(fitter.F_Hz):
104            db.scale_log = False
105        else:
106            db.scale_log = True
107
108        db.maxF_Hz = max(f)
109        db.minF_Hz = min(f)
110        select = f > 0
111        db.minF_HzNZ = min(f[select])
112
113        fit_list.append(db)
114        return db
115
116    return plot
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.fitting.SISO.plots.plot_augment.plot_augment_fit

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

plot_augment_residuals(self, ax_mag, ax_phase, fit_list, label=(<function argscan>, 'UNSPECIFIED'))[source][github]

This is a pytest needing documentation

code
 1def plot_augment_residuals(
 2    self,
 3    ax_mag,
 4    ax_phase,
 5    fit_list,
 6    label=args.UNSPEC,
 7):
 8    label_default = args.argscan(
 9        label, self.label_fit, "fit ({nP}P, {nZ}Z, Rsq ={Rsq:.3e})"
10    )
11
12    def plot(
13        fitter, label=None, db_ref=None, color=None, markersize=3, marker=".", **kwargs
14    ):
15        if label is None:
16            label = label_default
17        label = label.format(
18            nP=len(fitter.ZPKrep.poles),
19            nZ=len(fitter.ZPKrep.zeros),
20            Rsq=fitter.residuals_average,
21        )
22
23        if color is None and db_ref is not None:
24            color = db_ref.mline.get_color()
25
26        r = fitter.residuals_preferred
27        f = fitter.F_Hz
28        db = Bunch()
29
30        if markersize is not None:
31            kwargs["s"] = markersize
32        db.mline = ax_mag.scatter(
33            f, abs(r), label=label, color=color, marker=marker, **kwargs
34        )
35        ax_mag.set_yscale("log_zoom")
36
37        if color is None:
38            color = db.mline.get_color()
39
40        if ax_phase:
41            _f, _r = angle_cutter(f, r, deg=True)
42            db.pline = ax_phase.scatter(
43                _f, _r, label=label, color=color, marker=marker, **kwargs
44            )
45
46        midpt = (np.max(f) - np.min(f)) / 2
47        if np.count_nonzero(f < midpt) < 0.65 * len(f):
48            db.scale_log = False
49        else:
50            db.scale_log = True
51
52        db.maxF_Hz = max(f)
53        db.minF_Hz = min(f)
54        select = f > 0
55        db.minF_HzNZ = min(f[select])
56
57        db.min_res_err_lim = np.min(abs(r)) / 1.2
58        db.max_res_err_lim = np.max(abs(r)) * 1.2
59        db.median_res_lim = np.median(abs(r))
60        fit_list.append(db)
61        return db
62
63    return plot
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.fitting.SISO.plots.plot_augment.plot_augment_residuals

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

plot_augment_zp(self, ax)[source][github]

This is a pytest needing documentation

code
  1def plot_augment_zp(self, ax):
  2    def plot(fitter):
  3        BWs = []
  4        ZPKrep = ZPKrep2Sf(fitter.ZPKrep)
  5        p = ZPKrep.poles.fullplane
  6        F = p.imag
  7        BW = p.real
  8        select = BW < 0
  9        ax.errorbar(
 10            F[select],
 11            -BW[select],
 12            xerr=-BW[select],
 13            color=self.poleID_color,
 14            lw=0.5,
 15            alpha=0.5,
 16            marker="None",
 17            ls="None",
 18        )
 19        ax.scatter(
 20            F[select],
 21            -BW[select],
 22            s=10,
 23            facecolor=self.poleID_color,
 24            linewidths=0.5,
 25            # edgecolors = 'black',
 26        )
 27        BWs.extend(-BW[select])
 28        ax.errorbar(
 29            F[~select],
 30            BW[~select],
 31            xerr=BW[~select],
 32            color=self.poleOD_color,
 33            lw=0.5,
 34            alpha=0.5,
 35            marker="None",
 36            ls="None",
 37        )
 38        ax.scatter(
 39            F[~select],
 40            BW[~select],
 41            s=10,
 42            facecolor=self.poleOD_color,
 43            linewidths=0.5,
 44            # edgecolors = 'black',
 45        )
 46        BWs.extend(BW[~select])
 47
 48        z = ZPKrep.zeros.fullplane
 49        F = z.imag
 50        BW = z.real
 51        select = BW < 0
 52        ax.errorbar(
 53            F[select],
 54            -BW[select],
 55            xerr=-BW[select],
 56            color=self.zeroID_color,
 57            lw=0.5,
 58            alpha=0.5,
 59            marker="None",
 60            ls="None",
 61        )
 62        ax.scatter(
 63            F[select],
 64            -BW[select],
 65            s=10,
 66            facecolor=self.zeroID_color,
 67            linewidths=0.5,
 68            # edgecolors = 'black',
 69            marker="x",
 70        )
 71        BWs.extend(-BW[select])
 72        ax.errorbar(
 73            F[~select],
 74            BW[~select],
 75            xerr=BW[~select],
 76            color=self.zeroOD_color,
 77            lw=0.5,
 78            alpha=0.5,
 79            marker="None",
 80            ls="None",
 81        )
 82        ax.scatter(
 83            F[~select],
 84            BW[~select],
 85            s=10,
 86            facecolor=self.zeroOD_color,
 87            linewidths=0.5,
 88            # edgecolors = 'black',
 89            marker="x",
 90        )
 91        BWs.extend(BW[~select])
 92        BWs = np.asarray(BWs)
 93
 94        if len(z) > 0 or len(p) > 0:
 95            select = BWs > 0
 96            BWs = BWs[select]
 97            ax.set_ylim(np.max(BWs), np.min(BWs))
 98            ax.set_yscale("log_zoom")
 99        return
100
101    return plot
pytest information

This code is wrapped in a pytest function using conventions detailed in Pytest Conventions. The full name of this test, as known by the documentation, is:

wield.control.fitting.SISO.plots.plot_augment.plot_augment_zp

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.