plot_residuals¶
wield.control.fitting.SISO.plots.plot_residuals
This is a pytest module needing documentation
Functions
|
This is a pytest needing documentation |
Details
- plot_residuals(self, fitter=None, gs_base=GridSpec(1, 1)[0:1, 0:1], fig=None, ax_bunch=None, xscale=None, plot_now=True, **kwargs)[source][github]¶
This is a pytest needing documentation
code
1def plot_residuals( 2 self, 3 fitter=None, 4 gs_base=gridspec.GridSpec(1, 1)[0], 5 fig=None, 6 ax_bunch=None, 7 xscale=None, 8 plot_now=True, 9 **kwargs 10): 11 use_phase = True 12 13 if ax_bunch is None: 14 axB = generate_stacked_plot_ax( 15 [ 16 ("mag", True), 17 ("phase", use_phase), 18 ], 19 height_ratios=dict( 20 mag=2, 21 ), 22 heights_phys_in_default=1, 23 xscales="log", 24 gs_base=gs_base, 25 fig=fig, 26 ax_bunch=ax_bunch, 27 ) 28 else: 29 axB = ax_bunch 30 31 fit_list = [] 32 axB.plot_fit = plot_augment_residuals( 33 self, ax_mag=axB.mag, ax_phase=axB.phase, fit_list=fit_list, **kwargs 34 ) 35 36 axB.mag.set_ylabel("Residuals Magnitude") 37 if axB.phase: 38 axB.phase.set_ylabel("Residuals Phase [deg]") 39 axB.ax_bottom.set_xlabel("Frequency [Hz]") 40 41 if fitter is not None and plot_now: 42 axB.plot_fit(fitter) 43 44 def finalize(): 45 min_lims = [] 46 max_lims = [] 47 for fitB in fit_list: 48 min_err_lim = min( 49 fitB.median_res_lim, 50 fitB.min_res_err_lim, 51 max(fitB.min_res_err_lim / 30, fitB.min_res_err_lim * 1), 52 ) 53 min_lims.append(min_err_lim) 54 max_err_lim = max( 55 fitB.median_res_lim, 56 fitB.max_res_err_lim, 57 min(fitB.max_res_err_lim * 30, fitB.max_res_err_lim / 1), 58 ) 59 max_lims.append(max_err_lim) 60 axB.mag.set_ylim(np.min(min_lims), max(max_lims)) 61 62 scales = [] 63 mins = [] 64 minsNZ = [] 65 maxs = [] 66 for fitB in fit_list: 67 scales.append(fitB.scale_log) 68 mins.append(fitB.minF_Hz) 69 minsNZ.append(fitB.minF_HzNZ) 70 maxs.append(fitB.maxF_Hz) 71 72 if xscale is None: 73 if np.count_nonzero(scales) / len(scales) > 0.5: 74 final_xscale = "log_zoom" 75 else: 76 final_xscale = "linear" 77 else: 78 final_xscale = xscale 79 80 if final_xscale in ["log", "log_zoom"]: 81 xmin = np.min(minsNZ) 82 else: 83 xmin = np.min(mins) 84 xmax = np.max(maxs) 85 axB.ax_bottom.set_xscale(final_xscale) 86 axB.ax_bottom.set_xlim(xmin, xmax) 87 for subax in axB.ax_list_0: 88 subax.set_xscale(final_xscale) 89 subax.set_xlim(xmin, xmax) 90 axB.mag.legend(ncol=2, fontsize=8, loc="best") 91 92 axB.finalizers.append(finalize) 93 return axB
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_residuals.plot_residualsThe 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.