h5 = ObsFile(obsfile) print "ObsFile loaded" h5.loadWvlCalFile(calfile) print "WvlCal loaded" nypix = h5.nRow nxpix = h5.nCol image = np.empty((nypix,nxpix),dtype=int) colors = np.empty((nypix,nxpix),dtype = int) print "Making image" for i in xrange(nypix): for j in xrange(nxpix): photons = h5.getPixelWvlList(i,j,starttime,endtime) ind = np.where(np.logical_and((photons > startwl),(photons < stopwl))) #print "uncut counts = ", len(photons) photons = photons[ind] image[i,j] = len(photons) #print "cut counts = ", image[i,j] if color == True: try: colors[i,j] = np.median(photons) except: colors[i,j] = 10000 print "..." print "Finished constructing image" if n==1: totalimage = image
# Load time mask, wavelength calibration, and flat calibration and set wavelenth cutoffs. ob.loadHotPixCalFile(hotPixFn,switchOnMask=True) ob.loadWvlCalFile(wvlCalFilename) ob.loadFlatCalFile(flatCalFilename) ob.setWvlCutoffs(3000,5000) print 'Total load time: ' + str(time()-tic) + 's' tic = time() print 'Retrieving photon timestamps...' # Define the area of an observation containing the object. appMask = aperture(15,8,8) yValues,xValues = np.where(appMask==0) # Get a list of timestamps with photons from each pixel in the aperture. timestamps=[] for j in range(len(xValues)): x=ob.getPixelWvlList(iRow=yValues[j],iCol=xValues[j]) timestamps = np.append(timestamps,x['timestamps']) print 'Total retrieval time: ' + str(time()-tic) + 's' # Use timestamp data to perform periodograms. timestep = 5.0*10**-4 averagingTime = 2.0 exptime = ob.getFromHeader('exptime') totalAverageBins = int(exptime/averagingTime) timestepsPerBin = int(averagingTime/timestep) # Specify frequencies for which the periodogram algorithm should find transform components. freqs = np.linspace(1,1000,num=10**4) angularFreqs=2*np.pi*freqs binnedCounts, binEdges = np.histogram(timestamps,range=[0,exptime],bins = exptime/timestep) times = binEdges[0:timestepsPerBin]
exptime = ob.getFromHeader('exptime') unixtime= ob.getFromHeader('unixtime') if i == 0: unixOffset = unixtime exptimes[i]=exptime index1 = obsFn.find('_') hotPixFn = '/Scratch/timeMasks/timeMask' + obsFn[index1:] if not os.path.exists(hotPixFn): hp.findHotPixels(obsFn,hotPixFn) print "Flux file pixel mask saved to %s"%(hotPixFn) ob.loadHotPixCalFile(hotPixFn,switchOnMask=True) ob.loadWvlCalFile(wfn) ob.loadFlatCalFile(ffn) ob.setWvlCutoffs(3000,8000) for j in range(len(x_values)): x=ob.getPixelWvlList(iRow=y_values[j],iCol=x_values[j]) timestamps = np.append(timestamps,unixtime - unixOffset + (x['timestamps'])) print 'Loaded files in',time()-tic, 'seconds.' # Put photon in events in small time bins ~ 1 microsecond goal tic = time() print 'Binning photon events...' total_seconds = np.sum(exptimes) bins_per_second = 10**6 #time_bins = np.linspace(0,total_seconds,total_seconds*bins_per_second+1) #jd = time_bins/86400 #counts_per_timestep = np.zeros(len(time_bins)-1) #for j in range(len(time_bins)-1): #counts_per_timestep[j]=len(np.where(np.logical_and(timestamps>=time_bins[j],timestamps<time_bins[j+1]))[:][0]) counts_per_timestep, bin_edges = np.histogram(timestamps,bins = bins_per_second*total_seconds) jd =bin_edges[0:-1]