Exemplo n.º 1
0
 def runMasterFlatMaker(self, event):
     path = self.masterFlatPathCtrl.GetValue()
     self.flatpaths = []
     for impath in self.flatImagesPathCtrl.GetValue().split(','):
         self.flatpaths += glob(impath)
     self.flatdarkpaths = []
     for dpath in self.flatDarksPathCtrl.GetValue().split(','):
         self.flatdarkpaths += glob(dpath)
     if not path.endswith('.fits') and not path.endswith('.fit'):
         path += '.fits'
     pathCorrected = path.replace('/', os.sep)
     outfolder = pathCorrected[:pathCorrected.rfind(os.sep)] + os.sep + '*'
     self.standardFlat = (self.flatRadioBox.GetSelection() == 0)
     if pathCorrected in glob(outfolder):
         OverwFlatFrame(pathCorrected,self,-1)
     else:
         if self.standardFlat:
             oscaar.standardFlatMaker(self.flatpaths, self.flatdarkpaths, self.masterFlatPathCtrl.GetValue(), self.plotsRadioBox.GetSelection() == 0)
         else: 
             oscaar.twilightFlatMaker(self.flatpaths, self.flatdarkpaths, self.masterFlatPathCtrl.GetValue(), self.plotsRadioBox.GetSelection() == 0)
         self.Destroy()
Exemplo n.º 2
0
 def runMasterFlatMaker(self, event):
     path = self.masterFlatPathCtrl.GetValue()
     self.flatpaths = []
     for impath in self.flatImagesPathCtrl.GetValue().split(','):
         self.flatpaths += glob(impath)
     self.flatdarkpaths = []
     for dpath in self.flatDarksPathCtrl.GetValue().split(','):
         self.flatdarkpaths += glob(dpath)
     if not path.endswith('.fits') and not path.endswith('.fit'):
         path += '.fits'
     pathCorrected = path.replace('/', os.sep)
     outfolder = pathCorrected[:pathCorrected.rfind(os.sep)] + os.sep + '*'
     self.standardFlat = (self.flatRadioBox.GetSelection() == 0)
     if pathCorrected in glob(outfolder):
         OverwFlatFrame(pathCorrected,self,-1)
     else:
         if self.standardFlat:
             oscaar.standardFlatMaker(self.flatpaths, self.flatdarkpaths, self.masterFlatPathCtrl.GetValue(), self.plotsRadioBox.GetSelection() == 0)
         else: 
             oscaar.twilightFlatMaker(self.flatpaths, self.flatdarkpaths, self.masterFlatPathCtrl.GetValue(), self.plotsRadioBox.GetSelection() == 0)
         self.Destroy()
