From d325ff65e6a70e7383e8f2140e1144a2436050db Mon Sep 17 00:00:00 2001 From: Leonardo Baroncelli Date: Sat, 29 Apr 2023 16:25:23 +0200 Subject: [PATCH] Install AP package --- scripts/MANIFEST.in | 14 + scripts/ap/BBMainFunction.py | 4 +- scripts/ap/DisplayLC.py | 6 +- scripts/ap/Edp.py | 4 +- scripts/ap/SimAP.py | 5 +- scripts/ap/__init__.py | 0 scripts/ap/analyzeAP.py | 5 +- scripts/ap/analyzeLoadAP4.py | 7 +- scripts/ap/analyzeResults.py | 5 +- scripts/ap/display_lc.py | 1275 +++++++++++++++--------------- scripts/ap/drawLS.py | 5 +- scripts/ap/drawVM.py | 5 +- scripts/ap/normalizeAP.py | 7 +- scripts/ap/runanalysisLoadAP4.py | 5 +- scripts/ap/runcheckresults.py | 5 +- scripts/ap/runnormalizeAP.py | 5 +- scripts/pyproject.toml | 3 + scripts/setup.py | 32 + 18 files changed, 738 insertions(+), 654 deletions(-) create mode 100644 scripts/MANIFEST.in create mode 100644 scripts/ap/__init__.py create mode 100644 scripts/pyproject.toml create mode 100644 scripts/setup.py diff --git a/scripts/MANIFEST.in b/scripts/MANIFEST.in new file mode 100644 index 0000000..6cc4bdf --- /dev/null +++ b/scripts/MANIFEST.in @@ -0,0 +1,14 @@ +include README.md + +recursive-include * *.py +recursive-include * *.ipynb +recursive-include * *.ap +recursive-include * *.ph +recursive-include * *.lc +recursive-include * *.compare + +recursive-exclude * __pycache__ +recursive-exclude * *.egg-info +recursive-exclude * *.pyc +recursive-exclude * *.out +prune out* \ No newline at end of file diff --git a/scripts/ap/BBMainFunction.py b/scripts/ap/BBMainFunction.py index 758d393..c7d56ab 100644 --- a/scripts/ap/BBMainFunction.py +++ b/scripts/ap/BBMainFunction.py @@ -409,5 +409,5 @@ def RealTime(data,N_b,N_s): if stop == 'y' or stop == 'Y': break - -main() +if __name__=='__main__': + main() diff --git a/scripts/ap/DisplayLC.py b/scripts/ap/DisplayLC.py index c0b7e97..34b3325 100644 --- a/scripts/ap/DisplayLC.py +++ b/scripts/ap/DisplayLC.py @@ -1008,7 +1008,7 @@ def display(self, mode, scatter, fixed_flux, tstart_window_mjd, tstop_window_mjd plt.show() -if __name__ == "__main__": +def main(): mode = sys.argv[1] scatter = sys.argv[2] fixed_flux = float(sys.argv[3]) @@ -1023,3 +1023,7 @@ def display(self, mode, scatter, fixed_flux, tstart_window_mjd, tstop_window_mjd apdisplay = DisplayLC() apdisplay.display(mode, scatter, fixed_flux, tstart_window_mjd, tstop_window_mjd, file_one, file_two) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/ap/Edp.py b/scripts/ap/Edp.py index f438ea3..d61cefd 100644 --- a/scripts/ap/Edp.py +++ b/scripts/ap/Edp.py @@ -169,8 +169,8 @@ def detCorrectionSpectraFactorSimple(self, eMin, eMax, par1, verbose=0): -if __name__ == "__main__": +def main(): par1 = 1.7 par2 = 3403 #ec par3 = 0 @@ -183,3 +183,5 @@ def detCorrectionSpectraFactorSimple(self, eMin, eMax, par1, verbose=0): #detCorrectionSpectraFactorSimple(4, 12, par1) +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/ap/SimAP.py b/scripts/ap/SimAP.py index a13f417..5b25e42 100644 --- a/scripts/ap/SimAP.py +++ b/scripts/ap/SimAP.py @@ -438,10 +438,9 @@ def calculateAPLC(self, help=1, mode=0, windowfile='', apfile='', ranal= 1, gasv print('mean rate sim [cts / cm2 s]: %.3e +/- %.3e ' % (meanratesim/len(tstartA), math.sqrt(meanratesimerr) / expsum)) -if __name__ == "__main__": +def main(): #execute this class from command nline - apfile = sys.argv[1] windowfile = sys.argv[2] mode = sys.argv[3] @@ -453,3 +452,5 @@ def calculateAPLC(self, help=1, mode=0, windowfile='', apfile='', ranal= 1, gasv #test +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/ap/__init__.py b/scripts/ap/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/ap/analyzeAP.py b/scripts/ap/analyzeAP.py index 650eae8..b2701c8 100644 --- a/scripts/ap/analyzeAP.py +++ b/scripts/ap/analyzeAP.py @@ -2,6 +2,9 @@ #apfilename #ranal -if __name__ == '__main__': +def main(): ga = GammaAP() ga.fullAnalysis(sys.argv[1], ranal=sys.argv[2], gasvalue=0.00054, analyzevm=0, writevonmissesfiles=0, vonmissesthread=48, freqmin=0.5e-06, freqmax=5.0e-06, vmnumax=100, ngridfreq=10000, tgridfreq=10800, vmnoise=1, gal=0.7, iso=10, emin=100, emax=10000, gindex=2.1, evalULalgorithm=1) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/analyzeLoadAP4.py b/scripts/ap/analyzeLoadAP4.py index 6fdcccd..5c145db 100644 --- a/scripts/ap/analyzeLoadAP4.py +++ b/scripts/ap/analyzeLoadAP4.py @@ -1,8 +1,9 @@ from GammaAP import * #apfilename #ranal - -if __name__ == '__main__': +def main(): ga = GammaAP() ga.fullAnalysisLoadAP4(sys.argv[1], analyzevm=-1, vonmissesthread=48, freqmin=0.5e-06, freqmax=5.0e-06, vmnumax=100, ngridfreq=1000, tgridfreq=10800, vmnoise=1) - + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/analyzeResults.py b/scripts/ap/analyzeResults.py index d0f7414..f938edf 100644 --- a/scripts/ap/analyzeResults.py +++ b/scripts/ap/analyzeResults.py @@ -1,6 +1,7 @@ import os import sys -if __name__ == '__main__': + +def main(): filename = sys.argv[1] period = 8.4474 fractionofday = 2/24.0 @@ -27,3 +28,5 @@ # if time >= period/2 - fractionofday and time <= period/2 + fractionofday: # print(filename + " - " + line) +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/display_lc.py b/scripts/ap/display_lc.py index 55472a3..7fb9d85 100644 --- a/scripts/ap/display_lc.py +++ b/scripts/ap/display_lc.py @@ -242,770 +242,773 @@ def get_value_from_array(data_array): return {"x":x_array,"xerr":xerr_array,"tstart":tstart_array,"tstop":tstop_array,"flux":flux_array,"flux_err":flux_err_array,"sqrtts":sqrtts_array,'exp':exp_array,'exp_norm':exp_norm_array,"count":count_array,'count_err':count_err_array,"count_bkg":count_bkg_array,'count_bkg_err':count_bkg_err_array,'rate':rate_array,'rate_err':rate_err_array,'sensitivity':fixed_array,'flux_ul':flux_ul_array} +def main(): + ###### MAIN ######### -###### MAIN ######### + mode = sys.argv[1] + scatter = sys.argv[2] + fixed_flux = float(sys.argv[3]) + tstart_window_mjd = float(sys.argv[4]) + tstop_window_mjd = float(sys.argv[5]) -mode = sys.argv[1] -scatter = sys.argv[2] -fixed_flux = float(sys.argv[3]) -tstart_window_mjd = float(sys.argv[4]) -tstop_window_mjd = float(sys.argv[5]) + file_one = sys.argv[6] + if(mode=="2"): + file_two = sys.argv[7] -file_one = sys.argv[6] -if(mode=="2"): - file_two = sys.argv[7] + flux_notation = 100000000 + exp_notation = 1000000 -flux_notation = 100000000 -exp_notation = 1000000 + dict_one = extract_data(file_one,tstart_window_mjd,tstop_window_mjd) -dict_one = extract_data(file_one,tstart_window_mjd,tstop_window_mjd) + binsize = 15 -binsize = 15 + if(mode=="1"): -if(mode=="1"): + data_array_one = get_value_from_array(dict_one) - data_array_one = get_value_from_array(dict_one) + fig0 = plt.figure(constrained_layout=False) - fig0 = plt.figure(constrained_layout=False) + count = 0 + for detection in dict_one: + if(count==0): + count=1 + continue + + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') + else: + plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - count = 0 - for detection in dict_one: - if(count==0): - count=1 - continue - - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') - else: - plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - - if(dict_one[0]['sqrtts']<3): - plt.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') - else: - plt.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - - # if not (file_one.endswith(".lc")): - # # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) - # # - # f1_ax1.plot(data_array_one['x'], data_array_one['sensitivity'], color='r', marker='o', linewidth=1,linestyle='dashed', markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") - # - # x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - # x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - # y1 = data_array_one['sensitivity'] - # y2 = data_array_one['sensitivity'] - # f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) - - #plot fixed flux - if(fixed_flux!=-1): - plt.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g', linestyle='dashed' , linewidth=1.5,label="Fixed Flux") - - plt.xlabel('Time MJD') - plt.ylabel('Flux ph/cm2 s *10^-8') - plt.ylim(0) - #ax[0].xlabel("TT time *10^8") - #ax[0].ylabel("Flux ph/cm2 s *10^-8") - #ax[0].ylim(ymin=0) - plt.grid(True) - plt.legend(prop={'size':6}) - - - - - fig1 = plt.figure(constrained_layout=False) - - gs = GridSpec(6,1) - f1_ax1 = fig1.add_subplot(gs[:-3,0]) - f1_ax2 = fig1.add_subplot(gs[3,0]) - f1_ax3 = fig1.add_subplot(gs[4,0]) - f1_ax4 = fig1.add_subplot(gs[5,0]) - - #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label='flux 1', fmt='r.') - - count = 0 - for detection in dict_one: - if(count==0): - count=1 - continue - - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') + if(dict_one[0]['sqrtts']<3): + plt.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') else: - f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - - if(dict_one[0]['sqrtts']<3): - f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') - else: - f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') + plt.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - if not (file_one.endswith(".lc")): - # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) + # if not (file_one.endswith(".lc")): + # # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) + # # + # f1_ax1.plot(data_array_one['x'], data_array_one['sensitivity'], color='r', marker='o', linewidth=1,linestyle='dashed', markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") # - f1_ax1.plot(data_array_one['x'], data_array_one['sensitivity'], color='r', marker='o', linewidth=1,linestyle='dashed', markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") + # x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + # x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + # y1 = data_array_one['sensitivity'] + # y2 = data_array_one['sensitivity'] + # f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) - x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - y1 = data_array_one['sensitivity'] - y2 = data_array_one['sensitivity'] - f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) + #plot fixed flux + if(fixed_flux!=-1): + plt.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g', linestyle='dashed' , linewidth=1.5,label="Fixed Flux") - #plot fixed flux - if(fixed_flux!=-1): - f1_ax1.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g', linestyle='dashed' , linewidth=1.5,label="Fixed Flux") + plt.xlabel('Time MJD') + plt.ylabel('Flux ph/cm2 s *10^-8') + plt.ylim(0) + #ax[0].xlabel("TT time *10^8") + #ax[0].ylabel("Flux ph/cm2 s *10^-8") + #ax[0].ylim(ymin=0) + plt.grid(True) + plt.legend(prop={'size':6}) - #LC sqrts - f1_ax2.errorbar(data_array_one['x'], data_array_one['sqrtts'], xerr=data_array_one['xerr'],label=os.path.basename(file_one), fmt='r.') - f1_ax2.set(xlabel="Time MJD", ylabel="sqrt(TS)") - f1_ax2.grid(True) + fig1 = plt.figure(constrained_layout=False) - sqrtts_max = np.max(data_array_one['sqrtts']) + gs = GridSpec(6,1) + f1_ax1 = fig1.add_subplot(gs[:-3,0]) + f1_ax2 = fig1.add_subplot(gs[3,0]) + f1_ax3 = fig1.add_subplot(gs[4,0]) + f1_ax4 = fig1.add_subplot(gs[5,0]) - if(sqrtts_max<10): - f1_ax2.yaxis.set_major_locator(MultipleLocator(1)) - else: - f1_ax2.yaxis.set_major_locator(MultipleLocator(round(sqrtts_max/10))) + #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label='flux 1', fmt='r.') - #LC EXP - f1_ax3.errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], linestyle="-" , label=os.path.basename(file_one), fmt='r.') - f1_ax3.set(xlabel="Time MJD", ylabel="Exp 10^6") - f1_ax3.grid(True) + count = 0 + for detection in dict_one: + if(count==0): + count=1 + continue - #LC COUNT - f1_ax4.errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') - f1_ax4.set(xlabel="Time MJD", ylabel="Counts") - f1_ax4.grid(True) + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') + else: + f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - f1_ax4.scatter(data_array_one['x'], data_array_one['count_bkg'], marker="o",s=7,color="r" ) + if(dict_one[0]['sqrtts']<3): + f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') + else: + f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - y1 = data_array_one['count_bkg'] - y2 = data_array_one['count_bkg'] - f1_ax4.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) + if not (file_one.endswith(".lc")): + # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) + # + f1_ax1.plot(data_array_one['x'], data_array_one['sensitivity'], color='r', marker='o', linewidth=1,linestyle='dashed', markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") - max_one = np.max(data_array_one['count']) - if(max_one<10): - f1_ax4.yaxis.set_major_locator(MultipleLocator(1)) - else: - f1_ax4.yaxis.set_major_locator(MultipleLocator(round(max_one/10))) + x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + y1 = data_array_one['sensitivity'] + y2 = data_array_one['sensitivity'] + f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) + #plot fixed flux + if(fixed_flux!=-1): + f1_ax1.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g', linestyle='dashed' , linewidth=1.5,label="Fixed Flux") - f1_ax1.set(xlabel='Time MJD', ylabel='Flux ph/cm2 s *10^-8') - f1_ax1.set_ylim(ymin=0) - #ax[0].xlabel("TT time *10^8") - #ax[0].ylabel("Flux ph/cm2 s *10^-8") - #ax[0].ylim(ymin=0) - f1_ax1.grid(True) - f1_ax1.legend(prop={'size':6}) + #LC sqrts + f1_ax2.errorbar(data_array_one['x'], data_array_one['sqrtts'], xerr=data_array_one['xerr'],label=os.path.basename(file_one), fmt='r.') + f1_ax2.set(xlabel="Time MJD", ylabel="sqrt(TS)") + f1_ax2.grid(True) + sqrtts_max = np.max(data_array_one['sqrtts']) - fig1.subplots_adjust(left=0.06,bottom=0.06,right=0.97,top=0.97, wspace=0, hspace=0) - #fig1.subplots_adjust( wspace=0, hspace=1) + if(sqrtts_max<10): + f1_ax2.yaxis.set_major_locator(MultipleLocator(1)) + else: + f1_ax2.yaxis.set_major_locator(MultipleLocator(round(sqrtts_max/10))) - fig2, ax = plt.subplots(2,5) - fig2.suptitle('File 1 (red): '+os.path.basename(file_one)) - n, bins, patches = ax[0,0].hist(data_array_one['flux'], binsize, density=True, facecolor='r', alpha=0.6,label='flux 1') - ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux']), np.std(data_array_one['flux'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,1].hist(data_array_one['flux_err'], binsize, density=True, facecolor='r', alpha=0.6,label='flux err 1') - ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux_err']), np.std(data_array_one['flux_err'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,2].hist(data_array_one['sqrtts'], binsize, density=True, facecolor='r', alpha=0.6,label='sqrtts 1') - ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_one['sqrtts']), np.std(data_array_one['sqrtts'])), color="black", linestyle="--", alpha=0.9) - ax[0,0].set_title("Flux") - ax[0,0].set(xlabel='Flux ph/cm2 s *10^-8', ylabel='Det. Num.') - ax[0,1].set_title("Flux err") - ax[0,1].set(xlabel='Flux ph/cm2 s *10^-8') - ax[0,2].set_title("sqrt(Ts)") - ax[0,2].set(xlabel='sqrt(TS)') - #plt.legend([l1, l2, l3],["HHZ 1", "HHN", "HHE"]) + #LC EXP + f1_ax3.errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], linestyle="-" , label=os.path.basename(file_one), fmt='r.') + f1_ax3.set(xlabel="Time MJD", ylabel="Exp 10^6") + f1_ax3.grid(True) - ax[0,3].scatter(data_array_one['sqrtts'],data_array_one['flux'],color='red',s=10) - ax[0,3].set(xlabel='sqrts(TS)', ylabel='Flux ph/cm2 s *10^-8') - ax[0,3].set_title("sqrt(TS) vs Flux") + #LC COUNT + f1_ax4.errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') + f1_ax4.set(xlabel="Time MJD", ylabel="Counts") + f1_ax4.grid(True) - n, bins, patches = ax[1,3].hist(data_array_one['exp'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') - ax[1,3].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp']), np.std(data_array_one['exp'])), color="black", linestyle="--", alpha=0.9) - #ax[1,3].set_title("Exp") - ax[1,3].set(xlabel='Exp 10^6') + f1_ax4.scatter(data_array_one['x'], data_array_one['count_bkg'], marker="o",s=7,color="r" ) - if(file_one.endswith(".ap3")): - ax[0,4].scatter(data_array_one['exp_norm'],data_array_one['flux'],color='red',s=10) - ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') - ax[0,4].set_title("Exp norm vs Flux") + x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + y1 = data_array_one['count_bkg'] + y2 = data_array_one['count_bkg'] + f1_ax4.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) - n, bins, patches = ax[1,4].hist(data_array_one['exp_norm'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') - ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp_norm']), np.std(data_array_one['exp_norm'])), color="black", linestyle="--", alpha=0.9) + max_one = np.max(data_array_one['count']) + if(max_one<10): + f1_ax4.yaxis.set_major_locator(MultipleLocator(1)) + else: + f1_ax4.yaxis.set_major_locator(MultipleLocator(round(max_one/10))) - #ax[1,4].set_title("Exp Norm") - ax[1,4].set(xlabel='Exp Norm 10^6') - fig2.subplots_adjust(wspace=0.4, hspace=0.2) - fig3, ax = plt.subplots(3,3) - fig3.suptitle('File 1 (red): '+os.path.basename(file_one)) - bins = 40 + f1_ax1.set(xlabel='Time MJD', ylabel='Flux ph/cm2 s *10^-8') + f1_ax1.set_ylim(ymin=0) + #ax[0].xlabel("TT time *10^8") + #ax[0].ylabel("Flux ph/cm2 s *10^-8") + #ax[0].ylim(ymin=0) + f1_ax1.grid(True) + f1_ax1.legend(prop={'size':6}) - #LC COUNT - ax[0,0].errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,0].set(xlabel="Time MJD", ylabel="Counts") - ax[0,0].grid(True) - #LC COUNT BKG - ax[0,1].errorbar(data_array_one['x'], data_array_one['count_bkg'],xerr=data_array_one['xerr'], yerr=data_array_one['count_bkg_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,1].set(xlabel="Time MJD", ylabel="Counts Bkg") - ax[0,1].grid(True) + fig1.subplots_adjust(left=0.06,bottom=0.06,right=0.97,top=0.97, wspace=0, hspace=0) + #fig1.subplots_adjust( wspace=0, hspace=1) - #LC EXP - ax[1,0].errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') - ax[1,0].set(xlabel="Time MJD", ylabel="Exp 10^6") - ax[1,0].grid(True) + fig2, ax = plt.subplots(2,5) + fig2.suptitle('File 1 (red): '+os.path.basename(file_one)) + n, bins, patches = ax[0,0].hist(data_array_one['flux'], binsize, density=True, facecolor='r', alpha=0.6,label='flux 1') + ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux']), np.std(data_array_one['flux'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,1].hist(data_array_one['flux_err'], binsize, density=True, facecolor='r', alpha=0.6,label='flux err 1') + ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux_err']), np.std(data_array_one['flux_err'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,2].hist(data_array_one['sqrtts'], binsize, density=True, facecolor='r', alpha=0.6,label='sqrtts 1') + ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_one['sqrtts']), np.std(data_array_one['sqrtts'])), color="black", linestyle="--", alpha=0.9) + ax[0,0].set_title("Flux") + ax[0,0].set(xlabel='Flux ph/cm2 s *10^-8', ylabel='Det. Num.') + ax[0,1].set_title("Flux err") + ax[0,1].set(xlabel='Flux ph/cm2 s *10^-8') + ax[0,2].set_title("sqrt(Ts)") + ax[0,2].set(xlabel='sqrt(TS)') + #plt.legend([l1, l2, l3],["HHZ 1", "HHN", "HHE"]) - #LC EXP NORM - ax[1,1].errorbar(data_array_one['x'], data_array_one['exp_norm'],xerr=data_array_one['xerr'] , label=os.path.basename(file_one), fmt='r.') - ax[1,1].set(xlabel="Time MJD", ylabel="Exp Norm 10^6") - ax[1,1].grid(True) + ax[0,3].scatter(data_array_one['sqrtts'],data_array_one['flux'],color='red',s=10) + ax[0,3].set(xlabel='sqrts(TS)', ylabel='Flux ph/cm2 s *10^-8') + ax[0,3].set_title("sqrt(TS) vs Flux") + n, bins, patches = ax[1,3].hist(data_array_one['exp'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') + ax[1,3].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp']), np.std(data_array_one['exp'])), color="black", linestyle="--", alpha=0.9) + #ax[1,3].set_title("Exp") + ax[1,3].set(xlabel='Exp 10^6') - #LC RATE - ax[0,2].errorbar(data_array_one['x'], data_array_one['rate'],xerr=data_array_one['xerr'],yerr=data_array_one['rate_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,2].set(xlabel="Time MJD", ylabel="Rate") - ax[0,2].grid(True) + if(file_one.endswith(".ap3")): + ax[0,4].scatter(data_array_one['exp_norm'],data_array_one['flux'],color='red',s=10) + ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') + ax[0,4].set_title("Exp norm vs Flux") - #ISTOGRAMMA COUNT + n, bins, patches = ax[1,4].hist(data_array_one['exp_norm'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') + ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp_norm']), np.std(data_array_one['exp_norm'])), color="black", linestyle="--", alpha=0.9) - mean = np.mean(data_array_one['count']) - std = np.std(data_array_one['count']) - n, bins, patches = ax[2,2].hist(data_array_one['count'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[2,2].set_title("Count") - ax[2,2].set(xlabel='Count') - ax[2,2].legend() + #ax[1,4].set_title("Exp Norm") + ax[1,4].set(xlabel='Exp Norm 10^6') + fig2.subplots_adjust(wspace=0.4, hspace=0.2) - #ISTOGRAMMA COUNT BKG - mean = np.mean(data_array_one['count_bkg']) - std = np.std(data_array_one['count_bkg']) - n, bins, patches = ax[1,2].hist(data_array_one['count_bkg'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[1,2].set_title("Count") - ax[1,2].set(xlabel='Count') - ax[1,2].legend() + fig3, ax = plt.subplots(3,3) + fig3.suptitle('File 1 (red): '+os.path.basename(file_one)) - fig3.subplots_adjust(wspace=0.4, hspace=0.3) + bins = 40 + #LC COUNT + ax[0,0].errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,0].set(xlabel="Time MJD", ylabel="Counts") + ax[0,0].grid(True) - #plt.tight_layout() + #LC COUNT BKG + ax[0,1].errorbar(data_array_one['x'], data_array_one['count_bkg'],xerr=data_array_one['xerr'], yerr=data_array_one['count_bkg_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,1].set(xlabel="Time MJD", ylabel="Counts Bkg") + ax[0,1].grid(True) - plt.show() + #LC EXP + ax[1,0].errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') + ax[1,0].set(xlabel="Time MJD", ylabel="Exp 10^6") + ax[1,0].grid(True) -if(mode=="2"): + #LC EXP NORM + ax[1,1].errorbar(data_array_one['x'], data_array_one['exp_norm'],xerr=data_array_one['xerr'] , label=os.path.basename(file_one), fmt='r.') + ax[1,1].set(xlabel="Time MJD", ylabel="Exp Norm 10^6") + ax[1,1].grid(True) - dict_two = extract_data(file_two,tstart_window_mjd,tstop_window_mjd) - print(len(dict_one)) - print(len(dict_two)) + #LC RATE + ax[0,2].errorbar(data_array_one['x'], data_array_one['rate'],xerr=data_array_one['xerr'],yerr=data_array_one['rate_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,2].set(xlabel="Time MJD", ylabel="Rate") + ax[0,2].grid(True) - if(scatter=="1"): - plot_scatter = True - else: - plot_scatter = False + #ISTOGRAMMA COUNT + mean = np.mean(data_array_one['count']) + std = np.std(data_array_one['count']) + n, bins, patches = ax[2,2].hist(data_array_one['count'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[2,2].set_title("Count") + ax[2,2].set(xlabel='Count') + ax[2,2].legend() - if(plot_scatter is True): - dict_two_clean = [] - dict_one_clean = [] - for detection_two in dict_two: - tstart_two = detection_two['tstart'] + #ISTOGRAMMA COUNT BKG + mean = np.mean(data_array_one['count_bkg']) + std = np.std(data_array_one['count_bkg']) + n, bins, patches = ax[1,2].hist(data_array_one['count_bkg'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[1,2].set_title("Count") + ax[1,2].set(xlabel='Count') + ax[1,2].legend() - for detection_one in dict_one: - tstart_one = detection_one['tstart'] + fig3.subplots_adjust(wspace=0.4, hspace=0.3) - if(tstart_one == tstart_two): - dict_two_clean.append(detection_two) - dict_one_clean.append(detection_one) + #plt.tight_layout() - print(len(dict_one_clean)) - print(len(dict_two_clean)) + plt.show() + if(mode=="2"): - data_array_one = get_value_from_array(dict_one_clean) - data_array_two = get_value_from_array(dict_two_clean) - else: - data_array_one = get_value_from_array(dict_one) - data_array_two = get_value_from_array(dict_two) + dict_two = extract_data(file_two,tstart_window_mjd,tstop_window_mjd) + print(len(dict_one)) + print(len(dict_two)) - #plt.figure(1) - #fig, ax = plt.subplots(ncols=1, nrows=4, constrained_layout=True) - fig0 = plt.figure(constrained_layout=False) + if(scatter=="1"): + plot_scatter = True + else: + plot_scatter = False - count = 0 - for detection in dict_one: - if(count==0): - count=1 - continue - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') - else: - plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - - count = 0 - for detection in dict_two: - if(count==0): - count=1 - continue - - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='bv') - else: - plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='b.') - - - #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label=os.path.basename(file_one), fmt='r.') - - if(dict_one[0]['sqrtts']<3): - plt.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') - else: - plt.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - - - if(dict_two[0]['sqrtts']<3): - plt.errorbar(dict_two[0]['x'], dict_two[0]['flux_ul'],xerr=dict_two[0]['x_err'], yerr=0, label=os.path.basename(file_two), fmt='bv') - else: - plt.errorbar(dict_two[0]['x'], dict_two[0]['flux'],xerr=dict_two[0]['x_err'], yerr=dict_two[0]['flux_err'], label=os.path.basename(file_two), fmt='b.') - - # if not (file_one.endswith(".lc")): - # # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) - # # - # - # #,xerr=dict_one[0]['x_err'], yerr=0 - # plt.errorbar(data_array_one['x'], data_array_one['sensitivity'] , color='r', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") - # x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - # x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - # y1 = data_array_one['sensitivity'] - # y2 = data_array_one['sensitivity'] - # plt.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) - # - # if not (file_two.endswith(".lc")): - # # f1_ax1.scatter(data_array_two['x'], data_array_two['sensitivity'], marker="o",s=7,color="b" ) - # # - # - # #,xerr=dict_two[0]['x_err'], yerr=0, - # plt.errorbar(data_array_two['x'], data_array_two['sensitivity'],color='b', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_two)+" (4 sigma sensitivity)") - # x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) - # x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) - # y1 = data_array_two['sensitivity'] - # y2 = data_array_two['sensitivity'] - # plt.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed", linewidth=1) - # #plot fixed flux - - if(fixed_flux!=-1): - plt.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g',linestyle='dashed', linewidth=1.5,label="Fixed Flux") - - - plt.xlabel('Time MJD') - plt.ylabel('Flux ph/cm2 s *10^-8') - plt.ylim(0) - #ax[0].xlabel("TT time *10^8") - #ax[0].ylabel("Flux ph/cm2 s *10^-8") - #ax[0].ylim(ymin=0) - plt.grid(True) - plt.legend(prop={'size':6}) - - - fig1 = plt.figure(constrained_layout=False) - - gs = GridSpec(6,1) - f1_ax1 = fig1.add_subplot(gs[:-3,0]) - #f3_ax1.set_title('gs[0, :]') - f1_ax2 = fig1.add_subplot(gs[3,0]) - #f3_ax2.set_title('gs[0, :]') - f1_ax3 = fig1.add_subplot(gs[4,0]) - #f3_ax3.set_title('gs[0, :]') - f1_ax4 = fig1.add_subplot(gs[5,0]) - #f3_ax4.set_title('gs[0, :]') - - count = 0 - for detection in dict_one: - if(count==0): - count=1 - continue - - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') - else: - f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - - count = 0 - for detection in dict_two: - if(count==0): - count=1 - continue - - if(detection['sqrtts']<3): - #add arrow - #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) - f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='bv') + if(plot_scatter is True): + dict_two_clean = [] + dict_one_clean = [] + + + for detection_two in dict_two: + tstart_two = detection_two['tstart'] + + for detection_one in dict_one: + tstart_one = detection_one['tstart'] + + if(tstart_one == tstart_two): + dict_two_clean.append(detection_two) + dict_one_clean.append(detection_one) + + + print(len(dict_one_clean)) + print(len(dict_two_clean)) + + + data_array_one = get_value_from_array(dict_one_clean) + data_array_two = get_value_from_array(dict_two_clean) else: - f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='b.') + data_array_one = get_value_from_array(dict_one) + data_array_two = get_value_from_array(dict_two) - #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label=os.path.basename(file_one), fmt='r.') + #plt.figure(1) + #fig, ax = plt.subplots(ncols=1, nrows=4, constrained_layout=True) + fig0 = plt.figure(constrained_layout=False) - if(dict_one[0]['sqrtts']<3): - f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') - else: - f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') + count = 0 + for detection in dict_one: + if(count==0): + count=1 + continue + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') + else: + plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') - if(dict_two[0]['sqrtts']<3): - f1_ax1.errorbar(dict_two[0]['x'], dict_two[0]['flux_ul'],xerr=dict_two[0]['x_err'], yerr=0, label=os.path.basename(file_two), fmt='bv') - else: - f1_ax1.errorbar(dict_two[0]['x'], dict_two[0]['flux'],xerr=dict_two[0]['x_err'], yerr=dict_two[0]['flux_err'], label=os.path.basename(file_two), fmt='b.') + count = 0 + for detection in dict_two: + if(count==0): + count=1 + continue - if not (file_one.endswith(".lc")): - # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) - # + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + plt.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='bv') + else: + plt.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='b.') - #,xerr=dict_one[0]['x_err'], yerr=0 - f1_ax1.errorbar(data_array_one['x'], data_array_one['sensitivity'] , color='r', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") - x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - y1 = data_array_one['sensitivity'] - y2 = data_array_one['sensitivity'] - f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) - if not (file_two.endswith(".lc")): - # f1_ax1.scatter(data_array_two['x'], data_array_two['sensitivity'], marker="o",s=7,color="b" ) - # + #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label=os.path.basename(file_one), fmt='r.') - #,xerr=dict_two[0]['x_err'], yerr=0, - f1_ax1.errorbar(data_array_two['x'], data_array_two['sensitivity'],color='b', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_two)+" (4 sigma sensitivity)") - x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) - x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) - y1 = data_array_two['sensitivity'] - y2 = data_array_two['sensitivity'] - f1_ax1.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed", linewidth=1) - #plot fixed flux + if(dict_one[0]['sqrtts']<3): + plt.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') + else: + plt.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - if(fixed_flux!=-1): - f1_ax1.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g',linestyle='dashed', linewidth=1.5,label="Fixed Flux") - - - f1_ax1.set(xlabel='Time MJD', ylabel='Flux ph/cm2 s *10^-8') - f1_ax1.set_ylim(ymin=0) - #ax[0].xlabel("TT time *10^8") - #ax[0].ylabel("Flux ph/cm2 s *10^-8") - #ax[0].ylim(ymin=0) - f1_ax1.grid(True) - f1_ax1.legend(prop={'size':6}) - - #LC TS - f1_ax2.errorbar(data_array_one['x'], data_array_one['sqrtts'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') - f1_ax2.errorbar(data_array_two['x'], data_array_two['sqrtts'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') - f1_ax2.set(xlabel="Time MJD", ylabel="sqrt(TS)") - f1_ax2.grid(True) - min_one = np.amin(data_array_one['sqrtts']) - min_two = np.amin(data_array_two['sqrtts']) + if(dict_two[0]['sqrtts']<3): + plt.errorbar(dict_two[0]['x'], dict_two[0]['flux_ul'],xerr=dict_two[0]['x_err'], yerr=0, label=os.path.basename(file_two), fmt='bv') + else: + plt.errorbar(dict_two[0]['x'], dict_two[0]['flux'],xerr=dict_two[0]['x_err'], yerr=dict_two[0]['flux_err'], label=os.path.basename(file_two), fmt='b.') + + # if not (file_one.endswith(".lc")): + # # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) + # # + # + # #,xerr=dict_one[0]['x_err'], yerr=0 + # plt.errorbar(data_array_one['x'], data_array_one['sensitivity'] , color='r', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") + # x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + # x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + # y1 = data_array_one['sensitivity'] + # y2 = data_array_one['sensitivity'] + # plt.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) + # + # if not (file_two.endswith(".lc")): + # # f1_ax1.scatter(data_array_two['x'], data_array_two['sensitivity'], marker="o",s=7,color="b" ) + # # + # + # #,xerr=dict_two[0]['x_err'], yerr=0, + # plt.errorbar(data_array_two['x'], data_array_two['sensitivity'],color='b', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_two)+" (4 sigma sensitivity)") + # x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) + # x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) + # y1 = data_array_two['sensitivity'] + # y2 = data_array_two['sensitivity'] + # plt.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed", linewidth=1) + # #plot fixed flux + + if(fixed_flux!=-1): + plt.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g',linestyle='dashed', linewidth=1.5,label="Fixed Flux") + + + plt.xlabel('Time MJD') + plt.ylabel('Flux ph/cm2 s *10^-8') + plt.ylim(0) + #ax[0].xlabel("TT time *10^8") + #ax[0].ylabel("Flux ph/cm2 s *10^-8") + #ax[0].ylim(ymin=0) + plt.grid(True) + plt.legend(prop={'size':6}) + + + fig1 = plt.figure(constrained_layout=False) + + gs = GridSpec(6,1) + f1_ax1 = fig1.add_subplot(gs[:-3,0]) + #f3_ax1.set_title('gs[0, :]') + f1_ax2 = fig1.add_subplot(gs[3,0]) + #f3_ax2.set_title('gs[0, :]') + f1_ax3 = fig1.add_subplot(gs[4,0]) + #f3_ax3.set_title('gs[0, :]') + f1_ax4 = fig1.add_subplot(gs[5,0]) + #f3_ax4.set_title('gs[0, :]') + + count = 0 + for detection in dict_one: + if(count==0): + count=1 + continue + + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='rv') + else: + f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='r.') + + count = 0 + for detection in dict_two: + if(count==0): + count=1 + continue + + if(detection['sqrtts']<3): + #add arrow + #plt.arrow(detection['x'],detection['flux'],0,-70,width=1,head_width=10,head_starts_at_zero=True) + f1_ax1.errorbar(detection['x'], detection['flux_ul'],xerr=detection['x_err'], yerr=0, fmt='bv') + else: + f1_ax1.errorbar(detection['x'], detection['flux'],xerr=detection['x_err'], yerr=detection['flux_err'], fmt='b.') + + + #plt.errorbar(data_array_one['x'], data_array_one['flux'],xerr=data_array_one['xerr'], yerr=data_array_one['flux_err'], label=os.path.basename(file_one), fmt='r.') + + if(dict_one[0]['sqrtts']<3): + f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux_ul'],xerr=dict_one[0]['x_err'], yerr=0, label=os.path.basename(file_one), fmt='rv') + else: + f1_ax1.errorbar(dict_one[0]['x'], dict_one[0]['flux'],xerr=dict_one[0]['x_err'], yerr=dict_one[0]['flux_err'], label=os.path.basename(file_one), fmt='r.') - max_one = np.max(data_array_one['sqrtts']) - max_two = np.max(data_array_two['sqrtts']) - sqrtts_min = np.amin([min_one,min_two]) - sqrtts_max = np.amax([max_one,max_two]) + if(dict_two[0]['sqrtts']<3): + f1_ax1.errorbar(dict_two[0]['x'], dict_two[0]['flux_ul'],xerr=dict_two[0]['x_err'], yerr=0, label=os.path.basename(file_two), fmt='bv') + else: + f1_ax1.errorbar(dict_two[0]['x'], dict_two[0]['flux'],xerr=dict_two[0]['x_err'], yerr=dict_two[0]['flux_err'], label=os.path.basename(file_two), fmt='b.') + + if not (file_one.endswith(".lc")): + # f1_ax1.scatter(data_array_one['x'], data_array_one['sensitivity'], marker="o",s=7,color="r" ) + # + + #,xerr=dict_one[0]['x_err'], yerr=0 + f1_ax1.errorbar(data_array_one['x'], data_array_one['sensitivity'] , color='r', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_one)+" (4 sigma sensitivity)") + x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + y1 = data_array_one['sensitivity'] + y2 = data_array_one['sensitivity'] + f1_ax1.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed", linewidth=1) + + if not (file_two.endswith(".lc")): + # f1_ax1.scatter(data_array_two['x'], data_array_two['sensitivity'], marker="o",s=7,color="b" ) + # + + #,xerr=dict_two[0]['x_err'], yerr=0, + f1_ax1.errorbar(data_array_two['x'], data_array_two['sensitivity'],color='b', marker='o', linestyle='dashed', linewidth=1, markersize=3,label=os.path.basename(file_two)+" (4 sigma sensitivity)") + x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) + x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) + y1 = data_array_two['sensitivity'] + y2 = data_array_two['sensitivity'] + f1_ax1.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed", linewidth=1) + #plot fixed flux + + if(fixed_flux!=-1): + f1_ax1.plot([np.amin(data_array_one['x'])-np.amax(data_array_one['xerr']),np.amax(data_array_one['x'])+np.amax(data_array_one['xerr'])], [fixed_flux,fixed_flux], color='g',linestyle='dashed', linewidth=1.5,label="Fixed Flux") + + + f1_ax1.set(xlabel='Time MJD', ylabel='Flux ph/cm2 s *10^-8') + f1_ax1.set_ylim(ymin=0) + #ax[0].xlabel("TT time *10^8") + #ax[0].ylabel("Flux ph/cm2 s *10^-8") + #ax[0].ylim(ymin=0) + f1_ax1.grid(True) + f1_ax1.legend(prop={'size':6}) + + #LC TS + f1_ax2.errorbar(data_array_one['x'], data_array_one['sqrtts'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') + f1_ax2.errorbar(data_array_two['x'], data_array_two['sqrtts'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') + f1_ax2.set(xlabel="Time MJD", ylabel="sqrt(TS)") + f1_ax2.grid(True) + + min_one = np.amin(data_array_one['sqrtts']) + min_two = np.amin(data_array_two['sqrtts']) + + max_one = np.max(data_array_one['sqrtts']) + max_two = np.max(data_array_two['sqrtts']) + + sqrtts_min = np.amin([min_one,min_two]) + sqrtts_max = np.amax([max_one,max_two]) + + #grid_array = np.arange(int(sqrtts_min),int(sqrtts_max),1) + + #for grid_line in grid_array.tolist(): + # f1_ax2.axhline(grid_line, color='gray', linewidth=0.5) + if(sqrtts_max<10): + f1_ax2.yaxis.set_major_locator(MultipleLocator(1)) + else: + f1_ax2.yaxis.set_major_locator(MultipleLocator(round(sqrtts_max/10))) + #f1_ax2.set_axisbelow(True) - #grid_array = np.arange(int(sqrtts_min),int(sqrtts_max),1) + #LC EXP + f1_ax3.errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], linestyle="-" , label=os.path.basename(file_one), fmt='r.') + f1_ax3.errorbar(data_array_two['x'], data_array_two['exp'],xerr=data_array_two['xerr'], linestyle="-" , label=os.path.basename(file_two), fmt='b.') + f1_ax3.set(xlabel="Time MJD", ylabel="Exp 10^6") + f1_ax3.grid(True) - #for grid_line in grid_array.tolist(): - # f1_ax2.axhline(grid_line, color='gray', linewidth=0.5) - if(sqrtts_max<10): - f1_ax2.yaxis.set_major_locator(MultipleLocator(1)) - else: - f1_ax2.yaxis.set_major_locator(MultipleLocator(round(sqrtts_max/10))) - #f1_ax2.set_axisbelow(True) + #LC COUNT + f1_ax4.errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') + f1_ax4.errorbar(data_array_two['x'], data_array_two['count'],xerr=data_array_two['xerr'], yerr=data_array_two['count_err'], label=os.path.basename(file_two), fmt='b.') - #LC EXP - f1_ax3.errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], linestyle="-" , label=os.path.basename(file_one), fmt='r.') - f1_ax3.errorbar(data_array_two['x'], data_array_two['exp'],xerr=data_array_two['xerr'], linestyle="-" , label=os.path.basename(file_two), fmt='b.') - f1_ax3.set(xlabel="Time MJD", ylabel="Exp 10^6") - f1_ax3.grid(True) + f1_ax4.scatter(data_array_one['x'], data_array_one['count_bkg'], marker="o",s=7,color="r" ) + f1_ax4.scatter(data_array_two['x'], data_array_two['count_bkg'], marker="o",s=7,color="b" ) - #LC COUNT - f1_ax4.errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') - f1_ax4.errorbar(data_array_two['x'], data_array_two['count'],xerr=data_array_two['xerr'], yerr=data_array_two['count_err'], label=os.path.basename(file_two), fmt='b.') + x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) + x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) + y1 = data_array_one['count_bkg'] + y2 = data_array_one['count_bkg'] + f1_ax4.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed",linewidth=1,) - f1_ax4.scatter(data_array_one['x'], data_array_one['count_bkg'], marker="o",s=7,color="r" ) - f1_ax4.scatter(data_array_two['x'], data_array_two['count_bkg'], marker="o",s=7,color="b" ) + x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) + x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) + y1 = data_array_two['count_bkg'] + y2 = data_array_two['count_bkg'] + f1_ax4.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed",linewidth=1,) - x1 = np.subtract(data_array_one['x'],data_array_one['xerr']) - x2 = np.sum([data_array_one['x'],data_array_one['xerr']],axis=0) - y1 = data_array_one['count_bkg'] - y2 = data_array_one['count_bkg'] - f1_ax4.plot([x1,x2],[y1,y2],color = 'r',linestyle="dashed",linewidth=1,) + f1_ax4.set(xlabel="Time MJD", ylabel="Counts") + f1_ax4.grid(True) - x1 = np.subtract(data_array_two['x'],data_array_two['xerr']) - x2 = np.sum([data_array_two['x'],data_array_two['xerr']],axis=0) - y1 = data_array_two['count_bkg'] - y2 = data_array_two['count_bkg'] - f1_ax4.plot([x1,x2],[y1,y2],color = 'b',linestyle="dashed",linewidth=1,) + min_one = np.amin(data_array_one['count']) + min_two = np.amin(data_array_two['count']) - f1_ax4.set(xlabel="Time MJD", ylabel="Counts") - f1_ax4.grid(True) + max_one = np.max(data_array_one['count']) + max_two = np.max(data_array_two['count']) - min_one = np.amin(data_array_one['count']) - min_two = np.amin(data_array_two['count']) + cts_min = np.min([min_one,min_two]) + cts_max = np.max([max_one,max_two]) - max_one = np.max(data_array_one['count']) - max_two = np.max(data_array_two['count']) + #grid_array = np.arange(int(cts_min),int(cts_max),1) - cts_min = np.min([min_one,min_two]) - cts_max = np.max([max_one,max_two]) + #for grid_line in grid_array.tolist(): + # f1_ax4.axhline(grid_line, color='gray', linewidth=0.5) + if(cts_max<10): + f1_ax4.yaxis.set_major_locator(MultipleLocator(1)) + else: + f1_ax4.yaxis.set_major_locator(MultipleLocator(round(cts_max/10))) - #grid_array = np.arange(int(cts_min),int(cts_max),1) + #fig1.tight_layout() + fig1.subplots_adjust(left=0.06,bottom=0.06,right=0.97,top=0.97,wspace=0,hspace=0) - #for grid_line in grid_array.tolist(): - # f1_ax4.axhline(grid_line, color='gray', linewidth=0.5) - if(cts_max<10): - f1_ax4.yaxis.set_major_locator(MultipleLocator(1)) - else: - f1_ax4.yaxis.set_major_locator(MultipleLocator(round(cts_max/10))) - #fig1.tight_layout() - fig1.subplots_adjust(left=0.06,bottom=0.06,right=0.97,top=0.97,wspace=0,hspace=0) + fig2, ax = plt.subplots(2,5) + fig2.suptitle('File 1 (red): '+os.path.basename(file_one)+', File 2 (blue): '+os.path.basename(file_two)) + n, bins, patches = ax[0,0].hist(data_array_one['flux'], binsize, density=True, facecolor='r', alpha=0.6,label='flux 1') + ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux']), np.std(data_array_one['flux'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,0].hist(data_array_two['flux'], binsize, density=True, facecolor='b', alpha=0.6,label='flux 2') + ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_two['flux']), np.std(data_array_two['flux'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,1].hist(data_array_one['flux_err'], binsize, density=True, facecolor='r', alpha=0.6,label='flux err 1') + ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux_err']), np.std(data_array_one['flux_err'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,1].hist(data_array_two['flux_err'], binsize, density=True, facecolor='b', alpha=0.6,label='flux err 2') + ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_two['flux_err']), np.std(data_array_two['flux_err'])), color="black", linestyle="--", alpha=0.9) - fig2, ax = plt.subplots(2,5) - fig2.suptitle('File 1 (red): '+os.path.basename(file_one)+', File 2 (blue): '+os.path.basename(file_two)) - n, bins, patches = ax[0,0].hist(data_array_one['flux'], binsize, density=True, facecolor='r', alpha=0.6,label='flux 1') - ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux']), np.std(data_array_one['flux'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,0].hist(data_array_two['flux'], binsize, density=True, facecolor='b', alpha=0.6,label='flux 2') - ax[0,0].plot(bins, norm.pdf(bins, np.mean(data_array_two['flux']), np.std(data_array_two['flux'])), color="black", linestyle="--", alpha=0.9) - - n, bins, patches = ax[0,1].hist(data_array_one['flux_err'], binsize, density=True, facecolor='r', alpha=0.6,label='flux err 1') - ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_one['flux_err']), np.std(data_array_one['flux_err'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,1].hist(data_array_two['flux_err'], binsize, density=True, facecolor='b', alpha=0.6,label='flux err 2') - ax[0,1].plot(bins, norm.pdf(bins, np.mean(data_array_two['flux_err']), np.std(data_array_two['flux_err'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,2].hist(data_array_one['sqrtts'], binsize, density=True, facecolor='r', alpha=0.6,label='sqrt(TS) 1') + ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_one['sqrtts']), np.std(data_array_one['sqrtts'])), color="black", linestyle="--", alpha=0.9) + n, bins, patches = ax[0,2].hist(data_array_two['sqrtts'], binsize, density=True, facecolor='b', alpha=0.6,label='sqrt(TS) 2') + ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_two['sqrtts']), np.std(data_array_two['sqrtts'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,2].hist(data_array_one['sqrtts'], binsize, density=True, facecolor='r', alpha=0.6,label='sqrt(TS) 1') - ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_one['sqrtts']), np.std(data_array_one['sqrtts'])), color="black", linestyle="--", alpha=0.9) - n, bins, patches = ax[0,2].hist(data_array_two['sqrtts'], binsize, density=True, facecolor='b', alpha=0.6,label='sqrt(TS) 2') - ax[0,2].plot(bins, norm.pdf(bins, np.mean(data_array_two['sqrtts']), np.std(data_array_two['sqrtts'])), color="black", linestyle="--", alpha=0.9) + ax[0,0].set_title("Flux") + ax[0,0].set(xlabel='Flux ph/cm2 s *10^-8', ylabel='Det. Num.') + ax[0,1].set_title("Flux err") + ax[0,1].set(xlabel='Flux ph/cm2 s *10^-8') + ax[0,2].set_title("sqrt(TS)") + ax[0,2].set(xlabel='sqrt(TS)') - ax[0,0].set_title("Flux") - ax[0,0].set(xlabel='Flux ph/cm2 s *10^-8', ylabel='Det. Num.') - ax[0,1].set_title("Flux err") - ax[0,1].set(xlabel='Flux ph/cm2 s *10^-8') - ax[0,2].set_title("sqrt(TS)") - ax[0,2].set(xlabel='sqrt(TS)') + ##### CHANGE SCATTER PLOT ############################## - ##### CHANGE SCATTER PLOT ############################## + #change axes and label - #change axes and label + #possible axes: sqrtts,flux,flux_err,exp,exp_norm - #possible axes: sqrtts,flux,flux_err,exp,exp_norm + axes_x = "exp" + x_label = "exp" - axes_x = "exp" - x_label = "exp" + axes_y = "exp_norm" + y_label = "exp_norm" - axes_y = "exp_norm" - y_label = "exp_norm" + ax[0,3].scatter(data_array_one[axes_x],data_array_one[axes_y],color='red',s=10) + ax[0,3].scatter(data_array_two[axes_x],data_array_two[axes_y],color='blue',s=10) + ax[0,3].set(xlabel=x_label, ylabel=y_label) + ax[0,3].set_title(axes_x+" vs "+axes_y) - ax[0,3].scatter(data_array_one[axes_x],data_array_one[axes_y],color='red',s=10) - ax[0,3].scatter(data_array_two[axes_x],data_array_two[axes_y],color='blue',s=10) - ax[0,3].set(xlabel=x_label, ylabel=y_label) - ax[0,3].set_title(axes_x+" vs "+axes_y) + ########################################################### - ########################################################### + if(file_one.endswith(".ap3")): - if(file_one.endswith(".ap3")): + ax[0,4].scatter(data_array_one['exp_norm'],data_array_one['flux'],color='red',s=10) + ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') + ax[0,4].set_title("Exp norm vs Flux") - ax[0,4].scatter(data_array_one['exp_norm'],data_array_one['flux'],color='red',s=10) - ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') - ax[0,4].set_title("Exp norm vs Flux") - - n, bins, patches = ax[1,4].hist(data_array_one['exp_norm'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') - ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp_norm']), np.std(data_array_one['exp_norm'])), color="black", linestyle="--", alpha=0.9) - #ax[1,4].set_title("Exp Norm") - ax[1,4].set(xlabel='Exp Norm 10^6') + n, bins, patches = ax[1,4].hist(data_array_one['exp_norm'], binsize, density=True, facecolor='r', alpha=0.6,label='exp 1') + ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_one['exp_norm']), np.std(data_array_one['exp_norm'])), color="black", linestyle="--", alpha=0.9) + #ax[1,4].set_title("Exp Norm") + ax[1,4].set(xlabel='Exp Norm 10^6') - if(file_two.endswith(".ap3")): - - ax[0,4].scatter(data_array_two['exp_norm'],data_array_two['flux'],color='blue',s=10) - ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') - ax[0,4].set_title("Exp Norm vs Flux") + if(file_two.endswith(".ap3")): + + ax[0,4].scatter(data_array_two['exp_norm'],data_array_two['flux'],color='blue',s=10) + ax[0,4].set(xlabel='Exp Norm 10^6', ylabel='Flux ph/cm2 s *10^-8') + ax[0,4].set_title("Exp Norm vs Flux") - n, bins, patches = ax[1,4].hist(data_array_two['exp_norm'], binsize, density=True, facecolor='b', alpha=0.6,label='exp 1') - ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_two['exp_norm']), np.std(data_array_two['exp_norm'])), color="black", linestyle="--", alpha=0.9) - #ax[1,4].set_title("Exp Norm") - ax[1,4].set(xlabel='Exp Norm 10^6') + n, bins, patches = ax[1,4].hist(data_array_two['exp_norm'], binsize, density=True, facecolor='b', alpha=0.6,label='exp 1') + ax[1,4].plot(bins, norm.pdf(bins, np.mean(data_array_two['exp_norm']), np.std(data_array_two['exp_norm'])), color="black", linestyle="--", alpha=0.9) + #ax[1,4].set_title("Exp Norm") + ax[1,4].set(xlabel='Exp Norm 10^6') - mean = np.mean(data_array_one['exp']) - std = np.std(data_array_one['exp']) - n, bins, patches = ax[1,3].hist(data_array_one['exp'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[1,3].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + mean = np.mean(data_array_one['exp']) + std = np.std(data_array_one['exp']) + n, bins, patches = ax[1,3].hist(data_array_one['exp'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[1,3].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - mean = np.mean(data_array_two['exp']) - std = np.std(data_array_two['exp']) - n, bins, patches = ax[1,3].hist(data_array_two['exp'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[1,3].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[1,3].set_title("Exp") - ax[1,3].set(xlabel='Exp 10^6') - ax[1,3].legend() + mean = np.mean(data_array_two['exp']) + std = np.std(data_array_two['exp']) + n, bins, patches = ax[1,3].hist(data_array_two['exp'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[1,3].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[1,3].set_title("Exp") + ax[1,3].set(xlabel='Exp 10^6') + ax[1,3].legend() - if(plot_scatter): - ax[1,0].scatter(data_array_one['flux'], data_array_two['flux'],s=10) - min,max = find_min_max_axes(data_array_one['flux'],data_array_two['flux']) - ax[1,0].set_xlim([min,max]) - ax[1,0].set_ylim([min,max]) - ax[1,0].plot([min,max],[min,max],color='red') + if(plot_scatter): + ax[1,0].scatter(data_array_one['flux'], data_array_two['flux'],s=10) + min,max = find_min_max_axes(data_array_one['flux'],data_array_two['flux']) + ax[1,0].set_xlim([min,max]) + ax[1,0].set_ylim([min,max]) + ax[1,0].plot([min,max],[min,max],color='red') - if(plot_scatter): - ax[1,1].scatter(data_array_one['flux_err'],data_array_two['flux_err'],s=10) - min,max = find_min_max_axes(data_array_one['flux_err'],data_array_two['flux_err']) - ax[1,1].set_xlim([min,max]) - ax[1,1].set_ylim([min,max]) - ax[1,1].plot([min,max],[min,max],color='red') - - if(plot_scatter): - ax[1,2].scatter(data_array_one['sqrtts'],data_array_two['sqrtts'],s=10) - min,max = find_min_max_axes(data_array_one['sqrtts'],data_array_two['sqrtts']) - ax[1,2].set_xlim([min,max]) - ax[1,2].set_ylim([min,max]) - ax[1,2].plot([min,max],[min,max],color='red') - - #ax[1,0].set_title("Flux") - ax[1,0].set(xlabel='Flux 1', ylabel='Flux 2') - #ax[1,1].set_title("Flux err") - ax[1,1].set(xlabel='Flux err 1',ylabel="Flux err 2") - #ax[1,2].set_title("Ts") - ax[1,2].set(xlabel='sqrt(TS) 1',ylabel='sqrt(TS) 2') - - fig2.subplots_adjust(wspace=0.4, hspace=0.2) - - - - fig3, ax = plt.subplots(3,3) - fig3.suptitle('File 1 (red): '+os.path.basename(file_one)+', File 2 (blue): '+os.path.basename(file_two)) - - bins = 40 - - #LC COUNT - ax[0,0].errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,0].errorbar(data_array_two['x'], data_array_two['count'],xerr=data_array_two['xerr'], yerr=data_array_two['count_err'], label=os.path.basename(file_two), fmt='b.') - ax[0,0].set(xlabel="Time MJD", ylabel="Counts") - ax[0,0].grid(True) + if(plot_scatter): + ax[1,1].scatter(data_array_one['flux_err'],data_array_two['flux_err'],s=10) + min,max = find_min_max_axes(data_array_one['flux_err'],data_array_two['flux_err']) + ax[1,1].set_xlim([min,max]) + ax[1,1].set_ylim([min,max]) + ax[1,1].plot([min,max],[min,max],color='red') + + if(plot_scatter): + ax[1,2].scatter(data_array_one['sqrtts'],data_array_two['sqrtts'],s=10) + min,max = find_min_max_axes(data_array_one['sqrtts'],data_array_two['sqrtts']) + ax[1,2].set_xlim([min,max]) + ax[1,2].set_ylim([min,max]) + ax[1,2].plot([min,max],[min,max],color='red') + + #ax[1,0].set_title("Flux") + ax[1,0].set(xlabel='Flux 1', ylabel='Flux 2') + #ax[1,1].set_title("Flux err") + ax[1,1].set(xlabel='Flux err 1',ylabel="Flux err 2") + #ax[1,2].set_title("Ts") + ax[1,2].set(xlabel='sqrt(TS) 1',ylabel='sqrt(TS) 2') + + fig2.subplots_adjust(wspace=0.4, hspace=0.2) + + + + fig3, ax = plt.subplots(3,3) + fig3.suptitle('File 1 (red): '+os.path.basename(file_one)+', File 2 (blue): '+os.path.basename(file_two)) + + bins = 40 + + #LC COUNT + ax[0,0].errorbar(data_array_one['x'], data_array_one['count'],xerr=data_array_one['xerr'], yerr=data_array_one['count_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,0].errorbar(data_array_two['x'], data_array_two['count'],xerr=data_array_two['xerr'], yerr=data_array_two['count_err'], label=os.path.basename(file_two), fmt='b.') + ax[0,0].set(xlabel="Time MJD", ylabel="Counts") + ax[0,0].grid(True) - #LC COUNT BKG - ax[0,1].errorbar(data_array_one['x'], data_array_one['count_bkg'],xerr=data_array_one['xerr'], yerr=data_array_one['count_bkg_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,1].errorbar(data_array_two['x'], data_array_two['count_bkg'],xerr=data_array_two['xerr'], yerr=data_array_two['count_bkg_err'], label=os.path.basename(file_two), fmt='b.') - ax[0,1].set(xlabel="Time MJD", ylabel="Counts Bkg") - ax[0,1].grid(True) - - #LC EXP - ax[1,0].errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') - ax[1,0].errorbar(data_array_two['x'], data_array_two['exp'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') - ax[1,0].set(xlabel="Time MJD", ylabel="Exp 10^6") - ax[1,0].grid(True) - - #LC EXP NORM - ax[1,1].errorbar(data_array_one['x'], data_array_one['exp_norm'],xerr=data_array_one['xerr'] , label=os.path.basename(file_one), fmt='r.') - ax[1,1].errorbar(data_array_two['x'], data_array_two['exp_norm'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') - ax[1,1].set(xlabel="Time MJD", ylabel="Exp Norm 10^6") - ax[1,1].grid(True) - - #### SCATER PLOT COUNT - if(plot_scatter): - ax[2,0].scatter(data_array_one['count'],data_array_two['count'],s=10) - min,max = find_min_max_axes(data_array_one['count'],data_array_two['count']) - ax[2,0].set_xlim([min,max]) - ax[2,0].set_ylim([min,max]) - ax[2,0].plot([min,max],[min,max],color='red') - ax[2,0].set_title("Count vs Count") - - #### SCATER PLOT COUNT BKG - if(plot_scatter): - ax[2,1].scatter(data_array_one['count_bkg'],data_array_two['count_bkg'],s=10) - min,max = find_min_max_axes(data_array_one['count_bkg'],data_array_two['count_bkg']) - ax[2,1].set_xlim([min,max]) - ax[2,1].set_ylim([min,max]) - ax[2,1].plot([min,max],[min,max],color='red') - ax[2,1].set_title("Count bkg vs Count bkg") - - - - #LC RATE - ax[0,2].errorbar(data_array_one['x'], data_array_one['rate'],xerr=data_array_one['xerr'],yerr=data_array_one['rate_err'], label=os.path.basename(file_one), fmt='r.') - ax[0,2].errorbar(data_array_two['x'], data_array_two['rate'],xerr=data_array_two['xerr'],yerr=data_array_two['rate_err'] , label=os.path.basename(file_two), fmt='b.') - ax[0,2].set(xlabel="Time MJD", ylabel="Rate") - ax[0,2].grid(True) - - #ISTOGRAMMA COUNT - - mean = np.mean(data_array_one['count']) - std = np.std(data_array_one['count']) - n, bins, patches = ax[2,2].hist(data_array_one['count'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[2,2].set_title("Count") - ax[2,2].set(xlabel='Count') - ax[2,2].legend() - - - mean = np.mean(data_array_two['count']) - std = np.std(data_array_two['count']) - n, bins, patches = ax[2,2].hist(data_array_two['count'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[2,2].set_title("Count") - ax[2,2].set(xlabel='Count') - ax[2,2].legend() - - - #ISTOGRAMMA COUNT BKG - mean = np.mean(data_array_one['count_bkg']) - std = np.std(data_array_one['count_bkg']) - n, bins, patches = ax[1,2].hist(data_array_one['count_bkg'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[1,2].set_title("Count") - ax[1,2].set(xlabel='Count') - ax[1,2].legend() - - - mean = np.mean(data_array_two['count_bkg']) - std = np.std(data_array_two['count_bkg']) - n, bins, patches = ax[1,2].hist(data_array_two['count_bkg'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) - ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) - #ax[1,2].set_title("Count") - ax[1,2].set(xlabel='Count') - ax[1,2].legend() - - fig3.subplots_adjust(wspace=0.4, hspace=0.3) - - plt.show() + #LC COUNT BKG + ax[0,1].errorbar(data_array_one['x'], data_array_one['count_bkg'],xerr=data_array_one['xerr'], yerr=data_array_one['count_bkg_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,1].errorbar(data_array_two['x'], data_array_two['count_bkg'],xerr=data_array_two['xerr'], yerr=data_array_two['count_bkg_err'], label=os.path.basename(file_two), fmt='b.') + ax[0,1].set(xlabel="Time MJD", ylabel="Counts Bkg") + ax[0,1].grid(True) + + #LC EXP + ax[1,0].errorbar(data_array_one['x'], data_array_one['exp'],xerr=data_array_one['xerr'], label=os.path.basename(file_one), fmt='r.') + ax[1,0].errorbar(data_array_two['x'], data_array_two['exp'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') + ax[1,0].set(xlabel="Time MJD", ylabel="Exp 10^6") + ax[1,0].grid(True) + + #LC EXP NORM + ax[1,1].errorbar(data_array_one['x'], data_array_one['exp_norm'],xerr=data_array_one['xerr'] , label=os.path.basename(file_one), fmt='r.') + ax[1,1].errorbar(data_array_two['x'], data_array_two['exp_norm'],xerr=data_array_two['xerr'], label=os.path.basename(file_two), fmt='b.') + ax[1,1].set(xlabel="Time MJD", ylabel="Exp Norm 10^6") + ax[1,1].grid(True) + + #### SCATER PLOT COUNT + if(plot_scatter): + ax[2,0].scatter(data_array_one['count'],data_array_two['count'],s=10) + min,max = find_min_max_axes(data_array_one['count'],data_array_two['count']) + ax[2,0].set_xlim([min,max]) + ax[2,0].set_ylim([min,max]) + ax[2,0].plot([min,max],[min,max],color='red') + ax[2,0].set_title("Count vs Count") + + #### SCATER PLOT COUNT BKG + if(plot_scatter): + ax[2,1].scatter(data_array_one['count_bkg'],data_array_two['count_bkg'],s=10) + min,max = find_min_max_axes(data_array_one['count_bkg'],data_array_two['count_bkg']) + ax[2,1].set_xlim([min,max]) + ax[2,1].set_ylim([min,max]) + ax[2,1].plot([min,max],[min,max],color='red') + ax[2,1].set_title("Count bkg vs Count bkg") + + + + #LC RATE + ax[0,2].errorbar(data_array_one['x'], data_array_one['rate'],xerr=data_array_one['xerr'],yerr=data_array_one['rate_err'], label=os.path.basename(file_one), fmt='r.') + ax[0,2].errorbar(data_array_two['x'], data_array_two['rate'],xerr=data_array_two['xerr'],yerr=data_array_two['rate_err'] , label=os.path.basename(file_two), fmt='b.') + ax[0,2].set(xlabel="Time MJD", ylabel="Rate") + ax[0,2].grid(True) + + #ISTOGRAMMA COUNT + + mean = np.mean(data_array_one['count']) + std = np.std(data_array_one['count']) + n, bins, patches = ax[2,2].hist(data_array_one['count'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[2,2].set_title("Count") + ax[2,2].set(xlabel='Count') + ax[2,2].legend() + + + mean = np.mean(data_array_two['count']) + std = np.std(data_array_two['count']) + n, bins, patches = ax[2,2].hist(data_array_two['count'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[2,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[2,2].set_title("Count") + ax[2,2].set(xlabel='Count') + ax[2,2].legend() + + + #ISTOGRAMMA COUNT BKG + mean = np.mean(data_array_one['count_bkg']) + std = np.std(data_array_one['count_bkg']) + n, bins, patches = ax[1,2].hist(data_array_one['count_bkg'], binsize, density=True, facecolor='r', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[1,2].set_title("Count") + ax[1,2].set(xlabel='Count') + ax[1,2].legend() + + + mean = np.mean(data_array_two['count_bkg']) + std = np.std(data_array_two['count_bkg']) + n, bins, patches = ax[1,2].hist(data_array_two['count_bkg'], binsize, density=True, facecolor='b', alpha=0.6,label="mean: "+str(round(mean,2))+",std= "+str(round(std,2))) + ax[1,2].plot(bins, norm.pdf(bins, mean, std), color="black", linestyle="--", alpha=0.9) + #ax[1,2].set_title("Count") + ax[1,2].set(xlabel='Count') + ax[1,2].legend() + + fig3.subplots_adjust(wspace=0.4, hspace=0.3) + + plt.show() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/ap/drawLS.py b/scripts/ap/drawLS.py index 12a63a4..b707d3a 100644 --- a/scripts/ap/drawLS.py +++ b/scripts/ap/drawLS.py @@ -1,5 +1,8 @@ from GammaAP import * -if __name__ == '__main__': +def main(): ap = GammaAP() ap.evaluateLS(sys.argv[1], rescol=int(sys.argv[2]), plot=1) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/drawVM.py b/scripts/ap/drawVM.py index 5283e3d..7d95377 100644 --- a/scripts/ap/drawVM.py +++ b/scripts/ap/drawVM.py @@ -1,9 +1,12 @@ from GammaAP import * -if __name__ == '__main__': +def main(): ap = GammaAP() #last parameter #0 do not draw #1 draw on screen #2 draw on file ap.plotVonMisses(sys.argv[1], float(sys.argv[2]), 0, 2) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/normalizeAP.py b/scripts/ap/normalizeAP.py index 9f78202..7255b2d 100644 --- a/scripts/ap/normalizeAP.py +++ b/scripts/ap/normalizeAP.py @@ -3,7 +3,10 @@ #1 ap file #2 ranal -if __name__ == '__main__': +def main(): ap = GammaAP() - ap.normalizeAP(sys.argv[1], ranal=sys.argv[2], gasvalue=0.00054, gal=0.7, iso=10, emin=100, emax=10000, gindex=2.1, writevonmissesfiles=0, evalULalgorithm=1) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/runanalysisLoadAP4.py b/scripts/ap/runanalysisLoadAP4.py index b41159b..e82b4ec 100644 --- a/scripts/ap/runanalysisLoadAP4.py +++ b/scripts/ap/runanalysisLoadAP4.py @@ -1,10 +1,13 @@ import glob import os -if __name__ == '__main__': +def main(): regex="RES1_*.ap4" log_name_list = sorted(glob.glob(regex), key=os.path.getmtime) for filename in log_name_list: print(filename) ranal = filename.split("_")[2].split("R")[1] os.system("python analyzeLoadAP4.py " + filename) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/scripts/ap/runcheckresults.py b/scripts/ap/runcheckresults.py index 2fc59e2..333e7ea 100644 --- a/scripts/ap/runcheckresults.py +++ b/scripts/ap/runcheckresults.py @@ -1,9 +1,12 @@ import glob import os -if __name__ == '__main__': +def main(): regex="*.apres" log_name_list = sorted(glob.glob(regex), key=os.path.getmtime) for filename in log_name_list: print(filename) os.system("python analyzeResults.py " + filename) + +if __name__ == '__main__': + main() diff --git a/scripts/ap/runnormalizeAP.py b/scripts/ap/runnormalizeAP.py index 4817692..1641de8 100644 --- a/scripts/ap/runnormalizeAP.py +++ b/scripts/ap/runnormalizeAP.py @@ -1,10 +1,13 @@ import glob import os -if __name__ == '__main__': +def main(): regex="RES1_*.ap" log_name_list = sorted(glob.glob(regex), key=os.path.getmtime) for filename in log_name_list: print(filename) ranal = filename.split("_")[2].split("R")[1] os.system("python normalizeAP.py " + filename + " " + ranal) + +if __name__ == '__main__': + main() diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml new file mode 100644 index 0000000..fa7093a --- /dev/null +++ b/scripts/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/scripts/setup.py b/scripts/setup.py new file mode 100644 index 0000000..41741e7 --- /dev/null +++ b/scripts/setup.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +from setuptools import setup, find_packages + +entry_points = { + 'console_scripts': [ + 'analyzeAP = ap.analyzeAP:main', + 'analyzeLoadAP4 = ap.analyzeLoadAP4:main', + 'analyzeResults = ap.analyzeResults:main', + 'BBMainFunction = ap.BBMainFunction:main', + 'display_lc = ap.display_lc:main', + 'DisplayLC = ap.DisplayLC:main', + 'drawLS = ap.drawLS:main', + 'drawVM = ap.drawVM:main', + 'Edp = ap.Edp:main', + 'normalizeAP = ap.normalizeAP:main', + 'runanalysisLoadAP4 = ap.runanalysisLoadAP4:main', + 'runcheckresults = ap.runcheckresults:main', + 'runnormalizeAP = ap.runnormalizeAP:main', + 'SimAP = ap.SimAP:main' + ] +} + +setup( + name='ap', + author='Bulgarelli Andrea, Parmiggiani Nicolò, Valentina Fioretti', + author_email='andrea.bulgarelli@inaf.it, nicolo.parmiggiani@inaf.it, valentina.fioretti@inaf.it', + packages=find_packages(), + package_dir={ 'ap': 'ap' }, + entry_points=entry_points, + include_package_data=True +) \ No newline at end of file