From 7e72b617547cb64f11f56a38927b6958964e2df4 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Tue, 7 Nov 2023 17:25:28 +0100 Subject: [PATCH] Add support for PixelList v1, fixes #265 --- src/eventio/simtel/objects.py | 14 ++++++++------ tests/simtel/test_simtel_objects.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/eventio/simtel/objects.py b/src/eventio/simtel/objects.py index 57bc345..c4ba425 100644 --- a/src/eventio/simtel/objects.py +++ b/src/eventio/simtel/objects.py @@ -1735,15 +1735,17 @@ def parse(self): # even in the prod3b version of Max N the objects # of type 2027 seem to be of version 0 only. # not sure if version 1 was ever produced. - assert_exact_version(self, supported_version=0) + assert_max_version(self, last_supported=1) self.seek(0) byte_stream = BytesIO(self.read()) - pixels = read_short(byte_stream) - # in version 1 pixels is a crazy int - - pixel_list = read_array(byte_stream, 'i2', pixels) - # in version 1 pixel_list is an array of crazy int + if self.header.version < 1: + pixels = read_short(byte_stream) + pixel_list = read_array(byte_stream, 'i2', pixels) + else: + pixels = read_varint(byte_stream) + data = read_remaining_with_check(byte_stream, self.header.content_size) + pixel_list, _ = varint_array(data, pixels) return { 'code': self.code, diff --git a/tests/simtel/test_simtel_objects.py b/tests/simtel/test_simtel_objects.py index ce44f61..807c06e 100644 --- a/tests/simtel/test_simtel_objects.py +++ b/tests/simtel/test_simtel_objects.py @@ -8,7 +8,7 @@ yield_n_subobjects, yield_subobjects, ) -from eventio.simtel.objects import ImageParameters, LaserCalibration, TriggerInformation +from eventio.simtel.objects import ImageParameters, LaserCalibration, PixelList, TriggerInformation prod2_file = 'tests/resources/gamma_test.simtel.gz' camorgan_v2_file = 'tests/resources/test_camorganv2.simtel.gz' @@ -845,6 +845,18 @@ def test_laser_calibration_n_pixels(): assert data["calib"].shape == (1, 40000) +def test_pixel_list_version_1(): + """Test for implementation of #265""" + + with EventIOFile("tests/resources/40k_pixels.simtel.zst") as f: + expected = [49, 34] + for pixel_list, pixels in zip_longest(yield_subobjects(f, PixelList), expected): + assert pixel_list.header.version == 1 + data = pixel_list.parse() + assert data["pixels"] == pixels + assert data["pixel_list"].shape == (pixels, ) + + def test_image_parameters_version_6(): """Test for implementation of #266"""