Skip to content

Commit

Permalink
Set null island as fallback reference location in Subarray.from_hdf, f…
Browse files Browse the repository at this point in the history
…ixes #2626
  • Loading branch information
maxnoe committed Oct 24, 2024
1 parent 40faf69 commit c594ffc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changes/2627.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fix that hdf5 files created with older versions of ctapipe, e.g.
the public dataset created with 0.17 can be read by ctapipe-process.
These files are missing the subarray reference location, which was
introduced in later versions of ctapipe. A dummy location (lon=0, lat=0)
is used for these now, the same value is already used for simtel files
lacking this information.
8 changes: 7 additions & 1 deletion src/ctapipe/instrument/subarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ def from_hdf(cls, path, focal_length_choice=FocalLengthKind.EFFECTIVE):

positions = np.column_stack([layout[f"pos_{c}"] for c in "xyz"])

reference_location = None
name = layout.meta.get("SUBARRAY", "Unknown")

if "reference_itrs_x" in layout.meta:
Expand All @@ -760,6 +759,13 @@ def from_hdf(cls, path, focal_length_choice=FocalLengthKind.EFFECTIVE):
y=layout.meta["reference_itrs_y"] * u.m,
z=layout.meta["reference_itrs_z"] * u.m,
)
else:
# "null island" dummy location for backwards compatibility with old files
reference_location = EarthLocation(
lon=0 * u.deg,
lat=0 * u.deg,
height=0 * u.m,
)

return cls(
name=str(name),
Expand Down
29 changes: 28 additions & 1 deletion src/ctapipe/tools/tests/test_process.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3

"""
Test ctapipe-process on a few different use cases
"""
Expand Down Expand Up @@ -488,3 +487,31 @@ def test_only_trigger_and_simulation(tmp_path):
assert len(events) == 7
assert "tels_with_trigger" in events.colnames
assert "true_energy" in events.colnames


@pytest.mark.parametrize(
("input_url", "args"),
[
pytest.param(
"dataset://gamma_diffuse_dl2_train_small.dl2.h5",
["--no-write-images", "--max-events=5"],
id="0.17",
)
],
)
def test_on_old_file(input_url, args, tmp_path):
config = resource_file("stage1_config.json")

output_path = tmp_path / "test.dl1.h5"
run_tool(
ProcessorTool(),
argv=[
f"--config={config}",
f"--input={input_url}",
f"--output={output_path}",
"--overwrite",
*args,
],
cwd=tmp_path,
raises=True,
)

0 comments on commit c594ffc

Please sign in to comment.