Exemple #1
0
def test_h5_file(tmp_path_factory):
    """Test hdf5 file with some tables for the reader tests"""
    path = tmp_path_factory.mktemp("hdf5") / "test.h5"

    r0 = R0CameraContainer()
    shower = SimulatedShowerContainer()
    r0.waveform = np.random.uniform(size=(50, 10))
    r0.meta["test_attribute"] = 3.14159
    r0.meta["date"] = "2020-10-10"

    with HDF5TableWriter(path,
                         group_name="R0",
                         filters=tables.Filters(complevel=7)) as writer:

        for _ in range(100):
            r0.waveform[:] = np.random.uniform(size=(50, 10))
            shower.energy = 10**np.random.uniform(1, 2) * u.TeV
            shower.core_x = np.random.uniform(-1, 1) * u.m
            shower.core_y = np.random.uniform(-1, 1) * u.m

            writer.write("tel_001", r0)
            writer.write("tel_002", r0)  # write a second table too
            writer.write("sim_shower", shower)

    return path
Exemple #2
0
def test_write_container(temp_h5_file):
    r0tel = R0CameraContainer()
    simshower = SimulatedShowerContainer()
    simshower.reset()
    r0tel.waveform = np.random.uniform(size=(50, 10))
    r0tel.meta["test_attribute"] = 3.14159
    r0tel.meta["date"] = "2020-10-10"

    with HDF5TableWriter(temp_h5_file,
                         group_name="R0",
                         filters=tables.Filters(complevel=7)) as writer:

        for ii in range(100):
            r0tel.waveform[:] = np.random.uniform(size=(50, 10))
            simshower.energy = 10**np.random.uniform(1, 2) * u.TeV
            simshower.core_x = np.random.uniform(-1, 1) * u.m
            simshower.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("sim_shower", simshower)