DifferentialPhotometry_functions_student.py
def doPhotometry(imglist, xpos, ypos, aprad, skybuff, skywidth,timekey='MJD-OBS',verbose=1): 
    '''
    doPhotomoetry*
    
    determine the flux for each star from aperture photometry
    
    inputs
    -------
    imglist: list - list of .fits images
    xpos, ypos: lists - lists of x and y positions of stars
    aprad, skybuff, skywidth: floats - aperture, sky annuli inner, sky annuli outer radii 
    
    outputs
    -------
    Times: list - time stamps of each observation from the .fits header
    Photometry: list - aperture photometry flux values found at each xpos, ypos position
    
    '''
    
    #number of images
    nimages = len(imglist)
    nstars = len(xpos)
    print('Found {} images'.format(nimages))
    
    #create lists for timestamps and flux values
    Times = np.zeros(nimages)
    Photometry = np.zeros((nimages,nstars))
    
    print('making apertures')
    #make the apertures around each star
    apertures, annulus_apertures = makeApertures(xpos, ypos, aprad, skybuff, skywidth)
    

    #plot apertures
    plt.figure(figsize=(10,10))
    interval = ZScaleInterval()
    vmin, vmax = interval.get_limits(fits.getdata(imglist[0]))
    plt.imshow(fits.getdata(imglist[0]), vmin=vmin,vmax=vmax, origin='lower')
    apertures.plot(color='white', lw=2)
    #annulus_apertures.plot(color='red', lw=2)
    plt.title('apertures')
    plt.show()
    
    #determine area of apertures
    area_of_ap = apertureArea(apertures)    

    #determine area of annuli
    area_of_background = backgroundArea(annulus_apertures)

    checknum = np.linspace(0,nimages,10).astype(int)


    #go through each image and run aperture photometry
    for ind in np.arange(nimages):

        if ((ind in checknum) & (verbose==1)):
            print('running aperture photometry on image: ', ind )

        if (verbose>1):
            print('running aperture photometry on image: ', ind )
            
        #open image
        data_image, hdr = fits.getdata(imglist[ind], header=True)
        
        #find time stamp and append to list
        Times[ind] = hdr[timekey]
        
        #do photometry
        phot_table = aperture_photometry(data_image, (apertures,annulus_apertures))
        
        #determine flux: (aperture flux) - [(area of aperture * annuli flux)/area of background ]
        flux0 = np.array(phot_table['aperture_sum_0']) - (area_of_ap/area_of_background)*np.array(phot_table['aperture_sum_1'])

        #append to list 
        Photometry[ind,:] = flux0
           
    return Times,Photometry

    doPhotomoetry*
    
    determine the flux for each star from aperture photometry
    
    inputs
    -------
    imglist: list - list of .fits images
    xpos, ypos: lists - lists of x and y positions of stars
    aprad, skybuff, skywidth: floats - aperture, sky annuli inner, sky annuli outer radii 
    
    outputs
    -------
    Times: list - time stamps of each observation from the .fits header
    Photometry: list - aperture photometry flux values found at each xpos, ypos position
    
    
doPhotomoetry
determine the flux for each star from aperture photometry

inputs

list of .fits images
xpos, ypos: lists - lists of x and y positions of stars
aprad, skybuff, skywidth: floats - aperture, sky annuli inner, sky annuli outer radii

outputs

