-
Notifications
You must be signed in to change notification settings - Fork 267
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
Irf maker and cut optimiser #2473
base: main
Are you sure you want to change the base?
Changes from all commits
5c09d67
218c9de
582ae33
c18f811
bd5efb0
95c6fe1
11f3606
da86aa1
e961a21
c69337b
c33746c
d8b3795
beabdf0
4e53109
723fb26
fef7468
8ab46bd
f794b3c
b4b65a1
8edd9dc
723433b
e3349f3
b075e73
a4e36ea
2a89265
c02eeed
c338dc0
e78e206
d850b2e
1dd9738
de62326
19fddfa
393327e
7218b97
a96abf7
410de22
7e71775
8729e1f
cab78e9
21cd5d1
df5ba51
5f0e371
06e0e2d
c19a6be
cce0285
04f2054
9b53fe9
d7ae783
b1c840e
a65329d
95cedce
fd07242
fa17d36
23d1750
09a67d6
e3a64b9
31f428d
90b13d8
80248d4
b74d0c5
8c416f1
4601f59
df6e101
f55b0c6
51fca72
61fcab0
2d00341
e95b9b1
ad88ebe
e8997a9
e87d016
9126b6a
d66a91d
418d720
65a46ab
b29636d
8d984ca
927ff8c
727b721
c4ffdf8
282070d
061424b
1b9c767
13daa9a
1d1e194
90e833c
eef9165
fc9a888
9bd327a
8f5cbd8
892fb06
6eac846
448cb55
619e3fe
2be3d7d
96f1cdc
5ef1577
a28eca7
fd5f6e6
283a7d5
bd0d584
93eddef
a7d30fb
2d4c950
f809ca0
d8771e7
6a98c35
0175212
32c9fbe
576b887
8ad2181
85a0dbc
befa92b
58a8f13
adabf0d
594073f
0b796cd
bd24bcd
72c827e
1e0407c
8d8b9fb
70f4575
dd97404
10fd643
696f8f5
15df024
570da7b
2776af5
ff80aa1
0fa4477
555655d
0d7a114
e32144a
df47f71
99e21cb
9da6aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add a ``ctapipe-make-irf`` tool and a able to produce irfs given a cut-selection file and gamma, proton, and electron DL2 input files. | ||
|
||
Add a ``ctapipe-optimize-event-selection`` tool to produce cut-selection files. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ dependencies: | |
- pypandoc | ||
- pre-commit | ||
- psutil | ||
- pyirf | ||
- pytables | ||
- pytest | ||
- pytest-cov | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ dependencies = [ | |
"numba >=0.56", | ||
"numpy ~=1.16", | ||
"psutil", | ||
"pyirf >0.10.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should require an exact or at least a "compatible" version of pyirf. This should probably be |
||
"pyyaml >=5.1", | ||
"requests", | ||
"scikit-learn !=1.4.0", # 1.4.0 breaks with astropy tables, before and after works | ||
|
@@ -96,6 +97,8 @@ ctapipe-dump-instrument = "ctapipe.tools.dump_instrument:main" | |
ctapipe-display-dl1 = "ctapipe.tools.display_dl1:main" | ||
ctapipe-process = "ctapipe.tools.process:main" | ||
ctapipe-merge = "ctapipe.tools.merge:main" | ||
ctapipe-optimize-event-selection = "ctapipe.tools.optimize_event_selection:main" | ||
ctapipe-make-irf = "ctapipe.tools.make_irf:main" | ||
ctapipe-fileinfo = "ctapipe.tools.fileinfo:main" | ||
ctapipe-quickstart = "ctapipe.tools.quickstart:main" | ||
ctapipe-train-energy-regressor = "ctapipe.tools.train_energy_regressor:main" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
""" | ||
common pytest fixtures for tests in ctapipe | ||
""" | ||
|
||
import shutil | ||
from copy import deepcopy | ||
|
||
|
@@ -9,7 +10,7 @@ | |
import pytest | ||
import tables | ||
from astropy.coordinates import EarthLocation | ||
from astropy.table import Table | ||
from astropy.table import QTable, Table, vstack | ||
from pytest_astropy_header.display import PYTEST_HEADER_MODULES | ||
|
||
from ctapipe.core import run_tool | ||
|
@@ -684,3 +685,108 @@ def dl1_mon_pointing_file(dl1_file, dl1_tmp_path): | |
f.remove_node("/configuration/telescope/pointing", recursive=True) | ||
|
||
return path | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def gamma_diffuse_full_reco_file( | ||
gamma_train_clf, | ||
particle_classifier_path, | ||
model_tmp_path, | ||
): | ||
""" | ||
Energy reconstruction and geometric origin reconstruction have already been done. | ||
""" | ||
from ctapipe.tools.apply_models import ApplyModels | ||
|
||
output_path = model_tmp_path / "gamma_diffuse_full_reco.dl2.h5" | ||
run_tool( | ||
ApplyModels(), | ||
argv=[ | ||
f"--input={gamma_train_clf}", | ||
f"--output={output_path}", | ||
f"--reconstructor={particle_classifier_path}", | ||
"--no-dl1-parameters", | ||
"--StereoMeanCombiner.weights=konrad", | ||
], | ||
raises=True, | ||
) | ||
return output_path | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def proton_full_reco_file( | ||
proton_train_clf, | ||
particle_classifier_path, | ||
model_tmp_path, | ||
): | ||
""" | ||
Energy reconstruction and geometric origin reconstruction have already been done. | ||
""" | ||
from ctapipe.tools.apply_models import ApplyModels | ||
|
||
output_path = model_tmp_path / "proton_full_reco.dl2.h5" | ||
run_tool( | ||
ApplyModels(), | ||
argv=[ | ||
f"--input={proton_train_clf}", | ||
f"--output={output_path}", | ||
f"--reconstructor={particle_classifier_path}", | ||
"--no-dl1-parameters", | ||
"--StereoMeanCombiner.weights=konrad", | ||
], | ||
raises=True, | ||
) | ||
return output_path | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def irf_events_loader_test_config(): | ||
from traitlets.config import Config | ||
|
||
return Config( | ||
{ | ||
"EventPreProcessor": { | ||
"energy_reconstructor": "ExtraTreesRegressor", | ||
"geometry_reconstructor": "HillasReconstructor", | ||
"gammaness_classifier": "ExtraTreesClassifier", | ||
"quality_criteria": [ | ||
( | ||
"multiplicity 4", | ||
"np.count_nonzero(tels_with_trigger,axis=1) >= 4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is "trigger multiplicity". I think for the IRFs it makes more sense to look at "reconstruction multiplicity", i.e. Not really important for the test config though. |
||
), | ||
("valid classifier", "ExtraTreesClassifier_is_valid"), | ||
("valid geom reco", "HillasReconstructor_is_valid"), | ||
("valid energy reco", "ExtraTreesRegressor_is_valid"), | ||
], | ||
} | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def irf_events_table(): | ||
from ctapipe.irf import EventPreProcessor | ||
|
||
N1 = 1000 | ||
N2 = 100 | ||
N = N1 + N2 | ||
epp = EventPreProcessor() | ||
tab = epp.make_empty_table() | ||
# Add fake weight column | ||
tab.add_column((), name="weight") | ||
units = {c: tab[c].unit for c in tab.columns} | ||
|
||
empty = np.zeros((len(tab.columns), N)) * np.nan | ||
e_tab = QTable(data=empty.T, names=tab.colnames, units=units) | ||
# Setting values following pyirf test in pyirf/irf/tests/test_background.py | ||
e_tab["reco_energy"] = np.append(np.full(N1, 1), np.full(N2, 2)) * u.TeV | ||
e_tab["true_energy"] = np.append(np.full(N1, 0.9), np.full(N2, 2.1)) * u.TeV | ||
e_tab["reco_source_fov_offset"] = ( | ||
np.append(np.full(N1, 0.1), np.full(N2, 0.05)) * u.deg | ||
) | ||
e_tab["true_source_fov_offset"] = ( | ||
np.append(np.full(N1, 0.11), np.full(N2, 0.04)) * u.deg | ||
) | ||
|
||
ev = vstack([e_tab, tab], join_type="exact", metadata_conflicts="silent") | ||
return ev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Top level module for the irf functionality""" | ||
|
||
from .benchmarks import ( | ||
AngularResolution2dMaker, | ||
EnergyBiasResolution2dMaker, | ||
Sensitivity2dMaker, | ||
) | ||
from .binning import ( | ||
ResultValidRange, | ||
check_bins_in_range, | ||
make_bins_per_decade, | ||
) | ||
from .irfs import ( | ||
BackgroundRate2dMaker, | ||
EffectiveArea2dMaker, | ||
EnergyMigration2dMaker, | ||
Psf3dMaker, | ||
) | ||
from .optimize import ( | ||
GhPercentileCutCalculator, | ||
OptimizationResult, | ||
OptimizationResultStore, | ||
PercentileCuts, | ||
PointSourceSensitivityOptimizer, | ||
ThetaPercentileCutCalculator, | ||
) | ||
from .select import EventPreProcessor, EventsLoader | ||
from .spectra import SPECTRA, Spectra | ||
|
||
__all__ = [ | ||
"AngularResolution2dMaker", | ||
"EnergyBiasResolution2dMaker", | ||
"Sensitivity2dMaker", | ||
"Psf3dMaker", | ||
"BackgroundRate2dMaker", | ||
"EnergyMigration2dMaker", | ||
"EffectiveArea2dMaker", | ||
"ResultValidRange", | ||
"OptimizationResult", | ||
"OptimizationResultStore", | ||
"PointSourceSensitivityOptimizer", | ||
"PercentileCuts", | ||
"EventsLoader", | ||
"EventPreProcessor", | ||
"Spectra", | ||
"GhPercentileCutCalculator", | ||
"ThetaPercentileCutCalculator", | ||
"SPECTRA", | ||
"check_bins_in_range", | ||
"make_bins_per_decade", | ||
] |
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.
I think we should have a bit more extensive changelog here. What is currently supported? How is the intended use? It's a big step.