コード例 #1
0
def test_read_telescope_events_by_type(test_file_dl2):
    """Test reading telescope events for by types"""

    from ctapipe.io.tableloader import TableLoader

    _, dl2_file = test_file_dl2

    with TableLoader(
            dl2_file,
            load_dl1_images=False,
            load_dl1_parameters=False,
            load_dl2=True,
            load_simulated=True,
            load_true_images=True,
            load_trigger=False,
            load_instrument=True,
    ) as table_loader:

        tables = table_loader.read_telescope_events_by_type([25, 130])

        for tel_type in ["MST_MST_NectarCam", "MST_MST_FlashCam"]:

            table = tables[tel_type]

            assert "HillasReconstructor_alt" in table.colnames
            assert "true_energy" in table.colnames
            assert "true_image" in table.colnames
            assert set(table["tel_id"].data).issubset([25, 125, 130])
            assert "equivalent_focal_length" in table.colnames
コード例 #2
0
def test_h5file(test_file_dl2):
    """Test we can also pass an already open h5file"""
    from ctapipe.io.tableloader import TableLoader

    _, dl2_file = test_file_dl2

    # no input raises error
    with pytest.raises(ValueError):
        with TableLoader():
            pass

    # test we can use an already open file
    with tables.open_file(dl2_file, mode="r+") as h5file:
        with TableLoader(h5file=h5file) as loader:
            assert 25 in loader.subarray.tel
            loader.read_subarray_events()
            loader.read_telescope_events()
コード例 #3
0
def test_true_images(test_file):
    """Test joining true images onto telescope events"""
    from ctapipe.io.tableloader import TableLoader

    _, dl1_file = test_file

    with TableLoader(dl1_file,
                     load_dl1_parameters=False,
                     load_true_images=True) as table_loader:
        table = table_loader.read_telescope_events(["MST_MST_NectarCam"])
        assert "true_image" in table.colnames
コード例 #4
0
def test_load_instrument(test_file):
    """Test joining instrument data onto telescope events"""
    from ctapipe.io.tableloader import TableLoader

    _, dl1_file = test_file

    with TableLoader(dl1_file, load_instrument=True) as table_loader:
        expected = table_loader.subarray.tel[25].optics.equivalent_focal_length
        table = table_loader.read_telescope_events([25])
        assert "equivalent_focal_length" in table.colnames
        assert np.all(table["equivalent_focal_length"] == expected)
コード例 #5
0
def test_true_parameters(test_file):
    """Test joining true parameters onto telescope events"""
    from ctapipe.io.tableloader import TableLoader

    _, dl1_file = test_file

    with TableLoader(dl1_file,
                     load_dl1_parameters=False,
                     load_true_parameters=True) as table_loader:
        table = table_loader.read_telescope_events()
        assert "true_hillas_intensity" in table.colnames
コード例 #6
0
def test_load_simulated(test_file):
    """Test joining simulation info onto telescope events"""
    from ctapipe.io.tableloader import TableLoader

    _, dl1_file = test_file

    with TableLoader(dl1_file, load_simulated=True) as table_loader:
        table = table_loader.read_subarray_events()
        assert "true_energy" in table.colnames

        table = table_loader.read_telescope_events([25])
        assert "true_energy" in table.colnames
コード例 #7
0
def test_telescope_events_for_tel_id(test_file):
    """Test loading data for a single telescope"""
    from ctapipe.io.tableloader import TableLoader

    _, dl1_file = test_file

    loader = TableLoader(dl1_file, load_dl1_parameters=True, load_trigger=True)

    with loader as table_loader:
        table = table_loader.read_telescope_events([25])
        assert "hillas_length" in table.colnames
        assert "time" in table.colnames
        assert "event_type" in table.colnames
        assert np.all(table["tel_id"] == 25)

    with TableLoader(dl1_file, load_dl1_images=True) as table_loader:
        table = table_loader.read_telescope_events([25])
        assert "image" in table.colnames
        assert np.all(table["tel_id"] == 25)

    assert not table_loader.h5file.isopen
コード例 #8
0
def test_read_subarray_events(test_file_dl2):
    """Test reading subarray events"""

    from ctapipe.io.tableloader import TableLoader

    _, dl2_file = test_file_dl2

    with TableLoader(dl2_file,
                     load_dl2=True,
                     load_simulated=True,
                     load_trigger=True) as table_loader:
        table = table_loader.read_subarray_events()
        assert "HillasReconstructor_alt" in table.colnames
        assert "true_energy" in table.colnames
        assert "time" in table.colnames