Skip to content

Commit

Permalink
Merge pull request #210 from cta-observatory/add_support_lstv09_files
Browse files Browse the repository at this point in the history
Handle loading LST DL1 file from lstchain v0.9
  • Loading branch information
jsitarek authored Apr 5, 2024
2 parents 8663b3d + dc91ab9 commit 9dc7730
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions magicctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
# "dl1_LST-1.Run15337.0001.h5",
"dl1_LST-1.Run15337.0002.h5"
]
DL1_LST_old_lstchain = "dl1_LST-1.Run03265.0094.h5"


"""
Temporary paths
Expand Down Expand Up @@ -382,6 +384,19 @@ def dl1_lst(base_url, env_prefix):
return LST_dl1


@pytest.fixture(scope="session")
def dl1_lst_old(base_url, env_prefix):
download_path = download_file_cached(
name=f"LST/{DL1_LST_old_lstchain}",
cache_name="magicctapipe",
env_prefix=env_prefix,
auth=True,
default_url=base_url,
progress=True,
)
return download_path


@pytest.fixture(scope="session")
def config():
config_path = resource_file("test_config.yaml")
Expand Down
13 changes: 12 additions & 1 deletion magicctapipe/io/io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
I/O utilities
"""

import glob
import logging
import pprint
Expand All @@ -16,6 +17,7 @@
from ctapipe.containers import EventType
from ctapipe.coordinates import CameraFrame
from ctapipe.instrument import SubarrayDescription
from ctapipe_io_lst import REFERENCE_LOCATION, LSTEventSource
from lstchain.reco.utils import add_delta_t_key
from pyirf.binning import join_bin_lo_hi
from pyirf.simulations import SimulatedEventsInfo
Expand Down Expand Up @@ -607,7 +609,16 @@ def load_lst_dl1_data_file(input_file):
event_data["psi"] = np.rad2deg(event_data["psi"])

# Read the subarray description
subarray = SubarrayDescription.from_hdf(input_file)
try:
subarray = SubarrayDescription.from_hdf(input_file)
except OSError:
logger.warning(
"SubarrayDescription couldn't be loaded from the LST-1 file.\n"
"It is likely not from lstchain v0.10. A default one will replace it."
)
subarray = LSTEventSource.create_subarray(
tel_id=1, reference_location=REFERENCE_LOCATION
)

if focal_length == EQUIVALENT_FOCLEN_LST:
# Set the effective focal length to the subarray description
Expand Down
15 changes: 15 additions & 0 deletions magicctapipe/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pandas as pd
import pytest
from ctapipe_io_lst import REFERENCE_LOCATION

from magicctapipe.io.io import (
check_input_list,
Expand Down Expand Up @@ -522,6 +523,20 @@ def test_load_irf_files_exc(self, temp_irf_exc):


class TestDL1LST:
def test_load_lst_dl1_data_file_old(self, dl1_lst_old):
"""
Check on LST DL1
"""
events, subarray = load_lst_dl1_data_file(str(dl1_lst_old))
assert "event_type" in events.columns
assert "slope" in events.columns
assert "az_tel" not in events.columns
events = events.reset_index()
s = events.duplicated(subset=["obs_id_lst", "event_id_lst"])
assert np.all(s == False)
assert subarray.name == "LST-1 subarray"
assert subarray.reference_location == REFERENCE_LOCATION

@pytest.mark.dependency()
def test_load_lst_dl1_data_file(self, dl1_lst):
"""
Expand Down

0 comments on commit 9dc7730

Please sign in to comment.