Exemplo n.º 3
0
def main():
    #################################################################
    ## Tweak these parameters, if you like!
    NdataImages = 200        ## Number of data images to generate
    NdarkImages = 3          ## Number of dark frames to generate
    NflatImages = 3          ## Number of flat fields to generate
    flatFieldCounts = 20000  ## Approx counts per pixel in flat field
    imageDimensionX = 120    ## Pixel dimensions of each image
    imageDimensionY = 40
    starDimensions = 4       ## Pixel dimensions of the stars
    skyBackground = 500      ## Background counts from sky brightness
    darkBackground = 100     ## Background counts from detector
    targetFluxOOT = 10000    ## Flux (in counts) from each pixel of the unocculted target star (out-of-transit)
    relativeFluxCompA = 0.85 ## Flux from comp A relative to target
    relativeFluxCompB = 0.95 ## Flux from comp B relative to target
    plotModel = False        ## Plot the injected transit light curve
    createMasterFlatNow = True  ## Use oscaar to create a master flat from the freshly generated flat frames
    ## Isn't it nice to control the signal to noise?
    #################################################################
    
    ## Delete `images` directory, if there is one, and
    ##      make a fresh one.
    if len(glob(os.path.join(os.path.dirname(__file__),'images'))) > 0: rmtree(os.path.join(os.path.dirname(__file__),'images'))
    mkdir(os.path.join(os.path.dirname(__file__),'images'))
    
    ## Pixel positions of the stars (x,y)
    targetX = [20-starDimensions/2,20+starDimensions/2]
    compAX = [60-starDimensions/2,60+starDimensions/2]
    compBX = [100-starDimensions/2,100+starDimensions/2]
    starsY = [imageDimensionY/2-starDimensions/2,imageDimensionY/2+starDimensions/2]
    
    ## Set ingress/egress times, transiting system parameters 
    ## In GD: Ingress = 2013-05-15;10:06:30; egress = 2013-05-15;11:02:35
    jd0 = 2456427.88890 
    exposureTime = 45/(60*60*24.) ## Convert s -> hr
    times = np.arange(jd0,jd0+exposureTime*NdataImages,exposureTime)
    # [p,ap,P,i,gamma1,gamma2,e,longPericenter,t0]
    modelParams = [ 0.1179, 14.71, 1.580400, 90.0, 0.23, \
                    0.30, 0.00, 0.0, np.mean(times,dtype=np.float64)]
    np.savetxt(os.path.join(os.path.dirname(__file__),'modelParams.txt'),modelParams)
    modelLightCurve = oscaar.occultquad(times,modelParams)
    if plotModel: 
    	fig = plt.figure()
    	ax1 = fig.add_subplot(111)
    	def format_coord(x, y):
    		'''Function to also give data value on mouse over with imshow.'''
    		return 'JD=%1.6f, Flux=%1.6f' % (x, y)
    	ax1.set_xlabel('Time (JD)')
    	ax1.set_ylabel('Relative Flux')
    	ax1.set_title('Injected Light Curve')
    	ax1.plot(times,modelLightCurve)
    	ax1.format_coord = format_coord
    	plt.show()
    
    ## For producing random arrays, initialize reference arrays with the proper shapes
    imageShapedMatrix = np.zeros([imageDimensionY,imageDimensionX])
    starShapedMatrix = np.zeros([starDimensions,starDimensions])
    
    ## Simulate dark frames with shot noise
    for i in range(NdarkImages):
        darkFrame = darkBackground + np.random.normal(imageShapedMatrix,np.sqrt(darkBackground))
        darkFrame = np.require(darkFrame,dtype=int)   ## Require integer counts
        pyfits.writeto(os.path.join(os.path.dirname(__file__),'images/simulatedImg-'+str(i).zfill(3)+'d.fits'),darkFrame)
    
    ## Simulate ideal flat frames (perfectly flat)
    for i in range(NflatImages):
        ## Flats will be completely flat -- ie, we're pretending that we have a 
        ##      perfect optical path with no spatial flux variations.
        flatField = np.zeros([imageDimensionY,imageDimensionX]) +  flatFieldCounts
        flatField = np.require(flatField,dtype=int)## Require integer counts
        pyfits.writeto(os.path.join(os.path.dirname(__file__),'images/simulatedImg-'+str(i).zfill(3)+'f.fits'),flatField)
    
    
    ## Create master flat now using oscaar's standard flat maker
    if createMasterFlatNow:
        flatPaths = glob(os.path.join(os.path.dirname(__file__),'images/simulatedImg-???f.fits'))
        flatDarkPaths = glob(os.path.join(os.path.dirname(__file__),'images/simulatedImg-???d.fits'))   ## Use the same darks
        masterFlatSavePath = os.path.join(os.path.dirname(__file__),'images/masterFlat.fits')   ## Where to save the master
        oscaar.standardFlatMaker(flatPaths,flatDarkPaths,masterFlatSavePath,plots=False)
    
    
    ## Create data images
    for i in range(NdataImages):
        ## Produce image with sky and dark background with simulated photon noise for each source
        simulatedImage = darkBackground + skyBackground +\
            np.random.normal(imageShapedMatrix,np.sqrt(darkBackground)) +\
            np.random.normal(imageShapedMatrix,np.sqrt(skyBackground))
        
        ## Create two box-shaped stars with simulated photon noise
        targetBrightness = targetFluxOOT*modelLightCurve[i]  ## Scale brightness with the light curve
        target = targetBrightness + np.random.normal(starShapedMatrix,np.sqrt(targetBrightness))
        
        compBrightnessA = targetFluxOOT*relativeFluxCompA
        compBrightnessB = targetFluxOOT*relativeFluxCompB
        compA = compBrightnessA + np.random.normal(starShapedMatrix,np.sqrt(compBrightnessA))
        compB = compBrightnessB + np.random.normal(starShapedMatrix,np.sqrt(compBrightnessB))
        
        ## Add stars onto the simulated image with some position jitter
        randomPositionJitterX = np.sign(np.random.uniform(-1,1))	## +/- 1 pixel stellar centroid position jitter
        randomPositionJitterY = np.sign(np.random.uniform(-1,1))	## +/- 1 pixel stellar centroid position jitter
        simulatedImage[starsY[0]+randomPositionJitterY:starsY[1]+randomPositionJitterY,targetX[0]+randomPositionJitterX:targetX[1]+randomPositionJitterX] += target
        simulatedImage[starsY[0]+randomPositionJitterY:starsY[1]+randomPositionJitterY,compAX[0]+randomPositionJitterX:compAX[1]+randomPositionJitterX] += compA
        simulatedImage[starsY[0]+randomPositionJitterY:starsY[1]+randomPositionJitterY,compBX[0]+randomPositionJitterX:compBX[1]+randomPositionJitterX] += compB
    
        ## Force counts to integers, save.
        simulatedImage = np.require(simulatedImage,dtype=int)   ## Require integer counts before save
    
        header = pyfits.Header()
        header.append(('JD',times[i],'Simulated Time (Julian Date)'))
        pyfits.writeto(os.path.join(os.path.dirname(__file__),'images/simulatedImg-'+str(i).zfill(3)+'r.fits'),simulatedImage,header=header)
