diff --git a/eventio/__init__.py b/eventio/__init__.py index 83f591b5..7c1b1611 100644 --- a/eventio/__init__.py +++ b/eventio/__init__.py @@ -6,7 +6,7 @@ from .histograms import Histograms -__version__ = '0.21.3' +__version__ = '0.21.4' __all__ = [ 'EventIOFile', diff --git a/eventio/simtel/objects.py b/eventio/simtel/objects.py index 3feb6a83..845e1fbf 100644 --- a/eventio/simtel/objects.py +++ b/eventio/simtel/objects.py @@ -534,7 +534,8 @@ def __str__(self): ) def parse(self): - assert_max_version(self, 2) + assert_max_version(self, 3) + self.seek(0) byte_stream = BytesIO(self.read()) @@ -544,7 +545,8 @@ def parse(self): event_info['trigger_pattern'] = read_int(byte_stream) event_info['data_pattern'] = read_int(byte_stream) - if self.header.version >= 1: + version = self.header.version + if version >= 1: tels_trigger = read_short(byte_stream) event_info['n_triggered_telescopes'] = tels_trigger @@ -560,7 +562,7 @@ def parse(self): byte_stream, count=tels_data, dtype='= 2: + if version >= 2: # konrad saves the trigger mask as crazy int, but it uses only 4 bits # so it should be indentical to a normal unsigned int with 1 byte event_info['teltrg_type_mask'] = read_array( @@ -579,6 +581,14 @@ def parse(self): t = read_float(byte_stream) event_info['teltrg_time_by_type'][tel_id][trigger] = t + if version >= 3: + # information about "plane wavefront compensation" + comp = {} + comp['az'] = read_float(byte_stream) + comp['alt'] = read_float(byte_stream) + comp['speed_of_light'] = read_float(byte_stream) + event_info['plane_wavefront_compensation'] = comp + return event_info @@ -698,7 +708,7 @@ def __str__(self): ) def parse(self): - assert_max_version(self, 2) + assert_max_version(self, 3) self.seek(0) byte_stream = BytesIO(self.read()) @@ -749,6 +759,11 @@ def parse(self): ) pos += length + if self.header.version >= 3: + times = struct.unpack('ff', data[pos:pos + 8]) + pos += 8 + event_head['readout_time'], event_head['relative_trigger_time'] = times + event_head['telescope_id'] = self.header.id return event_head diff --git a/tests/simtel/test_simtel_objects.py b/tests/simtel/test_simtel_objects.py index 930945de..2e46092b 100644 --- a/tests/simtel/test_simtel_objects.py +++ b/tests/simtel/test_simtel_objects.py @@ -161,7 +161,7 @@ def test_2003_v2(): # print(pixel_id, sector) -def test_2004_3_objects(): +def test_2004(): from eventio.simtel.objects import PixelSettings with EventIOFile(prod2_file) as f: @@ -245,7 +245,7 @@ def test_2008_3_objects(): assert tracking_info['range_high_alt'] == approx(2 * np.pi) -def test_2009_3_objects(): +def test_2009(): from eventio.simtel.objects import TriggerInformation with EventIOFile(prod2_file) as f: @@ -255,6 +255,17 @@ def test_2009_3_objects(): assert 'gps_time' in data assert 'teltrg_time_by_type' in data + with EventIOFile('tests/resources/prod4_pixelsettings_v3.gz') as f: + for o in yield_n_and_assert(f, TriggerInformation, n=10): + assert o.header.version == 3 + + data = parse_and_assert_consumption(o, limit=3) + assert 'plane_wavefront_compensation' in data + comp = data['plane_wavefront_compensation'] + assert comp['az'] == 0 + assert comp['alt'] == np.float32(np.pi / 2) + assert comp['speed_of_light'] == approx(29.97, abs=0.01) + def test_2100_3_objects(): from eventio.simtel.objects import TrackingPosition @@ -288,7 +299,7 @@ def test_2010(): assert n_events > 0 -def test_2011_3_objects(): +def test_2011(): from eventio.simtel.objects import TelescopeEventHeader with EventIOFile(prod2_file) as f: @@ -358,6 +369,12 @@ def test_2011_3_objects(): } ''' + with EventIOFile('tests/resources/prod4_pixelsettings_v3.gz') as f: + for i, o in enumerate(yield_n_and_assert(f, TelescopeEventHeader, n=10)): + o = parse_and_assert_consumption(o, limit=3) + assert 'relative_trigger_time' in o + assert 'readout_time' in o + def test_2012_3_objects(): from eventio.simtel.objects import ADCSums diff --git a/tests/simtel/test_simtelfile.py b/tests/simtel/test_simtelfile.py index d31b122a..ae70422d 100644 --- a/tests/simtel/test_simtelfile.py +++ b/tests/simtel/test_simtelfile.py @@ -182,3 +182,11 @@ def test_skip_calibration_events(): def test_frankenstein(): with SimTelFile(frankenstein_path) as f: assert len(f.telescope_descriptions) == f.n_telescopes + + +def test_new_prod4(): + with SimTelFile('tests/resources/prod4_pixelsettings_v3.gz') as f: + i = 0 + for e in f: + i += 1 + assert i == 10