Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions docs/tutorials/light_curves/get_lctutorial_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
import os
import subprocess
from pathlib import Path
from cosipy.util import fetch_wasabi_file
from cosipy import BinnedData
from cosipy.pipeline.task.task import cosi_bindata
#
indir=str("./")
#

def get_data (wasabipath,outpath,unzip):
if not os.path.exists(outpath) and not os.path.exists(outpath[:-3]):
print ("Downloading")
print (wasabipath)
fetch_wasabi_file(wasabipath,output=outpath)
if unzip==True:
if outpath[-2:] == 'gz':
print("Gunzipping")
subprocess.run(["gunzip", outpath])
elif outpath[-3:] == 'zip':
print("Unzipping")
subprocess.run(["unzip", outpath])
return()


#
#Get Response from the develop folder in wasabi (new version)
#
filename='ResponseContinuum.o3.e100_10000.b10log.s10396905069491.m2284.filtered.nonsparse.binnedimaging.imagingresponse.h5'
wasabipath=os.path.join('COSI-SMEX/develop/Data/Responses',filename)
outpath=os.path.join(indir,filename)
get_data(wasabipath,outpath,False)

#
#Get Orientation files
#
filename="DC3_final_530km_3_month_with_slew_1sbins_GalacticEarth_SAA.ori"
wasabipath=os.path.join('COSI-SMEX/DC3/Data/Orientation',filename)
outpath=os.path.join(indir,filename)
get_data(wasabipath,outpath,False)



#
#Get Galactic background
#
filename='GalTotal_SA100_F98_3months_unbinned_data_filtered_with_SAAcut.fits.gz'
wasabipath=os.path.join('COSI-SMEX/DC3/Data/Backgrounds/Ge',filename)
outpath=os.path.join(indir,filename)
get_data(wasabipath,outpath,True)


#
#Get GRB source data
#
wasabirootpath="COSI-SMEX/DC3/Data/Sources"
#
#GRB
#
filename="GRB_bn081207680_3months_unbinned_data_filtered_with_SAAcut.fits.gz"
wasabipath=os.path.join(wasabirootpath,filename)
outpath=os.path.join(indir,filename)
get_data(wasabipath,outpath,True)
#
#Bin GRB data using the app cosi-bindata
#
args=['--config','prep_lctutorial_data.yaml', '--overwrite','--config_group','bindata_grb','--suffix','grbdc3']
cosi_bindata (argv=args)
#
#Bin and cut in time the bk data
#
args=['--config','prep_lctutorial_data.yaml', '--overwrite','--config_group','bindata_bk','--suffix','galbk']
cosi_bindata (argv=args)
#
#==================================
#
#Combine grb and galactic background, to have a dataset for the fit
#
grb=BinnedData("bin_grbdc3.yaml")
#
grb_bk=os.path.join (indir,"galbk_grbdc3")
#
grb.combine_unbinned_data(["GRB_bn081207680_3months_unbinned_data_filtered_with_SAAcut.fits","GalTotal_SA100_F98_3months_unbinned_data_filtered_with_SAAcut.fits"], output_name=grb_bk)
subprocess.run(["gunzip", "galbk_grbdc3.fits.gz"])
#
#Bin the grb+bk file:
#
args=['--config','prep_lctutorial_data.yaml', '--overwrite','--config_group','bindata_grbbk','--suffix','galbk_grbdc3']
cosi_bindata(argv=args)
37 changes: 37 additions & 0 deletions docs/tutorials/light_curves/prep_lctutorial_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
bindata_grb:
response:
class: ExpectationInterfaceTBD
args:
- ResponseContinuum.o3.e100_10000.b10log.s10396905069491.m2284.filtered.nonsparse.binnedimaging.imagingresponse.h5
unbinned_data_file: GRB_bn081207680_3months_unbinned_data_filtered_with_SAAcut.fits
sc_file: DC3_final_530km_3_month_with_slew_1sbins_GalacticEarth_SAA.ori
dt: 1
tmin: 1836496300.0
tmax: 1836496388.1
coo_sys: "local"


bindata_bk:
response:
class: ExpectationInterfaceTBD
args:
- ResponseContinuum.o3.e100_10000.b10log.s10396905069491.m2284.filtered.nonsparse.binnedimaging.imagingresponse.h5
unbinned_data_file: GalTotal_SA100_F98_3months_unbinned_data_filtered_with_SAAcut.fits
sc_file: DC3_final_530km_3_month_with_slew_1sbins_GalacticEarth_SAA.ori
dt: 1
tmin: 1836496200.0
tmax: 1836496488.1
coo_sys: "local"

bindata_grbbk:
response:
class: ExpectationInterfaceTBD
args:
- ResponseContinuum.o3.e100_10000.b10log.s10396905069491.m2284.filtered.nonsparse.binnedimaging.imagingresponse.h5
unbinned_data_file: galbk_grbdc3.fits
sc_file: DC3_final_530km_3_month_with_slew_1sbins_GalacticEarth_SAA.ori
dt: 1
tmin: 1836496300.0
tmax: 1836496388.1
coo_sys: "local"

Loading