Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6605589
test
Jun 26, 2025
1a68509
first working version, ruff
Jun 26, 2025
0791398
adding/fixing tests, ruff
Jun 28, 2025
473c0a1
ruff
Jun 30, 2025
298dc02
updating docs
Jun 30, 2025
9aaba99
fix the docs, ruff
Jun 30, 2025
8042312
addressing sonarqube, ruff
Jul 1, 2025
5d7b24b
addressing review, ruff
Jul 1, 2025
c07cb52
modifying renaming functionality
Jul 4, 2025
44a66a9
Improving changelog
Jul 7, 2025
2ca592e
Improving changelog
Jul 7, 2025
9042d95
Removing disable_column_renaming
Jul 8, 2025
4661647
addressing review
Jul 9, 2025
dd4902a
simpifying the table construction
Jul 15, 2025
42f58d2
addressing review
Jul 15, 2025
36f3eeb
relocating preprocessing to io
Jul 16, 2025
d035775
fixing docs and circular imports
Jul 16, 2025
40d9f50
fixing tests
Jul 16, 2025
15396e3
fixing import that strangely wasn't caught by the tests
Jul 16, 2025
ccd427b
trying to fix the minimal dependencies issue
Jul 17, 2025
8c924fa
Revert "trying to fix the minimal dependencies issue"
mexanick Jul 17, 2025
fb5f8ea
moving all tests that implicitly use pyirf to irf
Jul 17, 2025
7f3a16c
removing duplicated lines
Jul 17, 2025
5d07e5a
Make pyirf dependency optional, fix dl2_tables_preprocessing exposure
mexanick Jul 17, 2025
802319d
resolving conflicts
Jul 17, 2025
9af99dd
Fix min tests for preprocessing
mexanick Jul 18, 2025
4a234a6
Remove "u.dimensionless_unscaled" units from gh_score and weights.
mexanick Jul 22, 2025
7d4960d
fix test fixture (new order of columns)
mexanick Jul 22, 2025
e9a17ca
improving the help of a config parameter
Jul 28, 2025
1fa7012
supported pointing frames
Aug 4, 2025
6bfc371
Variable names, warning, imports
Sep 21, 2025
fed7c7f
Variable names, warning, imports
Sep 21, 2025
4061c9d
Put annotation when needed by the new importing scheme
Sep 21, 2025
11d98e2
Reverting to correct exception
Sep 22, 2025
e94ac42
Merge branch 'main' into generalise_table_preprocessing
maxnoe Oct 9, 2025
d685e25
Merge remote-tracking branch 'origin/main' into generalise_table_prep…
maxnoe Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/ctapipe/io/dl2_tables_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
calculate_event_weights,
)
from pyirf.utils import calculate_source_fov_offset, calculate_theta
except ModuleNotFoundError:
SimulatedEventsInfo = None
DIFFUSE_FLUX_UNIT = None
POINT_SOURCE_FLUX_UNIT = None
PowerLaw = None
calculate_event_weights = None
calculate_source_fov_offset = None
calculate_theta = None

has_pyirf = True
except ModuleNotFoundError:
has_pyirf = False

from tables import NoSuchNodeError
from traitlets import default
Expand Down Expand Up @@ -302,24 +297,26 @@ def load_preselected_events(

opts = dict(dl2=True, simulated=True, observation_info=True)

with TableLoader(self.file, parent=self, **opts) as load:
header = self.epp.make_empty_table()
sim_info, spectrum = self.get_simulation_information(load, obs_time)
with TableLoader(self.file, parent=self, **opts) as loader:
table_template = self.epp.make_empty_table()
sim_info, spectrum = self.get_simulation_information(loader, obs_time)
meta = {"sim_info": sim_info, "spectrum": spectrum}
bits = [header]
event_chunks = [table_template]
n_raw_events = 0
reader_func = getattr(load, self.event_reader_function)
reader_func = getattr(loader, self.event_reader_function)
table_reader = reader_func(chunk_size, **opts, **self.event_reader_kwargs)
for _, _, events in table_reader:
selected = events[self.epp.quality_query.get_table_mask(events)]
selected = self.epp.normalise_column_names(selected)
if self.epp.apply_derived_columns:
selected = self.make_derived_columns(selected)
bits.append(selected)
event_chunks.append(selected)
n_raw_events += len(events)

bits.append(header) # Putting it last ensures the correct metadata is used
table = vstack(bits, join_type="exact", metadata_conflicts="silent")
event_chunks.append(
table_template
) # Putting it last ensures the correct metadata is used
table = vstack(event_chunks, join_type="exact", metadata_conflicts="silent")
return table, n_raw_events, meta

def get_simulation_information(
Expand Down Expand Up @@ -347,15 +344,17 @@ def get_simulation_information(
NotImplementedError
If simulation parameters vary across runs.
"""
from ..exceptions import OptionalDependencyMissing

if SimulatedEventsInfo is None:
raise OptionalDependencyMissing("pyirf")
raise ImportError("pyirf is required for this functionality")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you replace the correct usage of the OptionalDependencyMissing exception here?


sim = loader.read_simulation_configuration()
try:
show = loader.read_shower_distribution()
except NoSuchNodeError:
self.log.warning(
"Simulation distributions were not found in the input files, falling back to estimating the number of showers from the simulation configuration."
)
show = Table([sim["n_showers"]], names=["n_entries"], dtype=[np.int64])
Comment thread
mexanick marked this conversation as resolved.

for itm in ["spectral_index", "energy_range_min", "energy_range_max"]:
Expand Down
Loading