コード例 #1
0
    def __init__(self, *dfargs, **dfkwargs):
        ### Pop default DataFrame keywords before initializing###
        self.name=dfkwargs.pop('name', 'TimeSpectra')

        ###Spectral index-related keywords
        specunit=dfkwargs.pop('specunit', None)

        ###Intensity data-related stuff
        iunit=dfkwargs.pop('iunit', None)

        ###Time index-related keywords  (note, the are only used if a DatetimeIndex is not passed in)
        freq=dfkwargs.pop('freq', None)    
        start=dfkwargs.pop('start', None)
        stop= dfkwargs.pop('stop', None)    
        periods=dfkwargs.pop('periods',None)
        timeunit=dfkwargs.pop('timeunit',None) #Not the same as freq, but inferred from it
        baseline=dfkwargs.pop('baseline', None)
        

        if stop and periods:
            raise AttributeError('TimeSpectra cannot be initialized with both periods and stop; please choose one or the other.')

        df=DataFrame(*dfargs, **dfkwargs)

        ### If user passes non datetime index to columns, make sure they didn't accidetnally pass SpecIndex by mistake.
        if not isinstance(df.columns, DatetimeIndex):
            try:
                if df.columns._kind == 'spectral':
                    raise IOError("SpecIndex must be passed as index, not columns.")   ### Can't be an attribute error or next won't be raised             

            ### df.columns has no attribute _kind, meaning it is likely a normal pandas index        
            except AttributeError:
                self._interval=True
                self.start=start
                self.stop=stop
                self.freq=freq
                self.timeunit=timeunit

        ### Take Datetime info and use to recreate the array
        else:
            self._interval=False        
            self.start=df.columns[0]
            self.stop=df.columns[-1]
            self.freq=df.columns.freq

            ### ADD TRANSLATION FOR FREQ--> basetimeuint
#       self.timeunit=get_time_from_freq(df.columns.freq)

        ### Have to do it here instead of defaulting on instantiation.
        df._tkind='temporal'

        ### Assign spectral intensity related stuff but 
        ### DONT CALL _set_itype function
        iunit=_valid_iunit(iunit)
        self._itype=iunit

        self.df=df
        
        ### This has to be done AFTER self.df has been set
        self._baseline=self._baseline_valid(baseline)#SHOULD DEFAULT TO NONE SO USER CAN PASS NORMALIZED DATA WITHOUT REF        

        ###Set Index as spectral variables
        self.specunit = specunit  #This will automatically convert to a spectral index