def __init__(self, lineshape=None, n=1, model=[], background=[], op=operator.add, preftext='lp', **kws): """ Initialize class. """ self.op = op self.lineshape = self._model_convert(lineshape) self.background = self._model_convert(background) self.model = model self.preftext = preftext # Initialize the number of components self.nbg = 0 # number of background components self.nlp = 0 # number of line profiles if 'independent_vars' not in kws: try: kws['independent_vars'] = self.components[0].independent_vars except: pass if 'missing' not in kws: try: kws['missing'] = self.components[0].missing except: pass def _tmp(self, *args, **kws): pass Model.__init__(self, _tmp, **kws) for side in self.components: prefix = side.prefix for basename, hint in side.param_hints.items(): self.param_hints["%s%s" % (prefix, basename)] = hint
def __init__(self, model=[], n=0, lineshape=[], background=[], op=operator.add, preftext='lp', **kws): """ Initialize class. """ self.components = [] self.op = op self.preftext = preftext # Initialize the number of components self.nbg = 0 # number of background components self.nlp = 0 # number of line profiles # Introduce a background function if background: try: bg_comp = background.components if type(bg_comp) == list: self.components += bg_comp self.nbg = len(bg_comp) except: bg_comp = list(background) self.components += bg_comp self.nbg = len(bg_comp) # Construct the lineshape components if lineshape: self.components += [lineshape(prefix=preftext+str(i+1)+'_', **kws) for i in range(n)] self.nlp = n if model: self.components += model.components self.nlp += len(model.components) if 'independent_vars' not in kws: try: kws['independent_vars'] = self.components[0].independent_vars except: pass if 'missing' not in kws: try: kws['missing'] = self.components[0].missing except: pass # def _tmp(self, *args, **kws): # pass # Model.__init__(self, _tmp, **kws) Model.__init__(self, self._tmp, **kws) for side in self.components: prefix = side.prefix for basename, hint in side.param_hints.items(): self.param_hints["%s%s" % (prefix, basename)] = hint
def __init__( self, left, right, on_undefined_conv="numeric", convMap=None, **kws ): if not isinstance(left, Model): raise ValueError(self._bad_arg.format(arg=left)) if not isinstance(right, Model): raise ValueError(self._bad_arg.format(arg=right)) if not np.isin(on_undefined_conv, ["numeric", "raise"]): raise ValueError( "Parameter 'on_undefined_conv' should be either " "'numeric' or 'raise'." ) self.left = left self.right = right self._on_undefined_conv = on_undefined_conv name_collisions = set(left.param_names) & set(right.param_names) if len(name_collisions) > 0: msg = "" for collision in name_collisions: msg += self._names_collide.format(clash=collision) raise NameError(msg) # we assume that all the sub-models have the same independent vars if "independent_vars" not in kws: kws["independent_vars"] = self.left.independent_vars if "nan_policy" not in kws: kws["nan_policy"] = self.left.nan_policy def _tmp(self, *args, **kws): pass Model.__init__(self, _tmp, **kws) for side in (left, right): prefix = side.prefix for basename, hint in side.param_hints.items(): self.param_hints["%s%s" % (prefix, basename)] = hint # set a default convolution map self.convMap = { "lorentzian": { "lorentzian": conv_lorentzian_lorentzian, "gaussian": conv_gaussian_lorentzian, "pvoigt": conv_lorentzian_pvoigt, "delta": conv_delta, "linear": conv_linear, }, "gaussian": { "lorentzian": conv_gaussian_lorentzian, "gaussian": conv_gaussian_gaussian, "delta": conv_delta, "linear": conv_linear, "pvoigt": conv_gaussian_pvoigt, }, "pvoigt": { "lorentzian": conv_lorentzian_pvoigt, "gaussian": conv_gaussian_pvoigt, "jump_diff": conv_jumpdiff_pvoigt, "linear": conv_linear, "delta": conv_delta, "rotations": conv_rotations_pvoigt, }, "jump_diff": { "gaussian": conv_gaussian_jumpdiff, "delta": conv_delta, "linear": conv_linear, "pvoigt": conv_jumpdiff_pvoigt, }, "rotations": { "gaussian": conv_gaussian_rotations, "delta": conv_delta, "linear": conv_linear, "pvoigt": conv_rotations_pvoigt, }, "delta": { "gaussian": conv_delta, "lorentzian": conv_delta, "voigt": conv_delta, "pvoigt": conv_delta, "jump_diff": conv_delta, "rotations": conv_delta, "linear": conv_linear, "two_diff_state": conv_delta, }, "linear": { "gaussian": conv_linear, "lorentzian": conv_linear, "voigt": conv_linear, "pvoigt": conv_linear, "jump_diff": conv_linear, "rotations": conv_linear, "two_diff_state": conv_linear, }, } # override default convolutions with provided ones if convMap is not None: self.convMap.update(convMap)