Skip to content

Commit

Permalink
Do not require SubarrayDataStream, will not be written by current swat
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Sep 4, 2023
1 parent 44362f4 commit 022cfd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
36 changes: 17 additions & 19 deletions src/ctapipe_io_zfits/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,24 @@
from ctapipe_io_zfits.time import time_to_cta_high_res

ANY_ARRAY_TYPE_TO_NUMPY_TYPE = {
1: np.int8,
2: np.uint8,
3: np.int16,
4: np.uint16,
5: np.int32,
6: np.uint32,
7: np.int64,
8: np.uint64,
9: np.float32,
10: np.float64,
AnyArray.S8: np.int8,
AnyArray.U8: np.uint8,
AnyArray.S16: np.int16,
AnyArray.U16: np.uint16,
AnyArray.S32: np.int32,
AnyArray.U32: np.uint32,
AnyArray.S64: np.int64,
AnyArray.U64: np.uint64,
AnyArray.FLOAT: np.float32,
AnyArray.DOUBLE: np.float64,
}

DTYPE_TO_ANYARRAY_TYPE = {v: k for k, v in ANY_ARRAY_TYPE_TO_NUMPY_TYPE.items()}

acada_user = "ctao-acada-n"
obs_start = Time("2023-08-02T02:15:31")
timezone_canary = ZoneInfo("Atlantic/Canary")
timezone_cta_n = ZoneInfo("Atlantic/Canary")

array_elements = {
1: "LSTN-01",
}


def to_anyarray(array):
Expand Down Expand Up @@ -65,13 +62,13 @@ def dl0_base(acada_base):
dl0 = acada_base / "DL0"
dl0.mkdir(exist_ok=True)

lst_base = dl0 / array_elements[1] / acada_user / "acada-adh"
lst_base = dl0 / "LSTN-01" / acada_user / "acada-adh"
lst_events = lst_base / "events"
lst_monitoring = lst_base / "monitoring"
array_triggers = dl0 / "array" / acada_user / "acada-adh" / "triggers"
array_monitoring = dl0 / "array" / acada_user / "acada-adh" / "monitoring"

evening = evening_of_obs(obs_start, timezone_canary)
evening = evening_of_obs(obs_start, timezone_cta_n)

for directory in (lst_events, lst_monitoring, array_triggers, array_monitoring):
date_path = directory / f"{evening:%Y/%m/%d}"
Expand Down Expand Up @@ -104,6 +101,7 @@ def dummy_dl0(dl0_base):
producer_id=producer_id,
sb_creator_id=sb_creator_id,
)

lst_data_stream = DL0_Telescope.DataStream(
tel_id=1,
sb_id=sb_id,
Expand Down Expand Up @@ -161,9 +159,9 @@ def open_next_event_file(sdh_id):
with ctx:
trigger_file = ctx.enter_context(ProtobufZOFits(**proto_kwargs))
trigger_file.open(str(trigger_path))
trigger_file.move_to_new_table("DataStream")
trigger_file.write_message(subarray_data_stream)
trigger_file.move_to_new_table("Events")
# trigger_file.move_to_new_table("DataStream")
# trigger_file.write_message(subarray_data_stream)
trigger_file.move_to_new_table("SubarrayEvents")

for sdh_id in sdh_ids:
open_next_event_file(sdh_id)
Expand Down
34 changes: 17 additions & 17 deletions src/ctapipe_io_zfits/dl0.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SchedulingBlockContainer,
TriggerContainer,
)
from ctapipe.core.traits import Integer
from ctapipe.instrument import SubarrayDescription
from ctapipe.io import DataLevel, EventSource
from protozfits import File
Expand All @@ -41,6 +42,7 @@ class ProtozfitsDL0EventSource(EventSource):
will then look for the other data files according to the filename and
directory schema layed out in the draft of the ACADA - DPPS ICD.
"""
subarray_id = Integer(default_value=1).tag(config=True)

def __init__(self, input_url=None, **kwargs):
if input_url is not None:
Expand All @@ -52,14 +54,18 @@ def __init__(self, input_url=None, **kwargs):
self._subarray_trigger_file = self._exit_stack.enter_context(
File(str(self.input_url))
)
self._subarray_trigger_stream = self._subarray_trigger_file.DataStream[0]

self._subarray = build_subarray_description(
self._subarray_trigger_stream.subarray_id
)

self.obs_id = self._subarray_trigger_stream.obs_id
self.sb_id = self._subarray_trigger_stream.sb_id
self._subarray_trigger_stream = None
if hasattr(self._subarray_trigger_file, "DataStream"):
self._subarray_trigger_stream = self._subarray_trigger_file.DataStream[0]
self.sb_id = self._subarray_trigger_stream.sb_id
self.obs_id = self._subarray_trigger_stream.obs_id
self.subarray_id = self._subarray_trigger_stream.subarray_id
else:
first_event = self._subarray_trigger_file.SubarrayEvents[0]
self.sb_id = first_event.sb_id
self.obs_id = first_event.obs_id

self._subarray = build_subarray_description(self.subarray_id)

self._observation_blocks = {
self.obs_id: ObservationBlockContainer(
Expand Down Expand Up @@ -122,7 +128,7 @@ def scheduling_blocks(self) -> Dict[int, SchedulingBlockContainer]:
return self._scheduling_blocks

def _generator(self):
for subarray_trigger in self._subarray_trigger_file.Events:
for subarray_trigger in self._subarray_trigger_file.SubarrayEvents:
array_event = ArrayEventContainer(
index=EventIndexContainer(
obs_id=subarray_trigger.obs_id, event_id=subarray_trigger.event_id
Expand Down Expand Up @@ -184,17 +190,11 @@ def is_compatible(cls, input_url):
log.debug(f"Error trying to open input file as fits: {e}")
return False

if "DataStream" not in hdul:
log.debug(
"FITS file does not contain a DataStream HDU, returning False"
)
return False

if "Events" not in hdul:
if "SubarrayEvents" not in hdul:
log.debug("FITS file does not contain an Events HDU, returning False")
return False

header = hdul["Events"].header
header = hdul["SubarrayEvents"].header

if header["XTENSION"] != "BINTABLE":
log.debug("Events HDU is not a bintable")
Expand Down

0 comments on commit 022cfd0

Please sign in to comment.