Skip to content

Commit 135b18c

Browse files
committed
merge with main
2 parents 21abc2d + 0b61f99 commit 135b18c

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

dl1_data_handler/reader.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ def __init__(
472472
"cam_coord_offset_x",
473473
"cam_coord_offset_y",
474474
"cam_coord_distance",
475+
"true_core_x",
476+
"true_core_y",
477+
"true_h_first_int",
478+
"true_x_max"
475479
]
476480
)
477481
elif self.process_type == ProcessType.Observation:
@@ -605,6 +609,8 @@ def _construct_mono_example_identifiers(self):
605609
events = self._transform_to_sky_spher_offsets(events)
606610
# Add the logarithm of the true energy in TeV
607611
events = self._transform_to_log_energy(events)
612+
# Add the impact radius
613+
events = self._transform_to_impact_radius(events)
608614
# Add the true shower primary class to the table based on the filename
609615
# is signal or background input file list
610616
true_shower_primary_class = (
@@ -779,6 +785,8 @@ def _multiplicity_cut_subarray(table, key_colnames):
779785
if self.process_type == ProcessType.Simulation:
780786
# Add the logarithm of the true energy in TeV
781787
events = self._transform_to_log_energy(events)
788+
# Add the impact radius
789+
events = self._transform_to_impact_radius(events)
782790
# Add the true shower primary class to the table based on the filename
783791
# is signal or background input file list
784792
true_shower_primary_class = (
@@ -894,6 +902,30 @@ def _transform_to_log_energy(self, table):
894902
table.add_column(np.log10(table["true_energy"]), name="log_true_energy")
895903
return table
896904

905+
def _transform_to_impact_radius(self, table) -> Table:
906+
"""
907+
Transform core coordinates to impact radius.
908+
909+
This method calculates the impact radius from the core coordinates
910+
in the provided table. The impact radius is the distance from the
911+
true core position to the subarray center.
912+
913+
Parameters:
914+
-----------
915+
table : astropy.table.Table
916+
A Table containing the true core coordinates.
917+
918+
Returns:
919+
--------
920+
table : astropy.table.Table
921+
A Table with the impact radius added as a new column.
922+
"""
923+
# Calculate the impact radius
924+
impact_radius = np.sqrt(table["true_core_x"]**2 + table["true_core_y"]**2)
925+
# Add the impact radius to the table
926+
table.add_column(impact_radius, name="impact_radius")
927+
return table
928+
897929
def _transform_to_cam_coord_offsets(self, table) -> Table:
898930
"""
899931
Transform Alt/Az coordinates to camera coordinate offsets w.r.t. the telescope pointing.

dl1_data_handler/tests/test_reader.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from traitlets.config.loader import Config
3+
import numpy as np
34

45
from dl1_data_handler.reader import DLImageReader, DLWaveformReader
56

@@ -20,6 +21,16 @@ def test_dl1_image_reading(dl1_image_reader):
2021
mono_batch = dl1_image_reader.generate_mono_batch([0])
2122
assert mono_batch["tel_id"] == 4 # nosec
2223
assert mono_batch["features"].shape == (1, 110, 110, 2) # nosec
24+
# Check that the columns that are kept have no NaN values
25+
for col in dl1_image_reader.example_ids_keep_columns:
26+
assert not np.isnan(mono_batch[col][0]) # nosec
27+
# Check that the transformation is also present and has no NaN values
28+
assert mono_batch["log_true_energy"][0] == np.log10(
29+
mono_batch["true_energy"][0]
30+
) # nosec
31+
assert mono_batch["impact_radius"][0] == np.sqrt(
32+
mono_batch["true_core_y"][0] ** 2 + mono_batch["true_core_x"][0] ** 2
33+
) # nosec
2334

2435

2536
def test_r1_waveform_reading(r1_tmp_path, r1_gamma_file):
@@ -46,7 +57,7 @@ def test_r1_waveform_reading(r1_tmp_path, r1_gamma_file):
4657
def test_dl1_hillas_parameter_extraction(dl1_image_reader):
4758
"""Test DL1 reader extracts hillas parameters correctly and handles missing keys."""
4859

49-
hillas_names_1 = dl1_image_reader.dl1b_parameter_colnames
60+
hillas_names_1 = dl1_image_reader.dl1b_parameter_colnames
5061

5162
hillas_names_2 = [
5263
"obs_id",

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
- numpy
1111
- scipy
1212
- pip
13-
- ctapipe==0.25.1
13+
- ctapipe>=0.22,<0.26
1414
- traitlets
1515
- pyyaml
1616
- pandas

0 commit comments

Comments
 (0)