def populateFlatCals(runPath, lookupPath=None): if lookupPath is None: lookupPath = os.environ['MKID_CAL_LOOKUP'] if not os.path.exists(path): writeNewCalLookupFile(path) lookup = CalLookupFile(path, mode='a') for root, dirs, files in os.walk(runPath): obsFilenames = fnmatch.filter(files, 'obs*.h5') for obsFilename in obsFilenames: obsPath = os.path.join(root, obsFilename) try: obs = ObsFile(obsPath) fn = FileName(obsFile=obsPath) params = {} params['obs_run'], params['obs_date'], params[ 'obs_tstamp'] = fn.getComponents() params['flatSoln_run'] = params['obs_run'] if params['obs_date'] in [ '20140923', '20140924', '20141020', '20141021', '20141022' ]: params['flatSoln_date'] = params['obs_date'] else: if params['obs_date'] == '20140925': params['flatSoln_date'] = '20140924' print(params) lookup.updateObs(newParams=params) except: pass
def makeFileName(self, obsTstamp, keyPrefix): entry = self.lookupObs(obsTstamp) if entry is None: print('entry none') return None run = entry[keyPrefix + '_run'] date = entry[keyPrefix + '_date'] tstamp = entry[keyPrefix + '_tstamp'] if run == '' and date == '' and tstamp == '': return None fn = FileName(run=run, date=date, tstamp=tstamp) return fn
def populateWaveCals(runPath, lookupPath=None): if lookupPath is None: lookupPath = os.environ['MKID_CAL_LOOKUP'] if not os.path.exists(path): writeNewCalLookupFile(path) lookup = CalLookupFile(path, mode='a') for root, dirs, files in os.walk(runPath): obsFilenames = fnmatch.filter(files, 'obs*.h5') for obsFilename in obsFilenames: obsPath = os.path.join(root, obsFilename) try: obs = ObsFile(obsPath) fn = FileName(obsFile=obsPath) params = {} params['obs_run'], params['obs_date'], params[ 'obs_tstamp'] = fn.getComponents() params['waveSoln_run'] = params['obs_run'] obs.loadBestWvlCalFile() waveCalPath = obs.wvlCalFileName waveCalFilename = os.path.basename(waveCalPath) if waveCalFilename.startswith('master'): params['waveSoln_isMasterCal'] = True tstamp = waveCalFilename.split('_')[1].split('.')[0] params['waveSoln_tstamp'] = tstamp params['waveSoln_date'] = '' else: params['waveSoln_isMasterCal'] = False tstamp = waveCalFilename.split('_')[1].split('.')[0] params['waveSoln_tstamp'] = tstamp dirs = os.path.dirname( os.path.normpath(waveCalPath)).split(os.sep) params['waveSoln_date'] = dirs[-1] print(params) lookup.updateObs(newParams=params) except: pass
def populateTimeMasks(runPath, lookupPath=None): if lookupPath is None: lookupPath = os.environ['MKID_CAL_LOOKUP'] if not os.path.exists(path): writeNewCalLookupFile(path) lookup = CalLookupFile(path, mode='a') for root, dirs, files in os.walk(runPath): obsFilenames = fnmatch.filter(files, 'obs*.h5') for obsFilename in obsFilenames: obsPath = os.path.join(root, obsFilename) try: obs = ObsFile(obsPath) fn = FileName(obsFile=obsPath) params = {} params['obs_run'], params['obs_date'], params[ 'obs_tstamp'] = fn.getComponents() params['timeMask_run'], params['timeMask_date'], params[ 'timeMask_tstamp'] = fn.getComponents() print(params) lookup.updateObs(newParams=params) except: pass
def makeCubeTimestream(configFileName): configData = readDict() configData.read_from_file(configFileName) # Extract parameters from config file nPos = int(configData['nPos']) startTimes = np.array(configData['startTimes'], dtype=int) stopTimes = np.array(configData['stopTimes'], dtype=int) darkSpan = np.array(configData['darkSpan'], dtype=int) flatSpan = np.array(configData['flatSpan'], dtype=int) xPos = np.array(configData['xPos'], dtype=int) yPos = np.array(configData['yPos'], dtype=int) numRows = int(configData['numRows']) numCols = int(configData['numCols']) upSample = int(configData['upSample']) padFraction = float(configData['padFraction']) coldCut = int(configData['coldCut']) fitPos = bool(configData['fitPos']) target = str(configData['target']) run = str(configData['run']) date = str(configData['date']) outputDir = str(configData['outputDir']) useImg = bool(configData['useImg']) doHPM = bool(configData['doHPM']) subtractDark = bool(configData['subtractDark']) divideFlat = bool(configData['divideFlat']) refFile = str(configData['refFile']) #hard coded for now to the daytime wvl cal we did with the WL data wvlCalTS = '1491870376' calPath = os.getenv('MKID_PROC_PATH', '/') timeMaskPath = os.path.join(calPath,"darkHotPixMasks") hpPath = os.path.join(timeMaskPath,date) ################################################# # Create empty arrays to save to npz file later timeStamps=[] cubes = [] ################################################# #get wvl cal soln file name cfn = FileName(run=run,date=date,tstamp=wvlCalTS).calSoln() #loop through obs files and each second within each file to make 1-s cubes for ts in startTimes: #load obs file obsFN = FileName(run=run, date=date, tstamp=str(ts)).obs() print(obsFN) obs = darkObsFile(obsFN) totalIntTime = obs.totalIntegrationTime #load wvlSoln file obs.loadWvlCalFile(cfn) for i in range(totalIntTime): fullTS = ts+i timeStamps.append(fullTS) print(i, fullTS) #get spectral cube for this second cDict = obs.getSpectralCube(i,1,weighted=False,fluxWeighted=False,energyBinWidth=0.07) cube = cDict['cube'] cubes.append(cube) wvlBinEdges = np.array(cDict['wvlBinEdges']) cubes = np.array(cubes) times = np.array(timeStamps) ################################################# # Setup npz file to save imageStack intermediate/cal files, parameter, and output stackPath = os.path.join(calPath,"imageStacks") npzPath = os.path.join(stackPath,date) #if configFileName.split('/')[0] is not 'Params': # print "Config file not in Params! Output stack will have wrong filename!" # print configFileName.split('/')[0] # npzBaseName = target #else: npzBaseName = configFileName.split('/')[1].split('.')[0] npzFileName = npzPath+'/%s.npz'%npzBaseName print(npzFileName) np.savez(npzFileName, times=times, cubes=cubes, wvlBinEdges = wvlBinEdges) return {'cubes':cubes,'times':times,'wvlBinEdges':wvlBinEdges}