def test_read_container(temp_h5_file): r0tel1 = R0CameraContainer() r0tel2 = R0CameraContainer() mc = MCEventContainer() reader = HDF5TableReader(str(temp_h5_file)) # get the generators for each table mctab = reader.read('/R0/MC', mc) r0tab1 = reader.read('/R0/tel_001', r0tel1) r0tab2 = reader.read('/R0/tel_002', r0tel2) # read all 3 tables in sync for ii in range(3): m = next(mctab) r0_1 = next(r0tab1) r0_2 = next(r0tab2) print("MC:", m) print("t0:", r0_1.image) print("t1:", r0_2.image) print("---------------------------") assert 'test_attribute' in r0_1.meta assert r0_1.meta['date'] == "2020-10-10" reader.close()
def test_read_container(temp_h5_file): r0tel1 = R0CameraContainer() r0tel2 = R0CameraContainer() mc = MCEventContainer() with HDF5TableReader(temp_h5_file) as reader: # get the generators for each table mctab = reader.read("/R0/MC", mc) r0tab1 = reader.read("/R0/tel_001", r0tel1) r0tab2 = reader.read("/R0/tel_002", r0tel2) # read all 3 tables in sync for ii in range(3): m = next(mctab) r0_1 = next(r0tab1) r0_2 = next(r0tab2) print("MC:", m) print("t0:", r0_1.waveform) print("t1:", r0_2.waveform) print("---------------------------") assert "test_attribute" in r0_1.meta assert r0_1.meta["date"] == "2020-10-10"
def test_read_whole_table(temp_h5_file): mc = MCEventContainer() with HDF5TableReader(temp_h5_file) as reader: for cont in reader.read("/R0/MC", mc): print(cont)
def test_read_whole_table(temp_h5_file): mc = MCEventContainer() reader = HDF5TableReader(str(temp_h5_file)) for cont in reader.read('/R0/MC', mc): print(cont)
def test_write_container(temp_h5_file): r0tel = R0CameraContainer() mc = MCEventContainer() mc.reset() r0tel.waveform = np.random.uniform(size=(50, 10)) r0tel.image = np.random.uniform(size=50) r0tel.num_samples = 10 r0tel.meta['test_attribute'] = 3.14159 r0tel.meta['date'] = "2020-10-10" writer = HDF5TableWriter(str(temp_h5_file), group_name='R0', filters=tables.Filters(complevel=7)) writer.exclude("tel_002", ".*samples") # test exclusion of columns for ii in range(100): r0tel.waveform[:] = np.random.uniform(size=(50, 10)) r0tel.image[:] = np.random.uniform(size=50) r0tel.num_samples = 10 mc.energy = 10**np.random.uniform(1, 2) * u.TeV mc.core_x = np.random.uniform(-1, 1) * u.m mc.core_y = np.random.uniform(-1, 1) * u.m writer.write("tel_001", r0tel) writer.write("tel_002", r0tel) # write a second table too writer.write("MC", mc) writer.close()
def test_with_context_reader(temp_h5_file): mc = MCEventContainer() with HDF5TableReader(str(temp_h5_file)) as h5_table: assert h5_table._h5file.isopen == True for cont in h5_table.read('/R0/MC', mc): print(cont) assert h5_table._h5file.isopen == False
def test_with_context_reader(temp_h5_file): mc = MCEventContainer() with HDF5TableReader(temp_h5_file) as h5_table: assert h5_table._h5file.isopen == 1 for cont in h5_table.read("/R0/MC", mc): print(cont) assert h5_table._h5file.isopen == 0
def test_write_container(temp_h5_file): r0tel = R0CameraContainer() mc = MCEventContainer() mc.reset() r0tel.adc_samples = np.random.uniform(size=(50, 10)) r0tel.adc_sums = np.random.uniform(size=50) r0tel.num_samples = 10 r0tel.meta['test_attribute'] = 3.14159 r0tel.meta['date'] = "2020-10-10" writer = HDF5TableWriter(str(temp_h5_file), group_name='R0', filters=tables.Filters( complevel=7)) writer.exclude("tel_002",".*samples") # test exclusion of columns for ii in range(100): r0tel.adc_samples[:] = np.random.uniform(size=(50, 10)) r0tel.adc_sums[:] = np.random.uniform(size=50) r0tel.num_samples = 10 mc.energy = 10**np.random.uniform(1,2) * u.TeV mc.core_x = np.random.uniform(-1, 1) * u.m mc.core_y = np.random.uniform(-1, 1) * u.m writer.write("tel_001", r0tel) writer.write("tel_002", r0tel) # write a second table too writer.write("MC", mc)
class ArrayEventContainer(Container): container_prefix = '' run_id = Field(-1, 'run id') array_event_id = Field(-1, 'array event id') reco = Field(ReconstructedShowerContainer(), 'reconstructed shower container') mc = Field(MCEventContainer(), 'array wide MC information') total_intensity = Field(np.nan, 'sum of all intensities') num_triggered_telescopes = Field(np.nan, 'Number of triggered Telescopes') num_triggered_lst = Field(np.nan, 'Number of triggered LSTs') num_triggered_mst = Field(np.nan, 'Number of triggered MSTs') num_triggered_sst = Field(np.nan, 'Number of triggered SSTs')
class CalibrationContainer(Container): """ This Container() is used for the camera calibration pipeline. It is meant to save each step of the calibration pipeline """ config = Field(list, 'List of the input parameters' ' of the calibration analysis') # Should use dict? pixel_id = Field(ndarray, 'pixel ids') data = CalibrationEventContainer() event_id = Field(int, 'event_id') event_type = Field(CameraEventType, 'Event type') hillas = Field(HillasParametersContainer, 'Hillas parameters') info = CalibrationContainerMeta() slow_data = Field(None, "Slow Data Information") mc = Field(MCEventContainer(), "Monte-Carlo data")
def test_read_container(temp_h5_file): r0tel1 = R0CameraContainer() r0tel2 = R0CameraContainer() mc = MCEventContainer() reader = SimpleHDF5TableReader(str(temp_h5_file)) # get the generators for each table mctab = reader.read('/R0/MC', mc) r0tab1 = reader.read('/R0/tel_001', r0tel1) r0tab2 = reader.read('/R0/tel_002', r0tel2) # read all 3 tables in sync for ii in range(3): print("MC:", next(mctab)) print("t0:", next(r0tab1).adc_sums) print("t1:", next(r0tab2).adc_sums) print("---------------------------")
class DataContainer(Container): """ Top-level container for all event information. Each field is representing a specific data processing level from (R0 to DL2) Please keep in mind that the data level definition and the associated fields might change rapidly as there is not a final data format. The data levels R0, R1, DL1, contains sub-containers for each telescope. After DL2 the data is not processed at the telescope level. """ r0 = Field(R0Container(), "Raw Data") r1 = Field(R1Container(), "Raw Common Data") dl0 = Field(DL0Container(), "DL0 Data Volume Reduced Data") dl1 = Field(DL1Container(), "DL1 Calibrated image") dl2 = Field(ReconstructedContainer(), "Reconstructed Shower Information") mc = Field(MCEventContainer(), "Monte-Carlo data") mcheader = Field(MCHeaderContainer(), "Monte-Carlo run header data") inst = Field(InstrumentContainer(), "Instrumental information") slow_data = Field(None, "Slow Data Information") trig = Field(CentralTriggerContainer(), "central trigger information") count = Field(0, "number of events processed")