Spring2020/PythonPhotometry/Sarah_DiffPhotometry.py
def runDifferentialPhotometry(Photometry, ePhotometry, nstars, most_accurate):

    '''
    runDifferentialPhotometry
    
    as the name says!
    
    inputs
    ----------
    Photometry: list - list of photometric values from detrend() function
    ePhotometry: list - list of photometric error values
    nstars: float - number of stars 
    most_accurate: list - list of indices of non variable comparison stars
    
    outputs
    ---------
    dPhotometry: list - differential photometry list
    edPhotometry: list - scaling factors to photometry error
    tePhotometry: list - differential photometry error
    
    '''

    #number of nights of photometry
    nimages = len(Photometry)
    
    #range of number of nights
    imgindex = np.arange(0,nimages,1)

    #create lists for diff photometry
    dPhotometry = np.zeros([nimages,len(Photometry[0])])
    edPhotometry = np.zeros([nimages,len(Photometry[0])])
    eedPhotometry = np.zeros([nimages,len(Photometry[0])])
    tePhotometry = np.zeros([nimages,len(Photometry[0])])

    checkstars = np.linspace(0,nstars,10).astype(int)


    
    for star in range(0,nstars):

        if star in checkstars:
        
            print('running differential photometry on star: ', star, '/', nstars)
            
        #pull out each star's photometry + error Photometry for each night and place in list 
        starPhotometry = np.array([starPhot[star] for starPhot in Photometry])
        starPhotometryerr = np.array([starPhoterr[star] for starPhoterr in ePhotometry])
        
        #create temporary photometry list for each comparison star
        tmp_phot = np.zeros([nimages,len(most_accurate)])

        #go through comparison stars and determine differential photometry
        for ind,comparison_index in enumerate(most_accurate):
            #pull out comparison star's photometry for each night and place in list 
            compStarPhotometry = np.array([starPhot[comparison_index] for starPhot in Photometry])
            
            #calculate differential photometry
            tmp_phot[:,ind] = (starPhotometry*np.nanmedian(compStarPhotometry))/(compStarPhotometry*np.nanmedian(starPhotometry))
       
        #median combine differential photometry found with each comparison star for every other star
        dPhotometry[:,star] = np.nanmedian(tmp_phot,axis=1)
        
        # apply final scaling factors to the photometric error
        edPhotometry[:,star] = starPhotometryerr*(np.nanmedian(tmp_phot,axis=1)/starPhotometry)

        # the differential photometry error
        eedPhotometry[:,star] = np.nanstd(tmp_phot,axis=1)

        # the differential photometry error
        tePhotometry[:,star] = ((starPhotometryerr*(np.nanmedian(tmp_phot,axis=1)/starPhotometry))**2. + (np.nanstd(tmp_phot,axis=1))**2.)**0.5
        
    return dPhotometry, edPhotometry, tePhotometry

    runDifferentialPhotometry
    
    as the name says!
    
    inputs
    ----------
    Photometry: list - list of photometric values from detrend() function
    ePhotometry: list - list of photometric error values
    nstars: float - number of stars 
    most_accurate: list - list of indices of non variable comparison stars
    
    outputs
    ---------
    dPhotometry: list - differential photometry list
    edPhotometry: list - scaling factors to photometry error
    tePhotometry: list - differential photometry error
    
    
runDifferentialPhotometry
as the name says!

inputs

list of photometric values from detrend() function
ePhotometry: list - list of photometric error values
nstars: float - number of stars
most_accurate: list - list of indices of non variable comparison stars

outputs

