Esempio n. 1
0
    def __init__(self, filelist, **kw):
        #TODO: Checkout ipython-progress bar??????????
        #TODO: MULTIEXT, CUBE, BURST METHODS
        '''
        Extract frames from list of fits files.  Assuming all the files in the input list are
        fits complient and have the same basic structure, data extraction can be done ~10**6 
        times faster than it can with pyfits (even without multiprocessing!!) by skipping unneessary 
        check and other cuft.
        '''
        self.start      = start         = kw.setdefault('start',       0)
        self.step       = step          = kw.setdefault('step',        1)
        self.stop       = stop          = kw.setdefault('stop',        None)

        keys            = kw.setdefault('keygrab',     None            )
        self.headkeys                   = []

        self.filelist                   = parsetolist(filelist)
        self.Nfiles     = Nfiles        = len(filelist)
        self.clobber                    = kw.setdefault('clobber',     True)
        #self.outfiles                   = []
        
        self.data_buffer = BytesIO()
        self.text_buffer = []
        
        #keyword extraction setup
        if isinstance(keys, (str, type(None))):
            keys = keys,
            
        self.match_keys = matchmaker(*keys)
        self.keygrab = keys
        
        self.bar        = kw.pop('progressbar', ProgressBar())     #initialise progress bar unless False
        
        self.filemem    = []            #memory buffer to reconstruct which frame came from which file
        self.setup( self.filelist[0] )
Esempio n. 2
0
    def __init__(self, filelist, **kw):
        #WARNING:  Turns out this sequential extraction thing is SUPER slow!!
        #TODO: Checkout ipython-progress bar??????????
        '''
        Extract frames from list of fits files.
        '''
        self.start      = start         = kw.setdefault( 'start',       0               )
        self.step       = step          = kw.setdefault( 'step',        1               )
        self.clobber                    = kw.setdefault( 'clobber',     True            )

        self.keygrab                    = kw.setdefault( 'keygrab',     None            )
        self.headkeys                   = []

        self.filelist                   = parsetolist( filelist )
        self.outfiles                   = []

        #map from integer extension number to (header, data) element
        self.data_element  = lambda hdulist, i:  ( hdulist[i+1].header, hdulist[i+1].data )                     #return header and data for extension i

        #read firts file
        first = pyfits.open( filelist[0], memmap=True )
        pheader = first[0].header

        #Assume all files have same number of extensions and calculate total number of frames.
        Next = pheader.get( 'nextend' )
        self.Nfiles     = Nfiles        = len(filelist)
        self.Ntot       = Ntot          = (Nfiles*Next - start) // step
        self.stop       = stop          = kw.setdefault( 'stop',        Ntot            )
       
        self.padwidth   = len(str(Ntot))                #for numerical file naming
        self.count      = 0

        self.bar        = kw.pop( 'progressbar', ProgressBar()    )     #initialise progress bar unless False

        #create master output file (HduList with header of first file)
        primary = pyfits.PrimaryHDU( header=pheader  )
        self.master = pyfits.HDUList( primary )                    #Use this as the master header for the output file
        self.mheader = self.master[0].header
Esempio n. 3
0
    pool.close()
    #pool.join()
    
    #Flatten the twice nested list of string matches (this is the fastest way of doing this!!)
    results = []
    for r in raw:   
        results.extend(r)
            
    return merger(results, keys, defaults, return_type)

#====================================================================================================   
if __name__ =='__main__':
    from time import time

        
    saltpath = '/media/Oceanus/UCT/Observing/SALT/V2400_Oph/20140921/product'
    filelist = parsetolist( saltpath+'/bxgp*.fits' )

    t0 = time()
    #print( len(filelist) )
    keys = 'utc-obs','date-obs'
    q = superheadhunter( filelist[:100], keys )
    #q = headhunter( filelist[0], ('date-obs', 'utc-obs', 'deadtime') )

    print( 'Took',  time()-t0, 's' )
    #print()
    ##print( q )
    #for k,v in q.items():
        #print( k, len(v) )
    #ipshell()