DifferentialPhotometry_functions_student.py
def doPhotometryError(imglist,xpos, ypos,aprad, skybuff, skywidth, flux0, GAIN=1.3, manual = False, **kwargs):
    '''
    doPhotometryError
    
    determine error in photometry from background noise 
    two options:
    - use sigma clipping and use whole background
    - manually input background box positions as kwargs
    
    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 
    flux0: list - aperture photometry found from doPhotometry() function
    GAIN: float - average gain 
    manual: boolean - switch between manually inputting box (True) or using sigma clipping (False)
                        if True -- must have kwargs
                        manual = False is default
    **kwargs
        kwargs[xboxcorner]: float - x edge of box in pixel coords
        kwargs[yboxcorner]: float - y edge of box in pixel coords
        kwargs[boxsize]: float - size of box in pixel coords
     

    '''
    
    # find number of images in list
    nimages = len(imglist)
    nstars = len(xpos)
    print('Found {} images'.format(nimages))
    
    #make apertures
    apertures, annulus_apertures = makeApertures(xpos, ypos, aprad, skybuff, skywidth)
    
    #find areas of apertures and annuli
    area_of_ap = apertureArea(apertures)    
    area_of_background = backgroundArea(annulus_apertures)

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

    #find error in photometry
    ePhotometry = np.zeros((nimages,nstars))
    for ind in np.arange(nimages):
        #open images
        im = fits.getdata(imglist[ind])

        if ind in checknum:
            print('running error analysis on image ', ind)
        
        #determine variance in background 
        if manual == True: #manual method -- choose back size
            skyvar = np.std(im[kwargs['xboxcorner']:kwargs['xboxcorner']+kwargs['boxsize'],kwargs['yboxcorner']:kwargs['yboxcorner']+kwargs['boxsize']])**2.
            err1 = skyvar*(area_of_ap)**2./(kwargs['boxsize']*kwargs['boxsize'])  # uncertainty in mean sky brightness
        if manual == False: #automatic method -- use sigma clipping
            filtered_data = sigma_clip(im, sigma=3)
            skyvar = np.std(filtered_data)**2.
            err1 = skyvar*(area_of_ap)**2./(np.shape(im[0])[0]*np.shape(im[1])[0])  # uncertainty in mean sky brightness
    
        err2 = area_of_ap * skyvar  # scatter in sky values
        err3 = flux0[ind]/GAIN # Poisson error
        print ('Scatter in sky values: ',err2**0.5,', uncertainty in mean sky brightness: ',err1**0.5)
        
        # sum souces of error in quadrature
        errtot = (err1 + err2 + err3)**0.5
        #append to list
        ePhotometry[ind,:] = errtot
        
    return ePhotometry

    doPhotometryError
    
    determine error in photometry from background noise 
    two options:
    - use sigma clipping and use whole background
    - manually input background box positions as kwargs
    
    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 
    flux0: list - aperture photometry found from doPhotometry() function
    GAIN: float - average gain 
    manual: boolean - switch between manually inputting box (True) or using sigma clipping (False)
                        if True -- must have kwargs
                        manual = False is default
    **kwargs
        kwargs[xboxcorner]: float - x edge of box in pixel coords
        kwargs[yboxcorner]: float - y edge of box in pixel coords
        kwargs[boxsize]: float - size of box in pixel coords
     

    
doPhotometryError
determine error in photometry from background noise
two options:
use sigma clipping and use whole background
manually input background box positions as kwargs

inputs