Exemplo n.º 4
0
def main():
    #################################################################
    ## Tweak these parameters, if you like!
    NdataImages = 200  ## Number of data images to generate
    NdarkImages = 3  ## Number of dark frames to generate
    NflatImages = 3  ## Number of flat fields to generate
    flatFieldCounts = 20000  ## Approx counts per pixel in flat field
    imageDimensionX = 120  ## Pixel dimensions of each image
    imageDimensionY = 40
    starDimensions = 4  ## Pixel dimensions of the stars
    skyBackground = 500  ## Background counts from sky brightness
    darkBackground = 100  ## Background counts from detector
    targetFluxOOT = 10000  ## Flux (in counts) from each pixel of the unocculted target star (out-of-transit)
    relativeFluxCompA = 0.85  ## Flux from comp A relative to target
    relativeFluxCompB = 0.95  ## Flux from comp B relative to target
    plotModel = False  ## Plot the injected transit light curve
    createMasterFlatNow = True  ## Use oscaar to create a master flat from the freshly generated flat frames
    ## Isn't it nice to control the signal to noise?
    #################################################################

    ## Delete `images` directory, if there is one, and
    ##      make a fresh one.
    if len(glob(os.path.join(os.path.dirname(__file__), 'images'))) > 0:
        rmtree(os.path.join(os.path.dirname(__file__), 'images'))
    mkdir(os.path.join(os.path.dirname(__file__), 'images'))

    ## Pixel positions of the stars (x,y)
    targetX = [20 - starDimensions / 2, 20 + starDimensions / 2]
    compAX = [60 - starDimensions / 2, 60 + starDimensions / 2]
    compBX = [100 - starDimensions / 2, 100 + starDimensions / 2]
    starsY = [
        imageDimensionY / 2 - starDimensions / 2,
        imageDimensionY / 2 + starDimensions / 2
    ]

    ## Set ingress/egress times, transiting system parameters
    ## In GD: Ingress = 2013-05-15;10:06:30; egress = 2013-05-15;11:02:35
    jd0 = 2456427.88890
    exposureTime = 45 / (60 * 60 * 24.)  ## Convert s -> hr
    times = np.arange(jd0, jd0 + exposureTime * NdataImages, exposureTime)
    # [p,ap,P,i,gamma1,gamma2,e,longPericenter,t0]
    modelParams = [ 0.1179, 14.71, 1.580400, 90.0, 0.23, \
                    0.30, 0.00, 0.0, np.mean(times,dtype=np.float64)]
    np.savetxt(os.path.join(os.path.dirname(__file__), 'modelParams.txt'),
               modelParams)
    modelLightCurve = oscaar.occultquad(times, modelParams)
    if plotModel:
        fig = plt.figure()
        ax1 = fig.add_subplot(111)

        def format_coord(x, y):
            '''Function to also give data value on mouse over with imshow.'''
            return 'JD=%1.6f, Flux=%1.6f' % (x, y)

        ax1.set_xlabel('Time (JD)')
        ax1.set_ylabel('Relative Flux')
        ax1.set_title('Injected Light Curve')
        ax1.plot(times, modelLightCurve)
        ax1.format_coord = format_coord
        plt.show()

    ## For producing random arrays, initialize reference arrays with the proper shapes
    imageShapedMatrix = np.zeros([imageDimensionY, imageDimensionX])
    starShapedMatrix = np.zeros([starDimensions, starDimensions])

    ## Simulate dark frames with shot noise
    for i in range(NdarkImages):
        darkFrame = darkBackground + np.random.normal(imageShapedMatrix,
                                                      np.sqrt(darkBackground))
        darkFrame = np.require(darkFrame, dtype=int)  ## Require integer counts
        pyfits.writeto(
            os.path.join(os.path.dirname(__file__),
                         'images/simulatedImg-' + str(i).zfill(3) + 'd.fits'),
            darkFrame)

    ## Simulate ideal flat frames (perfectly flat)
    for i in range(NflatImages):
        ## Flats will be completely flat -- ie, we're pretending that we have a
        ##      perfect optical path with no spatial flux variations.
        flatField = np.zeros([imageDimensionY, imageDimensionX
                              ]) + flatFieldCounts
        flatField = np.require(flatField, dtype=int)  ## Require integer counts
        pyfits.writeto(
            os.path.join(os.path.dirname(__file__),
                         'images/simulatedImg-' + str(i).zfill(3) + 'f.fits'),
            flatField)

    ## Create master flat now using oscaar's standard flat maker
    if createMasterFlatNow:
        flatPaths = glob(
            os.path.join(os.path.dirname(__file__),
                         'images/simulatedImg-???f.fits'))
        flatDarkPaths = glob(
            os.path.join(
                os.path.dirname(__file__),
                'images/simulatedImg-???d.fits'))  ## Use the same darks
        masterFlatSavePath = os.path.join(
            os.path.dirname(__file__),
            'images/masterFlat.fits')  ## Where to save the master
        oscaar.standardFlatMaker(flatPaths,
                                 flatDarkPaths,
                                 masterFlatSavePath,
                                 plots=False)

    ## Create data images
    for i in range(NdataImages):
        ## Produce image with sky and dark background with simulated photon noise for each source
        simulatedImage = darkBackground + skyBackground +\
            np.random.normal(imageShapedMatrix,np.sqrt(darkBackground)) +\
            np.random.normal(imageShapedMatrix,np.sqrt(skyBackground))

        ## Create two box-shaped stars with simulated photon noise
        targetBrightness = targetFluxOOT * modelLightCurve[
            i]  ## Scale brightness with the light curve
        target = targetBrightness + np.random.normal(starShapedMatrix,
                                                     np.sqrt(targetBrightness))

        compBrightnessA = targetFluxOOT * relativeFluxCompA
        compBrightnessB = targetFluxOOT * relativeFluxCompB
        compA = compBrightnessA + np.random.normal(starShapedMatrix,
                                                   np.sqrt(compBrightnessA))
        compB = compBrightnessB + np.random.normal(starShapedMatrix,
                                                   np.sqrt(compBrightnessB))

        ## Add stars onto the simulated image with some position jitter
        randomPositionJitterX = np.sign(np.random.uniform(
            -1, 1))  ## +/- 1 pixel stellar centroid position jitter
        randomPositionJitterY = np.sign(np.random.uniform(
            -1, 1))  ## +/- 1 pixel stellar centroid position jitter
        simulatedImage[starsY[0] + randomPositionJitterY:starsY[1] +
                       randomPositionJitterY,
                       targetX[0] + randomPositionJitterX:targetX[1] +
                       randomPositionJitterX] += target
        simulatedImage[starsY[0] + randomPositionJitterY:starsY[1] +
                       randomPositionJitterY,
                       compAX[0] + randomPositionJitterX:compAX[1] +
                       randomPositionJitterX] += compA
        simulatedImage[starsY[0] + randomPositionJitterY:starsY[1] +
                       randomPositionJitterY,
                       compBX[0] + randomPositionJitterX:compBX[1] +
                       randomPositionJitterX] += compB

        ## Force counts to integers, save.
        simulatedImage = np.require(
            simulatedImage, dtype=int)  ## Require integer counts before save

        header = pyfits.Header()
        header.append(('JD', times[i], 'Simulated Time (Julian Date)'))
        pyfits.writeto(os.path.join(
            os.path.dirname(__file__),
            'images/simulatedImg-' + str(i).zfill(3) + 'r.fits'),
                       simulatedImage,
                       header=header)