-
Notifications
You must be signed in to change notification settings - Fork 274
Add possibility to produce DL3 with ctapipe #2727
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
Draft
mdebony
wants to merge
62
commits into
cta-observatory:main
Choose a base branch
from
mdebony:create_dl3
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
ac0d718
Add function to compute selection cuts
mdebony 17f0ed0
Make a component for event selection
mdebony dbce02b
Generalise behaviour
mdebony 7606d22
Update event loader in the view of using it for DL3 production
mdebony 5111d1f
change the output format of get simulation
mdebony 47fc14d
Fix cicular depedency
mdebony 1b26017
Update documentation of cuts
mdebony 1af4094
Update event processor to support gamaness event selection
mdebony 62df524
Update event loader for gamma event selection
mdebony 50c1af4
Update path criteria for input
mdebony aa64f93
Further update to prepare for DL3
mdebony 207cb7c
Skeleton for creating DL3
mdebony 2ea79cc
Basic DL3 structure
mdebony 7811ab1
Add option for optional DL3 columns
mdebony 861d2fa
Change option for flag
mdebony bf0cd86
Fix the option
mdebony 4b3765c
Add DL3 and IRF mode for preprocessor
mdebony 9ff2f21
Adapt preprocessor columns request
mdebony 912d871
Add option to skip missing optional column
mdebony 8336606
Allow for variation of the pointing for DL3
mdebony 636fbae
Move the derived columns function
mdebony 15e089f
Update make_derived_columns function for producing columns needed for…
mdebony df6a9c6
Update columns selection for DL3 production
mdebony 8dcfea5
Update table creation
mdebony 3fcfe22
Correct handling of optional columns for DL3
mdebony 0f795b4
Fix on optional columns
mdebony f3ba314
Format column for DL3 format
mdebony aedf6d8
Change x max for h max
mdebony e2a119b
Set base object for DL3 formating
mdebony 475a4bd
Update message
mdebony fa25592
Compute average uncertainty on core position
mdebony 9b0c9f9
Switch to fully use the object for DL3 format
mdebony 8e45123
Fix setter
mdebony 5c06050
Fix getter
mdebony e06054f
Add edisp getter and setter
mdebony 0a1d94b
Direct access for overwrite
mdebony 60f14aa
Add a base abstract class for generic DL3 format
mdebony d2d87ff
Add loading of location and gti
mdebony 663faf4
Fix
mdebony 0f712c6
Update headers of the DL3 file
mdebony a9ca20c
Update way of reading metainformation of the runs
mdebony e8e3d0a
Merge branch 'table_loader_schedule_block' into create_dl3
mdebony 09e9ce5
Merge branch 'table_loader_schedule_block' into create_dl3
mdebony 74cca7f
Add reading of additional observation metadata from dl2 file
mdebony 681ce64
Add new metadata to dl3 class
mdebony 1ce26f5
Add dead time fraction as metadata
mdebony 25f8f8b
Proper selection of mandatory only columns
mdebony 8e03bdb
Add metadata header to the DL3 file
mdebony df027d1
Add GTI table in the DL3 file
mdebony 3223155
Add pointing table and header to the DL3 file
mdebony e3c5245
Fix interpolation
mdebony ae70fd4
Add docstring to the dl3.py file
mdebony e3c5af9
Merge remote-tracking branch 'upstream/main' into create_dl3
mdebony 917240f
Fix errors encountered in automatic tests
mdebony 58ecd82
Multiple fix
mdebony 0fde645
Add docstring
mdebony 3de36aa
Multiple fix
mdebony 5017133
Merge branch 'main' into create_dl3
mdebony 7914648
Fix configurations
mdebony 46b5a9b
Add X max calculation
mdebony e099c12
Switch time scale to TAI
mdebony bd20df6
Add configurable reference time
mdebony 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 hidden or 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ usera | |
nd | ||
studi | ||
referenc | ||
livetime |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
from .quality_cuts import EventQualitySelection | ||
from .selection_cuts import EventSelection | ||
|
||
__all__ = ["EventSelection", "EventQualitySelection"] |
This file contains hidden or 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,58 @@ | ||
from astropy.table import Table | ||
|
||
from ...core import QualityQuery | ||
from ...core.traits import List, Tuple, Unicode | ||
|
||
|
||
class EventQualitySelection(QualityQuery): | ||
""" | ||
Event pre-selection quality criteria for IRF and DL3 computation with different defaults. | ||
""" | ||
|
||
quality_criteria = List( | ||
Tuple(Unicode(), Unicode()), | ||
default_value=[ | ||
( | ||
"multiplicity 4", | ||
"np.count_nonzero(HillasReconstructor_telescopes,axis=1) >= 4", | ||
), | ||
("valid classifier", "RandomForestClassifier_is_valid"), | ||
("valid geom reco", "HillasReconstructor_is_valid"), | ||
("valid energy reco", "RandomForestRegressor_is_valid"), | ||
], | ||
help=QualityQuery.quality_criteria.help, | ||
).tag(config=True) | ||
|
||
def calculate_selection(self, events: Table): | ||
""" | ||
Add the selection columns to the events, will only compute quality selection | ||
|
||
Parameters | ||
---------- | ||
events: Table | ||
The table containing the events on which selection need to be applied | ||
|
||
Returns | ||
------- | ||
Table | ||
events with selection columns added. | ||
""" | ||
return self.calculate_quality_selection(events) | ||
|
||
def calculate_quality_selection(self, events: Table): | ||
""" | ||
Add the selection columns to the events, will only compute quality selection | ||
|
||
Parameters | ||
---------- | ||
events: Table | ||
The table containing the events on which selection need to be applied | ||
|
||
Returns | ||
------- | ||
Table | ||
events with selection columns added. | ||
""" | ||
events["selected_quality"] = self.get_table_mask(events) | ||
events["selected"] = events["selected_quality"] | ||
return events |
This file contains hidden or 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,88 @@ | ||
import operator | ||
|
||
from astropy.table import Table | ||
from pyirf.cuts import evaluate_binned_cut | ||
|
||
from ...core.traits import Path | ||
from ..optimize.results import OptimizationResult | ||
from .quality_cuts import EventQualitySelection | ||
|
||
__all__ = ["EventSelection"] | ||
|
||
|
||
class EventSelection(EventQualitySelection): | ||
""" | ||
Event selection quality and gammaness criteria for IRF and DL3 | ||
""" | ||
|
||
cuts_file = Path( | ||
allow_none=False, | ||
directory_ok=False, | ||
exists=True, | ||
help="Path to the cuts file to apply to the observation.", | ||
).tag(config=True) | ||
|
||
def __init__(self, config=None, parent=None, **kwargs): | ||
super().__init__(config=config, parent=parent, **kwargs) | ||
self.cuts = OptimizationResult.read(self.cuts_file) | ||
|
||
def calculate_selection(self, events: Table, apply_spatial_selection: bool = False): | ||
""" | ||
Add the selection columns to the events | ||
|
||
Parameters | ||
---------- | ||
events: Table | ||
The table containing the events on which selection need to be applied | ||
apply_spatial_selection: bool | ||
True if the theta cuts should be applied | ||
|
||
Returns | ||
------- | ||
Table | ||
events with selection columns added. | ||
""" | ||
events = self.calculate_quality_selection(events) | ||
events = self.calculate_gamma_selection(events, apply_spatial_selection) | ||
events["selected"] = events["selected_quality"] & events["selected_gamma"] | ||
return events | ||
|
||
def calculate_gamma_selection( | ||
self, events: Table, apply_spatial_selection: bool = False | ||
) -> Table: | ||
""" | ||
Add the selection columns to the events, will compute only gamma criteria | ||
|
||
Parameters | ||
---------- | ||
events: Table | ||
The table containing the events on which selection need to be applied | ||
apply_spatial_selection: bool | ||
True if the theta cuts should be applied | ||
|
||
Returns | ||
------- | ||
Table | ||
events with selection columns added. | ||
""" | ||
|
||
events["selected_gh"] = evaluate_binned_cut( | ||
events["gh_score"], | ||
events["reco_energy"], | ||
self.cuts.gh_cuts, | ||
operator.ge, | ||
) | ||
|
||
if apply_spatial_selection: | ||
events["selected_theta"] = evaluate_binned_cut( | ||
events["theta"], | ||
events["reco_energy"], | ||
self.cuts.spatial_selection_table, | ||
operator.le, | ||
) | ||
events["selected_gamma"] = events["selected_theta"] & events["selected_gh"] | ||
else: | ||
events["selected_gamma"] = events["selected_gh"] | ||
|
||
events["selected"] = events["selected_gamma"] | ||
return events |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We can't really allow the user to select events in a totally arbitrary way when going from DL2→DL3, as the cuts applied in DL2 also define the IRFs, and if you change them, the IRFs are wrong. So I think the correct thing here is not to allow a general QualityQuery (though maybe we need a fixed one to drop missing or non-reconstructed events), but rather to load the cuts that are output from
ctapipe-optimize-event-selection
and apply them to the observed DL2 data.