def test_read_run_header(): with eventio.EventIOFile(testfile) as f: run_header = next(f).parse() assert run_header['energy_min'] == approx(5.0) assert run_header['energy_max'] == approx(100.0) assert run_header['energy_spectrum_slope'] == approx(-2.7)
def test_seek(): with eventio.EventIOFile(testfile) as f: obj = next(f) obj.seek(0) pos = obj.seek(0, 2) assert pos == obj.header.content_size
def test_types_zcat(): from eventio.base import PipeWrapper testfile = 'tests/resources/one_shower.dat.gz' f = eventio.EventIOFile(testfile) assert isinstance(f._filehandle, PipeWrapper) types = [o.header.type for o in f] assert types == [1200, 1212, 1201, 1202, 1203, 1204, 1209, 1210]
def test_tell(): with eventio.EventIOFile(testfile) as f: obj = next(f) obj.seek(0) assert obj.tell() == 0 obj.read(4) assert obj.tell() == 4
def test_event_has_382_bunches(): from eventio.iact import Photons, TelescopeData with eventio.EventIOFile(testfile) as f: # first telescope data object should be the 6th object in the file for i in range(6): obj = next(f) assert isinstance(obj, TelescopeData) photons = next(obj) assert isinstance(photons, Photons) assert photons.n_bunches == 382
def test_corsika_event_header(): from eventio.iact import EventHeader with eventio.EventIOFile(testfile) as f: # first event header should be the 4th object in the file for i in range(4): obj = next(f) assert isinstance(obj, EventHeader) event_header = obj.parse() assert event_header['event_number'] == 1 assert event_header['zenith'] == approx(0.0) assert event_header['azimuth'] == approx(0.0) assert event_header['total_energy'] == approx(9.3249321)
def test_corsika_array_offsets(): from eventio.iact import ArrayOffsets with eventio.EventIOFile(testfile) as f: # first array offset object should be the 5th object in the file for i in range(5): obj = next(f) assert isinstance(obj, ArrayOffsets) time_offset, offsets = obj.parse() assert len(offsets) == 1 assert offsets['x'][0] == approx(-506.9717102050781) assert offsets['y'][0] == approx(-3876.447265625)
def test_bunches(): from eventio.iact import TelescopeData columns = ('x', 'y', 'cx', 'cy', 'time', 'zem', 'photons', 'wavelength') with eventio.EventIOFile(testfile) as f: # first telescope data object should be the 6th object in the file for i in range(6): obj = next(f) assert isinstance(obj, TelescopeData) photons = next(obj) bunches, emitter = photons.parse() assert bunches.dtype.names == columns assert emitter is None
def test_telescope_definition(): from eventio.iact import TelescopeDefinition with eventio.EventIOFile(testfile) as f: next(f) # skip run_header next(f) # skip inputcard telescope_definition = next(f) assert isinstance(telescope_definition, TelescopeDefinition) assert telescope_definition.n_telescopes == 1 telescope_definition_data = telescope_definition.parse() assert telescope_definition_data['x'][0] == approx(0.0) assert telescope_definition_data['y'][0] == approx(0.0) assert telescope_definition_data['z'][0] == approx(2500.0) assert telescope_definition_data['r'][0] == approx(2500.0)
def test_file_has_objects_at_expected_position(): expected = [ (16, 1096), (1128, 448), (1592, 20), (1628, 1096), (2740, 16), (2772, 6136), (8924, 1096), (10036, 16), ] testfile = 'tests/resources/one_shower.dat' f = eventio.EventIOFile(testfile) for o, (addr, size) in zip_longest(f, expected): assert o.header.content_address == addr assert o.header.content_size == size
def test_atmospheric_profile(): from eventio.iact.objects import AtmosphericProfile atmprof8 = np.genfromtxt('tests/resources/atmprof8.dat') with eventio.EventIOFile(test_profile_file) as f: for i in range(3): o = next(f) assert isinstance(o, AtmosphericProfile) profile = o.parse() assert profile['id'] == 8 assert profile['name'] == b'atmprof8.dat' assert np.allclose(profile['altitude_km'], atmprof8[:, 0]) assert np.allclose(profile['rho'], atmprof8[:, 1]) assert np.allclose(profile['thickness'], atmprof8[:, 2]) assert np.allclose(profile['refractive_index_minus_1'], atmprof8[:, 3])
def test_emitter_bunches(): from eventio.iact import TelescopeData columns = ('x', 'y', 'cx', 'cy', 'time', 'zem', 'photons', 'wavelength') with eventio.EventIOFile(test_emitter_file) as f: # first telescope data object should be the 6th object in the file for i in range(7): obj = next(f) assert isinstance(obj, TelescopeData) photons = next(obj) bunches, emitter = photons.parse() assert bunches.dtype.names == columns assert len(emitter) == len(bunches) assert np.all(emitter['wavelength'] == np.float32(9999)) # lightest particle should be an electron assert np.isclose(np.unique(emitter['mass'])[0], 0.000511, rtol=0.1) # second lightest particle should be a muon assert np.isclose(np.unique(emitter['mass'])[1], 0.105, rtol=0.1)
def test_can_open_file(): testfile = 'tests/resources/one_shower.dat' eventio.EventIOFile(testfile)
def test_file_has_correct_types(): testfile = 'tests/resources/one_shower.dat' f = eventio.EventIOFile(testfile) types = [o.header.type for o in f] assert types == [1200, 1212, 1201, 1202, 1203, 1204, 1209, 1210]
def test_types_gzip(): testfile = 'tests/resources/one_shower.dat.gz' f = eventio.EventIOFile(testfile, zcat=False) types = [o.header.type for o in f] assert types == [1200, 1212, 1201, 1202, 1203, 1204, 1209, 1210]
def test_file_has_run_header(): from eventio.iact import RunHeader with eventio.EventIOFile(testfile) as f: obj = next(f) assert isinstance(obj, RunHeader)
def test_file_is_iterable(): testfile = 'tests/resources/one_shower.dat' f = eventio.EventIOFile(testfile) for event in f: pass