time stamps of each observation from the .fits header
Photometry: list - aperture photometry flux values found at each xpos, ypos position
doPhotomoetry determine the flux for each star from aperture photometry inputs list of . fits images xpos ypos : lists - lists of x and y positions of stars aprad skybuff skywidth : floats - aperture sky annuli inner sky annuli outer radii outputs time stamps of each observation from the . fits header Photometry : list - aperture photometry flux values found at each xpos ypos position
def doPhotometry(imglist, xpos, ypos, aprad, skybuff, skywidth,timekey='MJD-OBS',verbose=1): 
    nimages = len(imglist)
    nstars = len(xpos)
    print('Found {} images'.format(nimages))
    Times = np.zeros(nimages)
    Photometry = np.zeros((nimages,nstars))
    print('making apertures')
    apertures, annulus_apertures = makeApertures(xpos, ypos, aprad, skybuff, skywidth)
    plt.figure(figsize=(10,10))
    interval = ZScaleInterval()
    vmin, vmax = interval.get_limits(fits.getdata(imglist[0]))
    plt.imshow(fits.getdata(imglist[0]), vmin=vmin,vmax=vmax, origin='lower')
    apertures.plot(color='white', lw=2)
    plt.title('apertures')
    plt.show()
    area_of_ap = apertureArea(apertures)    
    area_of_background = backgroundArea(annulus_apertures)
    checknum = np.linspace(0,nimages,10).astype(int)
    for ind in np.arange(nimages):
        if ((ind in checknum) & (verbose==1)):
            print('running aperture photometry on image: ', ind )
        if (verbose>1):
            print('running aperture photometry on image: ', ind )
        data_image, hdr = fits.getdata(imglist[ind], header=True)
        Times[ind] = hdr[timekey]
        phot_table = aperture_photometry(data_image, (apertures,annulus_apertures))
        flux0 = np.array(phot_table['aperture_sum_0']) - (area_of_ap/area_of_background)*np.array(phot_table['aperture_sum_1'])
        Photometry[ind,:] = flux0
    return Times,Photometry
def doPhotometry ( imglist , xpos , ypos , aprad , skybuff , skywidth , timekey = 'MJD-OBS' , verbose = 1 ) : nimages = len ( imglist ) nstars = len ( xpos ) print ( 'Found {} images' . format ( nimages ) ) Times = np . zeros ( nimages ) Photometry = np . zeros ( ( nimages , nstars ) ) print ( 'making apertures' ) apertures , annulus_apertures = makeApertures ( xpos , ypos , aprad , skybuff , skywidth ) plt . figure ( figsize = ( 10 , 10 ) ) interval = ZScaleInterval ( ) vmin , vmax = interval . get_limits ( fits . getdata ( imglist [ 0 ] ) ) plt . imshow ( fits . getdata ( imglist [ 0 ] ) , vmin = vmin , vmax = vmax , origin = 'lower' ) apertures . plot ( color = 'white' , lw = 2 ) plt . title ( 'apertures' ) plt . show ( ) area_of_ap = apertureArea ( apertures ) area_of_background = backgroundArea ( annulus_apertures ) checknum = np . linspace ( 0 , nimages , 10 ) . astype ( int ) for ind in np . arange ( nimages ) : if ( ( ind in checknum ) & ( verbose == 1 ) ) : print ( 'running aperture photometry on image: ' , ind ) if ( verbose > 1 ) : print ( 'running aperture photometry on image: ' , ind ) data_image , hdr = fits . getdata ( imglist [ ind ] , header = True ) Times [ ind ] = hdr [ timekey ] phot_table = aperture_photometry ( data_image , ( apertures , annulus_apertures ) ) flux0 = np . array ( phot_table [ 'aperture_sum_0' ] ) - ( area_of_ap / area_of_background ) * np . array ( phot_table [ 'aperture_sum_1' ] ) Photometry [ ind , : ] = flux0 return Times , Photometry
doPhotomoetry
determine the flux for each star from aperture photometry
doPhotomoetry determine the flux for each star from aperture photometry
'''
    doPhotomoetry*
    
    determine the flux for each star from aperture photometry
    
    inputs
    -------
    imglist: list - list of .fits images
    xpos, ypos: lists - lists of x and y positions of stars
    aprad, skybuff, skywidth: floats - aperture, sky annuli inner, sky annuli outer radii 
    
    outputs
    -------
    Times: list - time stamps of each observation from the .fits header
    Photometry: list - aperture photometry flux values found at each xpos, ypos position
    
    ''' #number of images #create lists for timestamps and flux values #make the apertures around each star #plot apertures #annulus_apertures.plot(color='red', lw=2) #determine area of apertures #determine area of annuli #go through each image and run aperture photometry #open image #find time stamp and append to list #do photometry #determine flux: (aperture flux) - [(area of aperture * annuli flux)/area of background ] #append to list 
imglist
xpos
ypos
aprad
skybuff
skywidth
timekey
verbose