doPhotometryError determine error in photometry from background noise two options : use sigma clipping and use whole background manually input background box positions as kwargs inputs
def doPhotometryError(imglist,xpos, ypos,aprad, skybuff, skywidth, flux0, GAIN=1.3, manual = False, **kwargs):
    nimages = len(imglist)
    nstars = len(xpos)
    print('Found {} images'.format(nimages))
    apertures, annulus_apertures = makeApertures(xpos, ypos, aprad, skybuff, skywidth)
    area_of_ap = apertureArea(apertures)    
    area_of_background = backgroundArea(annulus_apertures)
    checknum = np.linspace(0,nimages,10).astype(int)
    ePhotometry = np.zeros((nimages,nstars))
    for ind in np.arange(nimages):
        im = fits.getdata(imglist[ind])
        if ind in checknum:
            print('running error analysis on image ', ind)
        if manual == True: 
            skyvar = np.std(im[kwargs['xboxcorner']:kwargs['xboxcorner']+kwargs['boxsize'],kwargs['yboxcorner']:kwargs['yboxcorner']+kwargs['boxsize']])**2.
            err1 = skyvar*(area_of_ap)**2./(kwargs['boxsize']*kwargs['boxsize'])  
        if manual == False: 
            filtered_data = sigma_clip(im, sigma=3)
            skyvar = np.std(filtered_data)**2.
            err1 = skyvar*(area_of_ap)**2./(np.shape(im[0])[0]*np.shape(im[1])[0])  
        err2 = area_of_ap * skyvar  
        err3 = flux0[ind]/GAIN 
        print ('Scatter in sky values: ',err2**0.5,', uncertainty in mean sky brightness: ',err1**0.5)
        errtot = (err1 + err2 + err3)**0.5
        ePhotometry[ind,:] = errtot
    return ePhotometry
def doPhotometryError ( imglist , xpos , ypos , aprad , skybuff , skywidth , flux0 , GAIN = 1.3 , manual = False , ** kwargs ) : nimages = len ( imglist ) nstars = len ( xpos ) print ( 'Found {} images' . format ( nimages ) ) apertures , annulus_apertures = makeApertures ( xpos , ypos , aprad , skybuff , skywidth ) area_of_ap = apertureArea ( apertures ) area_of_background = backgroundArea ( annulus_apertures ) checknum = np . linspace ( 0 , nimages , 10 ) . astype ( int ) ePhotometry = np . zeros ( ( nimages , nstars ) ) for ind in np . arange ( nimages ) : im = fits . getdata ( imglist [ ind ] ) if ind in checknum : print ( 'running error analysis on image ' , ind ) if manual == True : skyvar = np . std ( im [ kwargs [ 'xboxcorner' ] : kwargs [ 'xboxcorner' ] + kwargs [ 'boxsize' ] , kwargs [ 'yboxcorner' ] : kwargs [ 'yboxcorner' ] + kwargs [ 'boxsize' ] ] ) ** 2. err1 = skyvar * ( area_of_ap ) ** 2. / ( kwargs [ 'boxsize' ] * kwargs [ 'boxsize' ] ) if manual == False : filtered_data = sigma_clip ( im , sigma = 3 ) skyvar = np . std ( filtered_data ) ** 2. err1 = skyvar * ( area_of_ap ) ** 2. / ( np . shape ( im [ 0 ] ) [ 0 ] * np . shape ( im [ 1 ] ) [ 0 ] ) err2 = area_of_ap * skyvar err3 = flux0 [ ind ] / GAIN print ( 'Scatter in sky values: ' , err2 ** 0.5 , ', uncertainty in mean sky brightness: ' , err1 ** 0.5 ) errtot = ( err1 + err2 + err3 ) ** 0.5 ePhotometry [ ind , : ] = errtot return ePhotometry
doPhotometryError
determine error in photometry from background noise
two options:
 use sigma clipping and use whole background
 manually input background box positions as kwargs
doPhotometryError determine error in photometry from background noise two options : use sigma clipping and use whole background manually input background box positions as kwargs
'''
    doPhotometryError
    
    determine error in photometry from background noise 
    two options:
    - use sigma clipping and use whole background
    - manually input background box positions as kwargs
    
    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 
    flux0: list - aperture photometry found from doPhotometry() function
    GAIN: float - average gain 
    manual: boolean - switch between manually inputting box (True) or using sigma clipping (False)
                        if True -- must have kwargs
                        manual = False is default
    **kwargs
        kwargs[xboxcorner]: float - x edge of box in pixel coords
        kwargs[yboxcorner]: float - y edge of box in pixel coords
        kwargs[boxsize]: float - size of box in pixel coords
     

    ''' # find number of images in list #make apertures #find areas of apertures and annuli #find error in photometry #open images #determine variance in background  #manual method -- choose back size # uncertainty in mean sky brightness #automatic method -- use sigma clipping # uncertainty in mean sky brightness # scatter in sky values # Poisson error # sum souces of error in quadrature #append to list
imglist
xpos
ypos
aprad
skybuff
skywidth
flux0
GAIN
manual