differential photometry list
edPhotometry: list - scaling factors to photometry error
tePhotometry: list - differential photometry error
runDifferentialPhotometry as the name says! inputs list of photometric values from detrend () function ePhotometry : list - list of photometric error values nstars : float - number of stars most_accurate : list - list of indices of non variable comparison stars outputs differential photometry list edPhotometry : list - scaling factors to photometry error tePhotometry : list - differential photometry error
def runDifferentialPhotometry(Photometry, ePhotometry, nstars, most_accurate):
    nimages = len(Photometry)
    imgindex = np.arange(0,nimages,1)
    dPhotometry = np.zeros([nimages,len(Photometry[0])])
    edPhotometry = np.zeros([nimages,len(Photometry[0])])
    eedPhotometry = np.zeros([nimages,len(Photometry[0])])
    tePhotometry = np.zeros([nimages,len(Photometry[0])])
    checkstars = np.linspace(0,nstars,10).astype(int)
    for star in range(0,nstars):
        if star in checkstars:
            print('running differential photometry on star: ', star, '/', nstars)
        starPhotometry = np.array([starPhot[star] for starPhot in Photometry])
        starPhotometryerr = np.array([starPhoterr[star] for starPhoterr in ePhotometry])
        tmp_phot = np.zeros([nimages,len(most_accurate)])
        for ind,comparison_index in enumerate(most_accurate):
            compStarPhotometry = np.array([starPhot[comparison_index] for starPhot in Photometry])
            tmp_phot[:,ind] = (starPhotometry*np.nanmedian(compStarPhotometry))/(compStarPhotometry*np.nanmedian(starPhotometry))
        dPhotometry[:,star] = np.nanmedian(tmp_phot,axis=1)
        edPhotometry[:,star] = starPhotometryerr*(np.nanmedian(tmp_phot,axis=1)/starPhotometry)
        eedPhotometry[:,star] = np.nanstd(tmp_phot,axis=1)
        tePhotometry[:,star] = ((starPhotometryerr*(np.nanmedian(tmp_phot,axis=1)/starPhotometry))**2. + (np.nanstd(tmp_phot,axis=1))**2.)**0.5
    return dPhotometry, edPhotometry, tePhotometry
def runDifferentialPhotometry ( Photometry , ePhotometry , nstars , most_accurate ) : nimages = len ( Photometry ) imgindex = np . arange ( 0 , nimages , 1 ) dPhotometry = np . zeros ( [ nimages , len ( Photometry [ 0 ] ) ] ) edPhotometry = np . zeros ( [ nimages , len ( Photometry [ 0 ] ) ] ) eedPhotometry = np . zeros ( [ nimages , len ( Photometry [ 0 ] ) ] ) tePhotometry = np . zeros ( [ nimages , len ( Photometry [ 0 ] ) ] ) checkstars = np . linspace ( 0 , nstars , 10 ) . astype ( int ) for star in range ( 0 , nstars ) : if star in checkstars : print ( 'running differential photometry on star: ' , star , '/' , nstars ) starPhotometry = np . array ( [ starPhot [ star ] for starPhot in Photometry ] ) starPhotometryerr = np . array ( [ starPhoterr [ star ] for starPhoterr in ePhotometry ] ) tmp_phot = np . zeros ( [ nimages , len ( most_accurate ) ] ) for ind , comparison_index in enumerate ( most_accurate ) : compStarPhotometry = np . array ( [ starPhot [ comparison_index ] for starPhot in Photometry ] ) tmp_phot [ : , ind ] = ( starPhotometry * np . nanmedian ( compStarPhotometry ) ) / ( compStarPhotometry * np . nanmedian ( starPhotometry ) ) dPhotometry [ : , star ] = np . nanmedian ( tmp_phot , axis = 1 ) edPhotometry [ : , star ] = starPhotometryerr * ( np . nanmedian ( tmp_phot , axis = 1 ) / starPhotometry ) eedPhotometry [ : , star ] = np . nanstd ( tmp_phot , axis = 1 ) tePhotometry [ : , star ] = ( ( starPhotometryerr * ( np . nanmedian ( tmp_phot , axis = 1 ) / starPhotometry ) ) ** 2. + ( np . nanstd ( tmp_phot , axis = 1 ) ) ** 2. ) ** 0.5 return dPhotometry , edPhotometry , tePhotometry
runDifferentialPhotometry
as the name says!
runDifferentialPhotometry as the name says!
'''
    runDifferentialPhotometry
    
    as the name says!
    
    inputs
    ----------
    Photometry: list - list of photometric values from detrend() function
    ePhotometry: list - list of photometric error values
    nstars: float - number of stars 
    most_accurate: list - list of indices of non variable comparison stars
    
    outputs
    ---------
    dPhotometry: list - differential photometry list
    edPhotometry: list - scaling factors to photometry error
    tePhotometry: list - differential photometry error
    
    ''' #number of nights of photometry #range of number of nights #create lists for diff photometry #pull out each star's photometry + error Photometry for each night and place in list  #create temporary photometry list for each comparison star #go through comparison stars and determine differential photometry #pull out comparison star's photometry for each night and place in list  #calculate differential photometry #median combine differential photometry found with each comparison star for every other star # apply final scaling factors to the photometric error # the differential photometry error # the differential photometry error
Photometry
ePhotometry
nstars
most_accurate