def __init__(self, data, alpha=0.05, linear=None, freundlich=None, langmuir=None): # validate input try: val.validateData(data) val.validateAlpha(alpha) except val.InputError as ie: print(ie) return None # intialize fitting with Linear isotherm self.Linear = isotherm.Linear(data, userParams=linear, validateInput=False) # test for linear model validity if not self.Linear.modelValidity: self.LinearFailCode() return None # test for statistical significance (Asymptotic Confidence Interval) Kd = [self.Linear.isoModelResult.params.valuesdict()["Kd"]] covar = self.Linear.isoModelResult.covar confIntrvl = AAstats.RegConfAsym(data[0], Kd, covar, alpha) if confIntrvl["lower"][0] <= 0: self.LinearFailCode return None # fit the other isotherms self.Freundlich = isotherm.Freundlich(data, userParams=freundlich, validateInput=False) self.Langmuir = isotherm.Langmuir(data, userParams=langmuir, validateInput=False)
def __init__( self, data, userParams=None, fitMethods=default_fitMethods, validateInput=True): # validate input if validateInput: try: val.validateData(data) if userParams: val.validate_userParams(userParams, self.IsothermFunc) except val.InputError as ie: print(ie) return None except Exception as inst: print(type(inst)) print(inst) return None # initiate lmfit's wrapper around the isotherm function isoModel = lmfit.Model(self.IsothermFunc) # replace inititial params with userParams if userParams: for key in userParams: isoModel.__dict__['def_vals'][key] = userParams[key] # fit models using given fitMethods isoModelResult = None for fit_method in fitMethods: if isoModelResult: isoModelResult = isoModel.fit( data=data[1], x=data[0], params=isoModelResult.params, # this is what's different method=fit_method, fit_kws=fitMethods[fit_method]) else: isoModelResult = isoModel.fit( data=data[1], x=data[0], method=fit_method, fit_kws=fitMethods[fit_method]) self.isoModelResult = isoModelResult # validate fit model against isotherm theory self.modelValidity = self.ValidateFit()