Skip to content

Commit

Permalink
Merge pull request #276 from cta-observatory/implement_aux_traces
Browse files Browse the repository at this point in the history
Add support for types 2029 and 2030
  • Loading branch information
maxnoe authored Jul 16, 2024
2 parents 82d4fd4 + b5b4d3e commit f46e371
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/eventio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import subprocess as sp
import zstandard as zstd
from typing import Any

from .file_types import is_gzip, is_eventio, is_zstd
from .header import parse_header_bytes, get_bits_from_word
Expand Down Expand Up @@ -338,7 +339,7 @@ def __repr__(self):
def __str__(self):
return '{}[{}]'.format(self.__class__.__name__, self.header.type)

def parse(self):
def parse(self) -> Any:
if self.only_subobjects:
raise ValueError('This object only contains subobjects')

Expand Down
4 changes: 2 additions & 2 deletions src/eventio/iact/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def parse(self):
dtype=dtype,
count=self.n_telescopes * dtype.itemsize,
)
tel_pos = np.core.records.fromarrays(
tel_pos = np.rec.fromarrays(
block.reshape(4, self.n_telescopes),
names=['x', 'y', 'z', 'r'],
)
Expand Down Expand Up @@ -148,7 +148,7 @@ def parse(self):
# the columns are stored one after another
offsets = read_array(self, count=n_columns * n_arrays, dtype=np.float32)
offsets = offsets.reshape((n_columns, n_arrays))
offsets = np.core.records.fromarrays(offsets, names=columns)
offsets = np.rec.fromarrays(offsets, names=columns)

return time_offset, offsets

Expand Down
20 changes: 20 additions & 0 deletions src/eventio/simtel/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
read_float,
read_string,
read_from,
read_unsigned_int,
read_unsigned_short,
read_var_string,
read_varint,
Expand Down Expand Up @@ -1789,10 +1790,29 @@ def __str__(self):
class AuxiliaryDigitalTraces(EventIOObject):
eventio_type = 2029

def parse(self):
data = {}
data["tel_id"] = read_int(self)
data["time_scale"] = read_float(self)
n_traces = read_unsigned_varint(self)
n_samples = read_unsigned_varint(self)
array_data = self.read()
data["trace_data"], _ = unsigned_varint_arrays_differential(array_data, n_traces, n_samples)
return data


class AuxiliaryAnalogTraces(EventIOObject):
eventio_type = 2030

def parse(self):
data = {}
data["tel_id"] = read_int(self)
data["time_scale"] = read_float(self)
n_traces = read_unsigned_varint(self)
n_samples = read_unsigned_varint(self)
data["trace_data"] = read_array(self, np.float32, n_traces * n_samples).reshape(n_traces, n_samples)
return data


class FSPhot(EventIOObject):
'''No idea what this should be, it's only defined in io_hess.h, no
Expand Down
6 changes: 6 additions & 0 deletions src/eventio/simtel/simtelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ADCSamples,
ADCSums,
ArrayEvent,
AuxiliaryAnalogTraces,
AuxiliaryDigitalTraces,
CalibrationEvent,
CameraMonitoring,
CameraOrganization,
Expand Down Expand Up @@ -494,5 +496,9 @@ def parse_telescope_event(telescope_event):

elif isinstance(o, PixelTriggerTimes):
event['pixel_trigger_times'] = o.parse()
elif isinstance(o, (AuxiliaryAnalogTraces, AuxiliaryDigitalTraces)):
if "aux_traces" not in event:
event["aux_traces"] = {}
event["aux_traces"][o.header.id] = o.parse()

return event
Binary file added tests/resources/aux_traces_2029.simtel.zst
Binary file not shown.
Binary file added tests/resources/aux_traces_2030.simtel.zst
Binary file not shown.
19 changes: 14 additions & 5 deletions tests/simtel/test_simtel_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
yield_n_subobjects,
yield_subobjects,
)
from eventio.simtel.objects import ImageParameters, LaserCalibration, PixelList, PixelTiming, TriggerInformation
from eventio.simtel.objects import AuxiliaryAnalogTraces, AuxiliaryDigitalTraces, ImageParameters, LaserCalibration, PixelList, PixelTiming, TriggerInformation

prod2_file = 'tests/resources/gamma_test.simtel.gz'
camorgan_v2_file = 'tests/resources/test_camorganv2.simtel.gz'
Expand Down Expand Up @@ -749,14 +749,23 @@ def test_2028():
assert n_events > 0


@pytest.mark.xfail
def test_2029():
assert False
with EventIOFile("./tests/resources/aux_traces_2029.simtel.zst") as f:
o = next(yield_subobjects(f, AuxiliaryDigitalTraces))
assert o.header.type == 2029
data = o.parse()
assert data["tel_id"] == 1
assert data["trace_data"].shape == (588, 48)


@pytest.mark.xfail
def test_2030():
assert False
with EventIOFile("./tests/resources/aux_traces_2030.simtel.zst") as f:
o = next(yield_subobjects(f, AuxiliaryAnalogTraces))
assert o.header.type == 2030
data = o.parse()
assert data["tel_id"] == 1
assert data["trace_data"].dtype == np.float32
assert data["trace_data"].shape == (1855, 300)


@pytest.mark.xfail
Expand Down
14 changes: 14 additions & 0 deletions tests/simtel/test_simtelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,17 @@ def test_type_2033():
'flags', 'n_pixels', 'n_gains', 'nsb_rate', 'qe_rel', 'gain_rel',
'hv_rel', 'current', 'fadc_amp_hg', 'disabled',
}


def test_type_2029():
with SimTelFile("./tests/resources/aux_traces_2029.simtel.zst") as f:
e = next(iter(f))
assert "aux_traces" in e["telescope_events"][1]
assert e["telescope_events"][1]["aux_traces"].keys() == {1}


def test_type_2030():
with SimTelFile("./tests/resources/aux_traces_2030.simtel.zst") as f:
e = next(iter(f))
assert "aux_traces" in e["telescope_events"][1]
assert e["telescope_events"][1]["aux_traces"].keys() == {1, 2}

0 comments on commit f46e371

Please sign in to comment.