<jupyter_start><jupyter_text>Imports<jupyter_code>import sp
from astropy.io import ascii
import time
import ccdproc as ccdp
from astropy.nddata import CCDData
import numpy as np
import glob
import itertools
from astropy.table import Table
from astropy import table
import Logs
from astropy.convolution import convolve, Box1DKernel
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Photometry<jupyter_code>science=ccdp.ImageFileCollection('Final_Science/median')

# sciencelist=glob.glob('Corrected_Science/r*fit')
#ascii.write(sc,'sc_summary.csv',format='csv',overwrite=True)
#found=Table(names=('fname','x','y','sh','ro'),dtype=('str','float32','float32','float32','float32'))
trackerf=[]
trackera=[]
start=time.time()
for imsd,imsn in science.data(return_fname=True):
    print('\nassessing',imsn)
    try:
        x,y,flux,sh,ro=sp.find(imsd,hmin=2000,fwhm=20,sharplim=([-5,5]),roundlim=([-2,2]))
        if len(x) == 2:
            for i in range(len(x)):
                trackerf.append([imsn,x[i],y[i],sh[i],ro[i]])
            flux,eflux,sky,skerr=sp.aper(imsd,x,y,phpadu=2.9,apr=[25],skyrad=[40,50],flux=True)
            trackera.append([imsn,flux[0][0],flux[1][0],sky[0],sky[1],eflux[0][0],eflux[1][0]])
            print(imsn,'flux calculated')
        elif len(x) != 2:
            print('skipping',imsn,'since it did not return exactly 2 star coordinates')

    except Exception as e:
        print(imsn,'did not meet sharpness or roundness criteria')
        print(e)
    


tf=np.reshape(trackerf,(-1,5))
ta=np.reshape(trackera,(-1,7))
print(time.time()-start)
foundf=Table(tf,names=('fname','x','y','sh','ro'),dtype=('str','float64','float64','float64','float64'))
fluxt=Table(ta,names=('fname','fluxcalib','fluxtarget','skycalib','skytarget','fluxerrcalib','fluxerrtarget')
            ,dtype=('str','float64','float64','float64','float64','float64','float64'))
ascii.write(foundf,'stars.csv',format='csv',overwrite=True)
ascii.write(fluxt,'fluxes.csv',format='csv',overwrite=True)<jupyter_output>assessing r1382286.fit
x, y in pixels, flux and sky in ADU
=======================================
aperture radius is 25 pixels
=======================================
x		 y		 flux +- fluxerr 		sky +- skyerr
656.7437400313955 	 341.44622871574876 	 3741552.067369872 +- 1251.4053294926237 	 3.476467247648724 +- 10.836094159887873
1049.7901565120706 	 1042.2002811852535 	 2582334.9420958715 +- 1051.3140038169959 	 3.893775994880613 +- 9.562555493698373
r1382286.fit flux calculated

assessing r1382287.fit
x, y in pixels, flux and sky in ADU
=======================================
aperture radius is 25 pixels
=======================================
x		 y		 flux +- fluxerr 		sky +- skyerr
657.9750340576511 	 340.03389926464155 	 3726494.5780473165 +- 1229.7337983477205 	 4.2569924560130765 +- 9.835697679652576
1051.049892789946 	 1040.8051862806687 	 2577958.2234661393 +- 1039.3354342245636 	 3.9827765554136256 +- 9.02352180627511
r1382287.fit flux calculated

assessing r1382288.fit
x, y i[...]<jupyter_text>Get logs<jupyter_code>log1=Logs.parse_logfile('HD115709/log_files/run_log_20180428.int')
log2=Logs.parse_logfile('HD115709/log_files/run_log_20180430.int')

log1t=Table(list(log1['Observations'].values()),names=tuple(log1['Observations'].keys()))

log2t=Table(list(log2['Observations'].values()),names=tuple(log2['Observations'].keys()))


# logc=table.vstack([log1t,log2t])<jupyter_output><empty_output><jupyter_text>Data manipulation<jupyter_code># fluxt=ascii.read('fluxes.csv')


c=[]
for i, val in enumerate(fluxt['fname']):
    c.append(int(val[1:8]))

fluxt['Run']=c

final1=table.join(fluxt,log1t,keys='Run')
final2=table.join(fluxt,log2t,keys='Run')


final1['truefluxcalib']=final1['fluxcalib']/final1['Exptime']
final2['truefluxcalib']=final2['fluxcalib']/final2['Exptime']

final1['truefluxtarget']=final1['fluxtarget']/final1['Exptime']
final2['truefluxtarget']=final2['fluxtarget']/final2['Exptime']

final1['diff']=final1['truefluxcalib']-final1['truefluxtarget']
final2['diff']=final2['truefluxcalib']-final2['truefluxtarget']


final1['relflux']=final1['diff']/np.nanmedian(final1['diff'])
final2['relflux']=final2['diff']/np.nanmedian(final2['diff'])<jupyter_output><empty_output><jupyter_text>Convolve<jupyter_code>final1['smadiff']=convolve(list(final1['relflux']),kernel=Box1DKernel(10),boundary='extend')
final2['smadiff']=convolve(list(final2['relflux']),kernel=Box1DKernel(10),boundary='extend')


ascii.write(final1,'final1.csv',overwrite=True,format='csv')
ascii.write(final2,'final2.csv',overwrite=True,format='csv')<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>fig, axs=plt.subplots(1,2,figsize=(40,10))
axs[0].scatter(final1['MJD']+2400000.5,final1['truefluxcalib'])
axs[0].ticklabel_format(axis='y',style='sci',scilimits=(0,0))
axs[0].set_ylim(1.7e6,1.9e6)
#axs[0].ticklabel_format(axis='x',useOffset=True,useLocale=True)
axs[1].scatter(final2['MJD']+2400000.5,final2['truefluxcalib'])
axs[1].ticklabel_format(axis='x',useOffset=True,useLocale=True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20498723738464558, 'fraction_numerical': 0.12232475947378756, 'mean_word_length': 8.096428571428572, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '41776', 'license': 'MIT', 'n_tokens_mistral': 2388, 'n_tokens_neox': 1978, 'n_words': 214, 'path': '.ipynb_checkpoints/PLot interm run-Copy1-checkpoint.ipynb', 'repo_name': 'ambarqadeer/ALOPqadeer', 'size': '5093'}