-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: Include declination bin and energy bin selection in IRF checks #87
Open
rishibbdb
wants to merge
4
commits into
threeML:master
Choose a base branch
from
rishibbdb:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−24
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c83483
Beta V5: Tested and Working declination band scripts
rishibbdb 88e8976
Beta V5: Tested and Working declination band scripts
rishibbdb db291d3
Beta V5: Tested and Working declination band scripts
rishibbdb 2873f38
Fixed a minor bug
rishibbdb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import division | ||
from builtins import zip | ||
from past.utils import old_div | ||
from builtins import object | ||
import argparse as ap | ||
import numpy as np | ||
import scipy.stats as stats | ||
import warnings | ||
import os | ||
import sys | ||
import corner as cn | ||
import healpy as hp | ||
import scipy | ||
|
||
from pathlib import Path | ||
|
||
import uproot | ||
from threeML.io.logging import setup_logger | ||
from astropy.coordinates import SkyCoord | ||
|
||
with warnings.catch_warnings(): | ||
import astromodels | ||
|
||
log = setup_logger(__name__) | ||
log.propagate = False | ||
|
||
def dec_index_search(response_file, dec_var, use_module): | ||
response = response_file | ||
with uproot.open(response) as response_file: | ||
dec_bins_lower_edge = response_file["DecBins/lowerEdge"].array().to_numpy() | ||
dec_bins_upper_edge = response_file["DecBins/upperEdge"].array().to_numpy() | ||
dec_bins_center = response_file["DecBins/simdec"].array().to_numpy() | ||
if use_module==True: | ||
dec_min = np.amin(dec_var) | ||
dec_max = np.amax(dec_var) | ||
else: | ||
dec_min = -37.5 | ||
dec_max = 77.5 | ||
|
||
log.info("Dec min= %.3f" %(dec_min)) | ||
log.info("Dec max= %.3f" %(dec_max)) | ||
#lower_edges = np.array([-37.5, -32.5, -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5], dtype=np.float) | ||
#upper_edges = np.array([-32.5, -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5], dtype=np.float) | ||
#centers = np.array([-35., -30., -25., -20., -15., -10., -5., 0., 5., 10., 15., 20., 25., 30., 35., 40., 45., 50., 55., 60., 65., 70., 75.], dtype=np.float) | ||
|
||
dec_bins_to_consider_idx = np.flatnonzero((dec_bins_upper_edge >= dec_min) & (dec_bins_lower_edge <= dec_max)) | ||
#dec_bins_to_consider_idx = np.flatnonzero((upper_edges >= dec_min) & (lower_edges <= dec_max)) | ||
#log.info("decbins before adding the extra bins : %s" %(dec_bins_to_consider_idx)) | ||
#log.info("Decbins to from response file before adding the extra bins : %s" %(dec_bins_to_consider_idx2)) | ||
|
||
dec_bins_to_consider_idx = np.append(dec_bins_to_consider_idx, [dec_bins_to_consider_idx[-1] + 1]) | ||
# Add one dec bin to cover the first part | ||
dec_bins_to_consider_idx = np.insert(dec_bins_to_consider_idx, 0, [dec_bins_to_consider_idx[0] - 1]) | ||
# Rescale bins to be remove dec bins less than 0 and greater than 22 | ||
dec_bins_in_use=dec_bins_to_consider_idx[(dec_bins_to_consider_idx >=0) & (23>dec_bins_to_consider_idx)] | ||
log.info("Declination bins to read response file: %s" %(dec_bins_in_use)) | ||
return dec_bins_in_use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
from hawc_hal import HAL, HealpixConeROI | ||
from threeML import * | ||
import astromodels | ||
import astropy.units as u | ||
import pytest | ||
from hawc_hal import HealpixConeROI | ||
from hawc_hal.maptree.map_tree import map_tree_factory | ||
from hawc_hal.region_of_interest import ( | ||
HealpixConeROI, | ||
HealpixMapROI | ||
) | ||
from hawc_hal.dec_band_select import dec_index_search | ||
test_data_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data") | ||
response=os.path.join(test_data_path, "geminga_response.root") | ||
ra_source, dec_source = 101.7, 16 | ||
data_r = 3 | ||
roi = HealpixConeROI(data_radius=data_r, | ||
model_radius=data_r + 10.0, | ||
ra=ra_source, dec=dec_source) | ||
|
||
dec_arange=[roi.ra_dec_center[1]-roi.model_radius.to(u.deg).value, roi.ra_dec_center[1]+roi.model_radius.to(u.deg).value] | ||
response_file=response | ||
#Use the declination band selection module | ||
dec_list = dec_index_search(response_file, dec_arange, use_module=True) | ||
print("Using declination list=", dec_list) | ||
|
||
#Using all declination bands | ||
dec_list = dec_index_search(response_file, dec_arange, use_module=False) | ||
print("Using declination list=", dec_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this take into account response files in .hd5 format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is a test with a response file in hd5 format and that's what is breaking the checks.