def __init__(self, ctrl, p, cdict=None, pdict=None, prep_bary=False): """Prepares ctrl & p for simulation by running the parameter updates when appropriate""" self.add(p=p) self.add(ctrl=ctrl) self.ctrl.f_samp = p.f_samp self.p.update() self.ctrl.update() self.prep_bary = prep_bary if prep_bary: lib.barywidth_map(self.p, reach=self.ctrl.bmap_reach , scaling_fct=self.ctrl.bmap_scaling , force_calculate=self.force_calculate, disp=self.show_bary) if self.force_calculate: self.p.update() self.ctrl.update() if cdict is not None: self.cdict=cdict if pdict is not None: self.pdict=pdict self.ctrl.f_samp = self.p.f_samp base_avg_amp = np.float64((np.sum(np.abs(self.p.analog_sig)))/len(self.p.analog_sig)) self.ctrl.trans_amp = lib.db2amp(ctrl.trans_power)*base_avg_amp
def update_bary(self): """Triggers the update of the barywidth map""" lib.barywidth_map(self.p, reach=self.ctrl.bmap_reach , scaling_fct=self.ctrl.bmap_scaling , force_calculate=self.force_calculate, disp=self.show_bary)
def barywidth(*args, axes=None, savename='', fit_type='order2', residuals=True, disp=True, **kwargs): """Accepts either a SyncParams() object or two iterables representing the CFO and the barywidth""" if len(args) == 1 and type(args[0]).__name__ == 'SyncParams': CFO, barywidths = barywidth_map(args[0], **kwargs) f_symb = args[0].f_symb elif len(args) == 2: CFO = args[0] barywidths = args[1] f_symb = 1 fit_type = 'none' else: print("Invalid input") # Axis specification shenanigans if axes is None: fh = plt.figure() if residuals: main_axes_loc = [.13,.3,.8,.6] else: main_axes_loc = [.13,.11,.8,.8] ax = fh.add_axes(main_axes_loc) make_rax = True if residuals else False else: make_rax = False typename = type(axes).__name__ # Only one axes object given if typename in ['Axes', 'AxesSubplot']: ax = axes if residuals: warnings.warn('No residuals plotted; not enough axes') residuals = False # Input checking elif len(axes) > 2: raise('Too many axes specified') # If only 1 ax is given elif len(axes) == 1: ax = axes if residuals: warnings.warn('No residuals plotted; not enough axes') residuals = False # If two axes given elif len(axes) == 2: ax = axes[0] rax = axes[1] if not residuals: warnings.warn('Specified a residuals axis, but residuals option False') x = CFO/f_symb y = barywidths lh = ax.plot(x, y, 'k-', label='Barycenter width') x_lims = [min(x), max(x)] ax.plot((0,0), (min(y),max(y))) fit_curve = None if fit_type == 'linear': # Linear fit display fit = np.empty(2) fit[0] = args[0].baryslope*f_symb fit[1] = args[0].basewidth fit_curve = fit[0]*x + fit[1] ax.plot(x, fit_curve, label='Linear fit') elif fit_type == 'order2': # parabola fit display fit = args[0].order2fit fit_curve = fit[0]*CFO**2 + fit[1]*CFO**1 + args[0].basewidth#fit[2] ax.plot(x, fit_curve, label='Order2 fit') elif fit_type == 'logistic': coeffs = args[0].logisticfit fit_curve = lib.logistic(CFO, coeffs) + args[0].basewidth ax.plot(x, fit_curve, label='Logistic fit') elif fit_type == 'none': pass else: print('Unknown fit option. No fit displayed') xlabel = 'CFO (f_symb)' ax.set_xlabel(xlabel) ax.set_ylabel('Barycenter width') ax.set_xlim(x_lims) ax.legend() # Plotting residuals if make_rax: residuals_loc = [main_axes_loc[0],.1,.8,0] residuals_loc[3] = main_axes_loc[1]-residuals_loc[1]-0.005 rax = fh.add_axes(residuals_loc) ax.set_xticklabels([]) if fit_curve is not None and residuals: residuals_vals = fit_curve - barywidths residuals_curve = residuals_vals/np.std(residuals_vals) rax.plot((x[0],x[-1]),(0,0), 'k-') rax.plot(x,residuals_curve) rax.yaxis.set_ticks((-1,1)) rax.set_ylabel('\sigma') rax.set_xlabel(xlabel) rax.set_xlim(x_lims) rax.set_ylim([-1.7,1.7]) msg = "Total error: " + str(np.abs(residuals_vals).sum()) if disp: print(msg) save(savename) if axes is None: return fh