Ejemplo n.º 1
0
def createEmptyPhotonListFile(obsFile,fileName=None):
     """
     creates a photonList h5 file 
     using header in headers.ArconsHeaders
     
     INPUTS:
         fileName - string, name of file to write to. If not supplied, default is used
                    based on name of original obs. file and standard directories etc.
                    (see usil.FileName). Added 4/29/2013, JvE
     """
     
     if fileName is None:    
         fileTimestamp = obsFile.fileName.split('_')[1].split('.')[0]
         fileDate = os.path.basename(os.path.dirname(obsFile.fullFileName))
         run = os.path.basename(os.path.dirname(os.path.dirname(obsFile.fullFileName)))
         fn = FileName(run=run, date=fileDate, tstamp=fileTimestamp)
         fullPhotonListFileName = fn.photonList()
     else:
         fullPhotonListFileName = fileName
     if (os.path.exists(fullPhotonListFileName)):
         if utils.confirm('Photon list file  %s exists. Overwrite?' % fullPhotonListFileName, defaultResponse=False) == False:
             warnings.warn('No photon list file created')
             return
     zlibFilter = tables.Filters(complevel=1, complib='zlib', fletcher32=False)
     try:
         plFile = tables.openFile(fullPhotonListFileName, mode='w')
         plGroup = plFile.createGroup('/', 'photons', 'Group containing photon list')
         plTable = plFile.createTable(plGroup, 'photons', ArconsHeaders.CrabList, 'Photon List Data', 
                                      filters=zlibFilter, 
                                      expectedrows=300000)  #Temporary fudge to see if it helps!
     except:
         plFile.close()
         raise
     return plFile
Ejemplo n.º 2
0
def writeNewCalLookupFile(path=None):
    if path is None:
        path = os.environ['MKID_CAL_LOOKUP']
    if os.path.exists(path):
        confirmResp = utils.confirm('File {} exists. Are you sure you want to DELETE it and make a new one?'.format(path),defaultResponse=False)
        if not confirmResp:
            return
            
    try:
        file = tables.openFile(path,mode='w')
    except:
        print 'Error: Couldn\'t create file, ',path
        return
    print 'writing to',path

    zlibFilter = tables.Filters(complevel=1, complib='zlib', fletcher32=False)
    table = file.createTable(file.root, 'lookup', CalLookup_Description,title='Cal Lookup Table',filters=zlibFilter)
    file.flush()
    file.close()
Ejemplo n.º 3
0
def createEmptyPhotonListFile(obsFile,fileName=None,photListDescription=ArconsHeaders.PhotonList):
    """
    creates a photonList h5 file 
    using header in headers.ArconsHeaders
    
    INPUTS:
        fileName - string, name of file to write to. If not supplied, default is used
                    based on name of original obs. file and standard directories etc.
                    (see usil.FileName). Added 4/29/2013, JvE
        photListDescription - a pytables description class that lays out the column structure of the photon table
                for a normal photon list, leave as ArconsHeaders.PhotonList.  For analyzing pulsars, use
                ArconsHeaders.PulsarPhotonList, which has a couple extra pulsar-specfic columns
    """
     
    if fileName is None:    
    #fileTimestamp = obsFile.fileName.split('_')[1].split('.')[0]
    #fileDate = os.path.basename(os.path.dirname(obsFile.fullFileName))
    #run = os.path.basename(os.path.dirname(os.path.dirname(obsFile.fullFileName)))
    #fn = FileName(run=run, date=fileDate, tstamp=fileTimestamp)
    #fullPhotonListFileName = fn.photonList()
        fullPhotonListFileName = FileName(obsFile=obsFile).photonList()
    else:
         fullPhotonListFileName = fileName
    if (os.path.exists(fullPhotonListFileName)):
        if utils.confirm('Photon list file %s exists. Overwrite?' % fullPhotonListFileName, defaultResponse=False) == False:
            warnings.warn('No photon list file created')
            return
    zlibFilter = tables.Filters(complevel=1, complib='zlib', fletcher32=False)
    bloscFilter = tables.Filters(complevel=9, complib='blosc', fletcher32=False)    #May be more efficient to use - needs some experimenting with compression level etc.
    plFile = tables.openFile(fullPhotonListFileName, mode='w')
    try:
        plGroup = plFile.createGroup('/', 'photons', 'Group containing photon list')
        plTable = plFile.createTable(plGroup, 'photons', photListDescription, 'Photon List Data', 
                                      filters=bloscFilter) 
                                      #expectedrows=300000)
    except:
        plFile.close()
        raise
    return plFile