def setup_fill_params(self): if not hasattr(self._fill_gases, '__len__') or \ len(self._fill_gases) < 2: return main_gas = self._fill_gases[0] for idx, value in enumerate(zip(self._fill_gases[1:], self._fill_ratio)): gas, ratio = value mol_name = '{}_{}'.format(gas, main_gas) param_name = mol_name param_tex = '{}/{}'.format(molecule_texlabel(gas), molecule_texlabel(main_gas)) def read_mol(self, idx=idx): return self._fill_ratio[idx] def write_mol(self, value, idx=idx): self._fill_ratio[idx] = value fget = read_mol fset = write_mol bounds = [1.0e-12, 0.1] default_fit = False self.add_fittable_param(param_name, param_tex, fget, fset, 'log', default_fit, bounds)
def add_active_gas_param(self): """ Adds the mixing ratio as a fitting parameter as the name of the molecule """ mol_name = self.molecule param_name = self.molecule param_tex = molecule_texlabel(mol_name) def read_mol(self): return self._mix_ratio def write_mol(self, value): self._mix_ratio = value read_mol.__doc__ = f"{mol_name} constant mix ratio (VMR)" fget = read_mol fset = write_mol bounds = [1.0e-12, 0.1] default_fit = False self.add_fittable_param(param_name, param_tex, fget, fset, 'log', default_fit, bounds)
def setup_molecule_parameters(self): """ This function will setup the fitting parameters programmatically """ # Loop through the molecules whilst getting the index for idx, molecule in enumerate(self._molecules): # Lets use fancy f-strings to create the parameter name param_name = f'{molecule}_frac' # Lets get the latex name of the molecule molecule_latex = molecule_texlabel(molecule) # Now create the parameter latex param_latex = f'{molecule_latex}_fraction' # Now we need to create the getters and setters # These will read and write each element in the array # The index=idx is needed to make sure the correct index # is always used for each molecule def mol_getter(self, index=idx): return self._fractions[index] def mol_setter(self, value, index=idx): self._fractions[index] = value # Lets set some bounds bounds = [1e-12, 1000] # Now lets add the fitting parameter!! self.add_fittable_param(param_name, param_latex, mol_getter, mol_setter, "log", False, bounds)
def add_surface_param(self): """ Generates surface fitting parameters. Has the form ''Moleculename_surface' """ param_name = self.molecule param_tex = molecule_texlabel(param_name) param_surface = '{}_surface'.format(param_name) param_surf_tex = '{}_surface'.format(param_tex) def read_surf(self): return self._mix_surface def write_surf(self, value): self._mix_surface = value fget_surf = read_surf fset_surf = write_surf bounds = [1.0e-12, 0.1] default_fit = False self.add_fittable_param(param_surface, param_surf_tex, fget_surf, fset_surf, 'log', default_fit, bounds)
def add_P_param(self): """ Generates pressure fitting parameter. Has the form 'Moleculename_P' """ mol_name = self.molecule mol_tex = molecule_texlabel(mol_name) param_P = '{}_P'.format(mol_name) param_P_tex = '{}_P'.format(mol_tex) def read_P(self): return self._mix_ratio_pressure def write_P(self, value): self._mix_ratio_pressure = value fget_P = read_P fset_P = write_P bounds = [1.0e-12, 0.1] default_fit = False self.add_fittable_param(param_P, param_P_tex, fget_P, fset_P, 'log', default_fit, bounds)
def add_top_param(self): """ Generates TOA fitting parameters. Has the form: 'Moleculename_top' """ param_name = self.molecule param_tex = molecule_texlabel(param_name) param_top = '{}_top'.format(param_name) param_top_tex = '{}_top'.format(param_tex) def read_top(self): return self._mix_top def write_top(self, value): self._mix_top = value fget_top = read_top fset_top = write_top bounds = [1.0e-12, 0.1] default_fit = False self.add_fittable_param(param_top, param_top_tex, fget_top, fset_top, 'log', default_fit, bounds)
def setup_derived_params(self, ratio_list): for elem_ratio in ratio_list: elem1, elem2 = elem_ratio.split('/') mol_name = '{}_{}_ratio'.format(elem1, elem2) param_name = mol_name param_tex = '{}/{}'.format(molecule_texlabel(elem1), molecule_texlabel(elem2)) def read_mol(self, elem=elem_ratio): return np.mean(self.get_element_ratio(elem)) fget = read_mol fget.__doc__ = f'{elem_ratio} ratio (volume)' compute = True self.add_derived_param(param_name, param_tex, fget, compute)
def add_gamma_param(self): mol_name = self.molecule param_name = self.molecule param_tex = molecule_texlabel(param_name) param_gamma = '{}_gamma'.format(param_name) param_gamma_tex = '{}_gamma'.format(param_tex) def read_gamma(self): return self._gamma def write_gamma(self, value): self._gamma = value fget_gamma = read_gamma fset_gamma = write_gamma bounds = [5, 25] default_fit = False self.add_fittable_param(param_gamma, param_gamma_tex,fget_gamma,fset_gamma,'linear',default_fit,bounds)
def add_beta_param(self): mol_name = self.molecule param_name = self.molecule param_tex = molecule_texlabel(param_name) param_beta = '{}_beta'.format(param_name) param_beta_tex = '{}_beta'.format(param_tex) def read_beta(self): return self._beta def write_beta(self, value): self._beta = value fget_beta = read_beta fset_beta = write_beta bounds = [1e4, 6e4] default_fit = False self.add_fittable_param(param_beta, param_beta_tex,fget_beta,fset_beta,'log',default_fit,bounds)
def add_alpha_param(self): mol_name = self.molecule param_name = self.molecule param_tex = molecule_texlabel(param_name) param_alpha = '{}_alpha'.format(param_name) param_alpha_tex = '{}_alpha'.format(param_tex) def read_alpha(self): return self._alpha def write_alpha(self, value): self._alpha = value fget_alpha = read_alpha fset_alpha = write_alpha bounds = [0.5, 2.5] default_fit = False self.add_fittable_param(param_alpha, param_alpha_tex,fget_alpha,fset_alpha,'linear',default_fit,bounds)