Open israelmcmc opened 1 month ago
Code to fudged Earth occultation on the response (it only works for DC2 because the SC was always pointed at zenith)
from cosipy.response import FullDetectorResponse
import numpy as np
from pathlib import Path
import h5py as h5
data_dir = Path("/Users/imartin5/cosi/data_challenge/cosi-data-challenge-2/data") # Current directory by default. Modify if you can want a different path
response_path = data_dir/"SMEXv12.Continuum.HEALPixO3_10bins_log_flat.binnedimaging.imagingresponse.nonsparse_nside8.area.good_chunks_unzip.h5"
response_path_new = data_dir/"SMEXv12.Continuum.HEALPixO3_10bins_log_flat.binnedimaging.imagingresponse.nonsparse_nside8.area.good_chunks_unzip.earthocc.h5"
response = FullDetectorResponse.open(response_path)
nulambda_axis = response.axes['NuLambda']
theta,phi = nulambda_axis.pix2ang(range(nulambda_axis.npix))
with h5.File(response_path_new, 'r+') as response_file:
for pix in np.where(theta > np.deg2rad(113))[0]:
response_file['DRM']['CONTENTS'][pix] = 0
Make sure to copy (duplicate) the response file into response_path_new
@Yong2Sheng showed that issue with the Crab expected counts is that the response did not account for Earth occultations (but the simulation did).
We need to fully close the loop on this by fitting the Crab and making sure the resulting spectrum matches the input. Basically re-running the Crab Spectral fit tutorial with a new response.