def _set_itype(df, sout, ref=None): """Function used to change spectral intensity representation in a convertible manner. Not called on initilization of TimeSpectra(); rather, only called by as_iunit() method.""" sout = _valid_iunit(sout) sin = df._itype ######################################################################## ### Case 1: User converting from full data down to referenced data.##### ######################################################################## if sin == None and sout != None: rout = _ref_valid(ref, df) ### Divide by ref and convert spectrum df = divby(df, divisor=rout) df = df.apply(from_T[sout]) ################################################################ ### Case 2: Changing spectral representation of converted data.# ################################################################ elif sin != None and sout != None: df = df.apply(to_T[sin]) df = df.apply(from_T[sout]) rout = df._ref # For sake of consistent transferring at end of this function ############################################################# ### Case 3: User converting referenced data up to full data.# ############################################################# elif sin != None and sout == None: rout = _ref_valid(ref, df) df = df.apply(to_T[sin]) df = df.mul(rout, axis=0) # Multiply up! df._ref = rout df._itype = sout return df
def _set_itype(self, sout, ref=None): """Function used to change spectral intensity representation in a convertible manner. Not called on initilization of TimeSpectra(); rather, only called by as_iunit() method.""" sout = _valid_iunit(sout) sin = self._itype df = self._df # for convienence/back compatibility # Corner case, for compatibility with baseline.setter if sin == None and sout == None: return ######################################################################## ### Case 1: User converting from full data down to referenced data.##### ######################################################################## if sin == None and sout != None: rout = self._baseline_valid(ref) ### If user tries to downconvert but doesn't pass reference, use stored one if rout == None: rout = self._baseline ### If ref not passed, use current baseline. Want to make sure it is ### not none, but have to roundabout truthtest if isinstance(rout, NoneType): raise TypeError("Cannot convert spectrum to iunit %s without a baseline" % sout) else: df = divby(df, divisor=rout) df = df.apply(from_T[sout]) # Assumes typeerror is due to rout not being a series/array, but doesn't further test it. EG do another # typeerror check of try: if rout == None: raise error ################################################################ ### Case 2: Changing spectral representation of converted data.# ################################################################ elif sin != None and sout != None: ### If user changing reference on the fly, need to change ref ### if not isinstance(ref, NoneType): # and ref != self._baseline: rout = self._baseline_valid(ref) ### Make this it's own method called change baseline? df = df.apply(to_T[sin]) df = df.mul(self._baseline, axis=0) df = divby(df, divisor=rout) df = df.apply(from_T[sout]) else: rout = self._baseline # For sake of consistent transferring at end of this function df = df.apply(to_T[sin]) df = df.apply(from_T[sout]) ############################################################# ### Case 3: User converting referenced data up to full data.# ############################################################# elif sin != None and sout == None: rout = self._baseline_valid(ref) df = df.apply(to_T[sin]) df = df.mul(rout, axis=0) # Multiply up! self._baseline = rout self._itype = sout self._df = df