DifferentialPhotometry_functions_student.py
def detrend(idx, Photometry_initial, ePhotometry, nstars, sn_thresh):
    '''
    detrend the background for each night to find least variable comparison stars
    
    inputs
    -------
    idx                 :   list - list of indices of target stars
    Photometry_initial  :   list - list of flux values from aperture photometry
    ePhotometry         :   list - list of flux errors from aperture photometry
    nstars              :   float - number of stars in the field
    sn_thresh           :   float - S/N threshold of what is considered a star or not (good value to use: 3)
    
    outputs
    --------
    Photometry_fin_mask :   list - final aperture photometry of sources with bad sources masked out  
    cPhotometry_mask    :   list - detrended aperture photometry with bad sources masked out
    
    '''
    #determine S/N of all sources
    sn = Photometry_initial / ePhotometry
    
    #mask out bad photometry: photometry < 0, S/N is less than threshold
    Photometry_mask1 = ma.masked_where(Photometry_initial <= 0, Photometry_initial)
    Photometry_mask2 = ma.masked_where(sn < sn_thresh, Photometry_mask1)
    #mask out target stars
    m = np.zeros_like(Photometry_mask2)
    m[:,idx] = 1
    Photometry_fin_mask = ma.masked_array(Photometry_mask2, m)
       
    #find median of all photometry
    med_val = np.median(Photometry_fin_mask, axis=0)
    
    #mask out photometry where the median value is < 0
    c = np.zeros_like(Photometry_fin_mask)
    c[:,med_val<=0] = 1

    # get median flux value for each star (find percent change)
    cPhotometry = ma.masked_array(Photometry_fin_mask, c)
    cPhotometry = cPhotometry / med_val

    # do a check for outlier photometry?
    for night in np.arange(len(cPhotometry)):
        # remove large-scale image-to-image variation to find best stars
        cPhotometry[night] = cPhotometry[night] / np.median(cPhotometry[night])
    # eliminate stars with outliers from consideration 
    cPhotometry_mask = ma.masked_where( ((cPhotometry < 0.5) | (cPhotometry > 1.5)), cPhotometry)
    
    return Photometry_fin_mask, cPhotometry_mask

    detrend the background for each night to find least variable comparison stars
    
    inputs
    -------
    idx                 :   list - list of indices of target stars
    Photometry_initial  :   list - list of flux values from aperture photometry
    ePhotometry         :   list - list of flux errors from aperture photometry
    nstars              :   float - number of stars in the field
    sn_thresh           :   float - S/N threshold of what is considered a star or not (good value to use: 3)
    
    outputs
    --------
    Photometry_fin_mask :   list - final aperture photometry of sources with bad sources masked out  
    cPhotometry_mask    :   list - detrended aperture photometry with bad sources masked out
    
    
detrend the background for each night to find least variable comparison stars
inputs



outputs

Photometry_fin_mask :   list - final aperture photometry of sources with bad sources masked out
cPhotometry_mask    :   list - detrended aperture photometry with bad sources masked out
detrend the background for each night to find least variable comparison stars inputs outputs Photometry_fin_mask : list - final aperture photometry of sources with bad sources masked out cPhotometry_mask : list - detrended aperture photometry with bad sources masked out
def detrend(idx, Photometry_initial, ePhotometry, nstars, sn_thresh):
    sn = Photometry_initial / ePhotometry
    Photometry_mask1 = ma.masked_where(Photometry_initial <= 0, Photometry_initial)
    Photometry_mask2 = ma.masked_where(sn < sn_thresh, Photometry_mask1)
    m = np.zeros_like(Photometry_mask2)
    m[:,idx] = 1
    Photometry_fin_mask = ma.masked_array(Photometry_mask2, m)
    med_val = np.median(Photometry_fin_mask, axis=0)
    c = np.zeros_like(Photometry_fin_mask)
    c[:,med_val<=0] = 1
    cPhotometry = ma.masked_array(Photometry_fin_mask, c)
    cPhotometry = cPhotometry / med_val
    for night in np.arange(len(cPhotometry)):
        cPhotometry[night] = cPhotometry[night] / np.median(cPhotometry[night])
    cPhotometry_mask = ma.masked_where( ((cPhotometry < 0.5) | (cPhotometry > 1.5)), cPhotometry)
    return Photometry_fin_mask, cPhotometry_mask
def detrend ( idx , Photometry_initial , ePhotometry , nstars , sn_thresh ) : sn = Photometry_initial / ePhotometry Photometry_mask1 = ma . masked_where ( Photometry_initial <= 0 , Photometry_initial ) Photometry_mask2 = ma . masked_where ( sn < sn_thresh , Photometry_mask1 ) m = np . zeros_like ( Photometry_mask2 ) m [ : , idx ] = 1 Photometry_fin_mask = ma . masked_array ( Photometry_mask2 , m ) med_val = np . median ( Photometry_fin_mask , axis = 0 ) c = np . zeros_like ( Photometry_fin_mask ) c [ : , med_val <= 0 ] = 1 cPhotometry = ma . masked_array ( Photometry_fin_mask , c ) cPhotometry = cPhotometry / med_val for night in np . arange ( len ( cPhotometry ) ) : cPhotometry [ night ] = cPhotometry [ night ] / np . median ( cPhotometry [ night ] ) cPhotometry_mask = ma . masked_where ( ( ( cPhotometry < 0.5 ) | ( cPhotometry > 1.5 ) ) , cPhotometry ) return Photometry_fin_mask , cPhotometry_mask
detrend the background for each night to find least variable comparison stars
inputs
detrend the background for each night to find least variable comparison stars inputs
'''
    detrend the background for each night to find least variable comparison stars
    
    inputs
    -------
    idx                 :   list - list of indices of target stars
    Photometry_initial  :   list - list of flux values from aperture photometry
    ePhotometry         :   list - list of flux errors from aperture photometry
    nstars              :   float - number of stars in the field
    sn_thresh           :   float - S/N threshold of what is considered a star or not (good value to use: 3)
    
    outputs
    --------
    Photometry_fin_mask :   list - final aperture photometry of sources with bad sources masked out  
    cPhotometry_mask    :   list - detrended aperture photometry with bad sources masked out
    
    ''' #determine S/N of all sources #mask out bad photometry: photometry < 0, S/N is less than threshold #mask out target stars #find median of all photometry #mask out photometry where the median value is < 0 # get median flux value for each star (find percent change) # do a check for outlier photometry? # remove large-scale image-to-image variation to find best stars # eliminate stars with outliers from consideration 
idx
Photometry_initial
ePhotometry
nstars
sn_thresh