Skip to content

Commit

Permalink
Add support for PixelList v1, fixes #265
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Nov 9, 2023
1 parent c505ab6 commit 7e72b61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/eventio/simtel/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion 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, 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'
Expand Down Expand Up @@ -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"""

Expand Down

0 comments on commit 7e72b61

Please sign in to comment.