Ejemplo n.º 1
0
    def build_timespectra(self):
        """ Attempts to build timespectra form picklefile, legacy and finally
            from the raw datafiles."""
                
        # Files in working directory, ignore certain extensions; ignore directories
        infiles = get_files_in_dir(self.inpath, sort=True)
        infiles = [f for f in infiles if not ext(f) in self.img_ignore]
                
        if not infiles:
            raise IOError("No valid files found in %s" % self.infolder)        
        
        # Try get timespectra from picklefiles
        ts_full = self._ts_from_picklefiles(infiles)
        if ts_full:
            return ts_full

        # Try get timespectra from timefile/datafile (legacy)
        ts_full = self._ts_from_legacy(infiles)
        if ts_full:
            return ts_full
        
        # Import from raw specfiles (overwrite if data < 1s apart)
        logger.info('Loading contents of %s multiple raw spectral '
                    'files %s.' % (self.infolder, len(infiles)))     
        try:
            return from_spec_files(infiles, name=self.infolder, 
                                   check_for_overlapping_time=False) 
        except Exception as exc:
            logger.critical('Could not import files from pickle, legacy or' 
            ' from_spec_files()')
            raise
Ejemplo n.º 2
0
    def build_timespectra(self):
        """ Attempts to build timespectra form picklefile, legacy and finally
            from the raw datafiles."""

        # Files in working directory, ignore certain extensions; ignore directories
        infiles = get_files_in_dir(self.inpath, sort=True)
        infiles = [f for f in infiles if not ext(f) in self.img_ignore]

        if not infiles:
            raise IOError("No valid files found in %s" % self.infolder)

        # Try get timespectra from picklefiles
        ts_full = self._ts_from_picklefiles(infiles)
        if ts_full:
            return ts_full

        # Try get timespectra from timefile/datafile (legacy)
        ts_full = self._ts_from_legacy(infiles)
        if ts_full:
            return ts_full

        # Import from raw specfiles (overwrite if data < 1s apart)
        logger.info('Loading contents of %s multiple raw spectral '
                    'files %s.' % (self.infolder, len(infiles)))
        try:
            return from_spec_files(infiles,
                                   name=self.infolder,
                                   check_for_overlapping_time=False)
        except Exception as exc:
            logger.critical('Could not import files from pickle, legacy or'
                            ' from_spec_files()')
            raise
Ejemplo n.º 3
0
def from_oceanoptics(directory, sample_by=None, sort=True, **from_spec_files_kwds):
    ''' Wrapper to from_spec_files to both generate a file list from a directory and read files into time spectra.
        
        Parameters:
        -----------
            directory: directory with raw spectral files.
            sample_by: Sample every X files.  (Useful for reducing large datsets prior to readin)
            **from_spec_files_kwds: All kwds passed to from_spec_files().
            
        Notes:
        ------
            Slice works by taking the 0 file every time and counting from there.  So if you enter sample_by=3,
            expect to get files 0, 3, 6 etc... but if sample_by_10, you get files 0,10,20
    '''
    
    files=get_files_in_dir(directory, sort=sort)

    if sample_by:    
        files=files[0::sample_by]  #Slice already takes cares of most errors
    
    return from_spec_files(files, **from_spec_files_kwds)
Ejemplo n.º 4
0
    
    files=get_files_in_dir(directory, sort=sort)

    if sample_by:    
        files=files[0::sample_by]  #Slice already takes cares of most errors
    
    return from_spec_files(files, **from_spec_files_kwds)

if __name__=='__main__':
    # Assumes datapath is ../data/gwuspecdata...
    
    ### Test of raw fiber spectral data
    
    ts=from_oceanoptics('../data/gwuspecdata/fiber1', sample_by=10, sort=True, name='oceanopticstest')

    files=get_files_in_dir('../data/gwuspecdata/fiber1')
    ts=from_spec_files(files, name='Test Spectra')
    #print ts, type(ts)
    
    ### Test of timefile/datafile
    #dfile='../data/gwuspecdata/ex_tf_df/11_data.txt'
    #tfile='../data/gwuspecdata/ex_tf_df/11_tfile.txt'
    #ts2=from_timefile_datafile(dfile, tfile, extract_dark=True, name='Test Spec 2')
    #print ts2, type(ts2)
    
    ### Test of chem UVVIS data
    files=get_files_in_dir('../data/gwuspecdata/IRData')
    ts3=from_gwu_chem_UVVIS(files, name='IR Spec')
    print ts3, type(ts3), ts3[ts3.columns[0]]
    
    ### ADD CHEM IR DATA (Did it in a notebook at one point actually)