コード例 #1
0
def test_simtel_event_source_on_gamma_test_one_event():
    with SimTelEventSource(input_url=gamma_test_path) as reader:
        assert reader.is_compatible(gamma_test_path)
        assert not reader.is_stream

        for event in reader:
            if event.count == 0:
                assert event.r0.tels_with_data == {38, 47}
            elif event.count == 1:
                assert event.r0.tels_with_data == {11, 21, 24, 26, 61, 63, 118,
                                                   119}
            else:
                break
        for event in reader:
            # Check generator has restarted from beginning
            assert event.count == 0
            break

    # test that max_events works:
    max_events = 5
    with SimTelEventSource(input_url=gamma_test_path, max_events=max_events) as reader:
        count = 0
        for _ in reader:
            count += 1
        assert count == max_events

    # test that the allowed_tels mask works:
    with pytest.warns(UserWarning):
        with SimTelEventSource(
            input_url=gamma_test_path,
            allowed_tels={3, 4}
        ) as reader:
            for event in reader:
                assert event.r0.tels_with_data.issubset(reader.allowed_tels)
コード例 #2
0
def test_true_image_sum():
    # this file does not contain true pe info
    with SimTelEventSource(
        gamma_test_large_path,
        focal_length_choice="nominal",
    ) as s:
        e = next(iter(s))
        assert np.all(np.isnan(sim.true_image_sum) for sim in e.simulation.tel.values())

    with SimTelEventSource(
        calib_events_path,
        focal_length_choice="nominal",
    ) as s:
        e = next(iter(s))

        true_image_sums = {}
        for tel_id, sim_camera in e.simulation.tel.items():
            # since the test file contains both sums and individual pixel values
            # we can compare.
            assert sim_camera.true_image_sum == sim_camera.true_image.sum()
            true_image_sums[tel_id] = sim_camera.true_image_sum

    # check it also works with allowed_tels, since the values
    # are stored in a flat array in simtel
    with SimTelEventSource(
        calib_events_path,
        allowed_tels={2, 3},
        focal_length_choice="nominal",
    ) as s:
        e = next(iter(s))
        assert e.simulation.tel[2].true_image_sum == true_image_sums[2]
        assert e.simulation.tel[3].true_image_sum == true_image_sums[3]
コード例 #3
0
def test_hessio_file_reader():
    dataset = gamma_test_path
    with SimTelEventSource(input_url=dataset) as reader:
        assert reader.is_compatible(dataset)
        assert not reader.is_stream
        for event in reader:
            if event.count == 0:
                assert event.r0.tels_with_data == {38, 47}
            elif event.count == 1:
                assert event.r0.tels_with_data == {
                    11, 21, 24, 26, 61, 63, 118, 119
                }
            else:
                break
        for event in reader:
            # Check generator has restarted from beginning
            assert event.count == 0
            break

    # test that max_events works:
    max_events = 5
    with SimTelEventSource(input_url=dataset, max_events=max_events) as reader:
        count = 0
        for _ in reader:
            count += 1
        assert count == max_events

    # test that the allowed_tels mask works:
    with SimTelEventSource(input_url=dataset, allowed_tels={3, 4}) as reader:
        for event in reader:
            assert event.r0.tels_with_data.issubset(reader.allowed_tels)
コード例 #4
0
def test_focal_length_choice():
    # this file does not contain the effective focal length
    with pytest.raises(RuntimeError):
        SimTelEventSource(gamma_test_large_path)

    with pytest.raises(RuntimeError):
        SimTelEventSource(gamma_test_large_path, focal_length_choice="effective")

    s = SimTelEventSource(gamma_test_large_path, focal_length_choice="nominal")
    assert s.subarray.tel[1].optics.equivalent_focal_length == 28 * u.m

    # this file does
    s = SimTelEventSource(prod5b_path, focal_length_choice="effective")
    assert u.isclose(
        s.subarray.tel[1].optics.equivalent_focal_length, 29.3 * u.m, atol=0.05 * u.m
    )
    # check guessing of the name is not affected by focal length choice
    assert str(s.subarray.tel[1]) == "LST_LST_LSTCam"

    s = SimTelEventSource(prod5b_path, focal_length_choice="nominal")
    assert u.isclose(
        s.subarray.tel[1].optics.equivalent_focal_length, 28.0 * u.m, atol=0.05 * u.m
    )
    # check guessing of the name is not affected by focal length choice
    assert str(s.subarray.tel[1]) == "LST_LST_LSTCam"
コード例 #5
0
def test_effective_focal_length():
    test_file_url = (
        "https://github.com/cta-observatory/pyeventio/raw/master/tests"
        "/resources/prod4_pixelsettings_v3.gz"
    )
    test_file = download_file(test_file_url)

    focal_length_nominal = 0
    focal_length_effective = 0

    with SimTelEventSource(
        input_url=test_file, focal_length_choice="nominal"
    ) as source:
        subarray = source.subarray
        focal_length_nominal = subarray.tel[1].optics.equivalent_focal_length

    with SimTelEventSource(
        input_url=test_file, focal_length_choice="effective"
    ) as source:
        subarray = source.subarray
        focal_length_effective = subarray.tel[1].optics.equivalent_focal_length

    assert focal_length_nominal > 0
    assert focal_length_effective > 0
    assert focal_length_nominal != focal_length_effective
コード例 #6
0
def test_simtel_event_source_on_gamma_test_one_event():
    with SimTelEventSource(input_url=gamma_test_large_path) as reader:
        assert reader.is_compatible(gamma_test_large_path)
        assert not reader.is_stream

        for event in reader:
            if event.count > 1:
                break

        for event in reader:
            # Check generator has restarted from beginning
            assert event.count == 0
            break

    # test that max_events works:
    max_events = 5
    with SimTelEventSource(input_url=gamma_test_large_path,
                           max_events=max_events) as reader:
        count = 0
        for _ in reader:
            count += 1
        assert count == max_events

    # test that the allowed_tels mask works:
    with SimTelEventSource(input_url=gamma_test_large_path,
                           allowed_tels={3, 4}) as reader:
        for event in reader:
            assert event.r0.tels_with_data.issubset(reader.allowed_tels)
コード例 #7
0
def test_additional_meta_data_from_mc_header():
    with SimTelEventSource(input_url=gamma_test_path) as reader:
        data = next(iter(reader))

    # for expectation values
    from astropy import units as u
    from astropy.coordinates import Angle

    assert data.mcheader.corsika_version == 6990
    assert data.mcheader.simtel_version == 1404919891
    assert data.mcheader.spectral_index == -2.0

    name_expectation = {
        'energy_range_min': u.Quantity(3.0e-03, u.TeV),
        'energy_range_max': u.Quantity(3.3e+02, u.TeV),
        'prod_site_B_total': u.Quantity(27.181243896484375, u.uT),
        'prod_site_B_declination': Angle(0.0 * u.rad),
        'prod_site_B_inclination': Angle(-1.1581752300262451 * u.rad),
        'prod_site_alt': 1640.0 * u.m,
    }

    for name, expectation in name_expectation.items():
        value = getattr(data.mcheader, name)

        assert value.unit == expectation.unit
        assert np.isclose(
            value.to_value(expectation.unit),
            expectation.to_value(expectation.unit)
        )
コード例 #8
0
def test_calibration_events():
    from ctapipe.containers import EventType

    # this test file as two of each of these types
    expected_types = [
        EventType.DARK_PEDESTAL,
        EventType.DARK_PEDESTAL,
        EventType.SKY_PEDESTAL,
        EventType.SKY_PEDESTAL,
        EventType.SINGLE_PE,
        EventType.SINGLE_PE,
        EventType.FLATFIELD,
        EventType.FLATFIELD,
        EventType.SUBARRAY,
        EventType.SUBARRAY,
    ]

    expected_ids = [-1, -2, -3, -4, -5, -6, -7, -8, 100, 200]
    with SimTelEventSource(
        input_url=calib_events_path,
        skip_calibration_events=False,
        focal_length_choice="nominal",
    ) as reader:
        for event, expected_type, expected_id in zip_longest(
            reader, expected_types, expected_ids
        ):
            assert event.trigger.event_type is expected_type
            assert event.index.event_id == expected_id
コード例 #9
0
def test_properties():
    source = SimTelEventSource(input_url=gamma_test_large_path)

    assert source.is_simulation
    assert source.simulation_config.corsika_version == 6990
    assert source.datalevels == (DataLevel.R0, DataLevel.R1)
    assert source.obs_ids == [7514]
コード例 #10
0
def test_calibration_events():
    with SimTelEventSource(
            input_url=calib_events_path,
            skip_calibration_events=False,
    ) as reader:
        for e in reader:
            pass
コード例 #11
0
def test_properties():
    source = SimTelEventSource(input_url=gamma_test_large_path)

    assert source.is_simulation
    assert source.mc_header.corsika_version == 6990
    assert source.datalevels == (DataLevel.R0, DataLevel.R1, DataLevel.DL0)
    assert source.obs_id == 7514
コード例 #12
0
def test_instrument():
    """Test if same telescope types share a single instance of CameraGeometry"""
    source = SimTelEventSource(
        input_url=gamma_test_large_path,
        focal_length_choice="nominal",
    )
    subarray = source.subarray
    assert subarray.tel[1].optics.num_mirrors == 1
コード例 #13
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = SimTelEventSource(parent=self)

        self.calibrator = CameraCalibrator(parent=self,
                                           subarray=self.eventsource.subarray)
        self.calculator = ChargeResolutionCalculator()
コード例 #14
0
def test_max_events():
    max_events = 5
    with SimTelEventSource(input_url=gamma_test_path,
                           max_events=max_events) as reader:
        count = 0
        for _ in reader:
            count += 1
        assert count == max_events
コード例 #15
0
def test_subarray_property():
    source = SimTelEventSource(input_url=gamma_test_large_path)
    subarray = deepcopy(source.subarray)
    event = next(iter(source))
    subarray_event = event.inst.subarray
    assert subarray.tel.keys() == subarray_event.tel.keys()
    assert (subarray.tel[1].camera.geometry.pix_x ==
            subarray_event.tel[1].camera.geometry.pix_x).all()
コード例 #16
0
def test_true_image():
    with SimTelEventSource(
        input_url=calib_events_path,
        focal_length_choice="nominal",
    ) as reader:

        for event in reader:
            for tel in event.simulation.tel.values():
                assert np.count_nonzero(tel.true_image) > 0
コード例 #17
0
def test_extracted_calibevents():
    with SimTelEventSource("dataset://extracted_pedestals.simtel.zst") as s:
        i = 0
        for e in s:
            i = e.count
            # these events are simulated but do not have shower information
            assert e.simulation is not None
            assert e.simulation.shower is None
        assert i == 4
コード例 #18
0
def test_eventio_prod2():
    with pytest.warns(UnknownPixelShapeWarning):
        with SimTelEventSource(
                input_url=dataset,
                focal_length_choice='nominal',
        ) as reader:
            for event in reader:
                if event.count == 2:
                    break
コード例 #19
0
def test_properties():
    source = SimTelEventSource(
        input_url=gamma_test_large_path,
        focal_length_choice="nominal",
    )

    assert source.is_simulation
    assert source.datalevels == (DataLevel.R0, DataLevel.R1)
    assert source.obs_ids == [7514]
    assert source.simulation_config[7514].corsika_version == 6990
コード例 #20
0
def test_simtel_event_source_on_gamma_test_one_event():
    assert SimTelEventSource.is_compatible(gamma_test_large_path)

    with SimTelEventSource(
        input_url=gamma_test_large_path,
        back_seekable=True,
        focal_length_choice="nominal",
    ) as reader:
        assert not reader.is_stream

        for event in reader:
            if event.count > 1:
                break

        with pytest.warns(UserWarning):
            for event in reader:
                # Check generator has restarted from beginning
                assert event.count == 0
                break
コード例 #21
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = self.add_component(SimTelEventSource(parent=self))

        extractor = self.add_component(
            ImageExtractor.from_name(self.extractor_product, parent=self))

        self.calibrator = self.add_component(
            CameraCalibrator(parent=self, image_extractor=extractor))
        self.calculator = ChargeResolutionCalculator()
コード例 #22
0
def test_trigger_times():

    source = SimTelEventSource(input_url=calib_events_path)
    t0 = Time("2020-05-06T15:30:00")
    t1 = Time("2020-05-06T15:40:00")

    for event in source:
        assert t0 <= event.trigger.time <= t1
        for tel_id, trigger in event.trigger.tel.items():
            # test single telescope events triggered within 50 ns
            assert 0 <= (trigger.time - event.trigger.time).to_value(u.ns) <= 50
コード例 #23
0
def test_max_events():
    max_events = 5
    with SimTelEventSource(
        input_url=gamma_test_large_path,
        max_events=max_events,
        focal_length_choice="nominal",
    ) as reader:
        count = 0
        for _ in reader:
            count += 1
        assert count == max_events
コード例 #24
0
def test_allowed_telescopes():
    # test that the allowed_tels mask works:
    allowed_tels = {3, 4}
    with SimTelEventSource(input_url=gamma_test_large_path,
                           allowed_tels=allowed_tels) as reader:
        assert not allowed_tels.symmetric_difference(reader.subarray.tel_ids)
        for event in reader:
            assert set(event.r0.tel).issubset(allowed_tels)
            assert set(event.r1.tel).issubset(allowed_tels)
            assert set(event.dl0.tel).issubset(allowed_tels)
            assert set(event.trigger.tels_with_trigger).issubset(allowed_tels)
            assert set(event.pointing.tel).issubset(allowed_tels)
コード例 #25
0
def test_pointing():
    with SimTelEventSource(input_url=gamma_test_large_path, max_events=3) as reader:
        for e in reader:
            assert np.isclose(e.pointing.array_altitude.to_value(u.deg), 70)
            assert np.isclose(e.pointing.array_azimuth.to_value(u.deg), 0)
            assert np.isnan(e.pointing.array_ra)
            assert np.isnan(e.pointing.array_dec)

            # normal run, alle telescopes point to the array direction
            for pointing in e.pointing.tel.values():
                assert u.isclose(e.pointing.array_azimuth, pointing.azimuth)
                assert u.isclose(e.pointing.array_altitude, pointing.altitude)
コード例 #26
0
def compare_sources(input_url):
    kwargs = dict(config=None, tool=None, input_url=input_url)

    with SimTelEventSource(**kwargs) as simtel_source, \
            HESSIOEventSource(**kwargs) as hessio_source:

        for s, h in zip_longest(simtel_source, hessio_source):

            assert s is not None
            assert h is not None

            assert h.count == s.count
            assert h.r0.obs_id == s.r0.obs_id
            assert h.r0.event_id == s.r0.event_id
            assert h.r0.tels_with_data == s.r0.tels_with_data

            assert (h.trig.tels_with_trigger == s.trig.tels_with_trigger).all()
            assert h.trig.gps_time == s.trig.gps_time

            assert h.mc.energy == s.mc.energy
            assert h.mc.alt == s.mc.alt
            assert h.mc.az == s.mc.az
            assert h.mc.core_x == s.mc.core_x
            assert h.mc.core_y == s.mc.core_y

            assert h.mc.h_first_int == s.mc.h_first_int
            assert h.mc.x_max == s.mc.x_max
            assert h.mc.shower_primary_id == s.mc.shower_primary_id
            assert (h.mcheader.run_array_direction == s.mcheader.run_array_direction).all()

            tels_with_data = s.r0.tels_with_data
            for tel_id in tels_with_data:

                assert h.mc.tel[tel_id].reference_pulse_shape.dtype == s.mc.tel[tel_id].reference_pulse_shape.dtype
                assert type(h.mc.tel[tel_id].meta['refstep']) is type(s.mc.tel[tel_id].meta['refstep'])
                assert type(h.mc.tel[tel_id].time_slice) is type(s.mc.tel[tel_id].time_slice)

                assert (h.mc.tel[tel_id].dc_to_pe == s.mc.tel[tel_id].dc_to_pe).all()
                assert (h.mc.tel[tel_id].pedestal == s.mc.tel[tel_id].pedestal).all()
                assert h.r0.tel[tel_id].waveform.shape == s.r0.tel[tel_id].waveform.shape
                assert np.allclose(h.r0.tel[tel_id].waveform, s.r0.tel[tel_id].waveform)
                assert (h.r0.tel[tel_id].num_samples == s.r0.tel[tel_id].num_samples)
                assert (h.r0.tel[tel_id].image == s.r0.tel[tel_id].image).all()

                assert h.r0.tel[tel_id].num_trig_pix == s.r0.tel[tel_id].num_trig_pix
                assert (h.r0.tel[tel_id].trig_pix_id == s.r0.tel[tel_id].trig_pix_id).all()
                assert (h.mc.tel[tel_id].reference_pulse_shape == s.mc.tel[tel_id].reference_pulse_shape).all()

                assert (h.mc.tel[tel_id].photo_electron_image == s.mc.tel[tel_id].photo_electron_image).all()
                assert h.mc.tel[tel_id].meta == s.mc.tel[tel_id].meta
                assert h.mc.tel[tel_id].time_slice == s.mc.tel[tel_id].time_slice
                assert h.mc.tel[tel_id].azimuth_raw == s.mc.tel[tel_id].azimuth_raw
                assert h.mc.tel[tel_id].altitude_raw == s.mc.tel[tel_id].altitude_raw
コード例 #27
0
def test_that_event_is_not_modified_after_loop():

    dataset = gamma_test_large_path
    with SimTelEventSource(input_url=dataset, max_events=2) as source:
        for event in source:
            last_event = copy.deepcopy(event)

        # now `event` should be identical with the deepcopy of itself from
        # inside the loop.
        # Unfortunately this does not work:
        #      assert last_event == event
        # So for the moment we just compare event ids
        assert event.r0.event_id == last_event.r0.event_id
コード例 #28
0
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = SimTelEventSource(parent=self)

        extractor = ImageExtractor.from_name(self.extractor_product,
                                             parent=self)

        self.dl0 = CameraDL0Reducer(parent=self)

        self.dl1 = CameraDL1Calibrator(extractor=extractor, parent=self)

        self.calculator = ChargeResolutionCalculator()
コード例 #29
0
def test_allowed_telescopes():
    # test that the allowed_tels mask works:
    allowed_tels = {3, 4}
    with SimTelEventSource(input_url=gamma_test_large_path,
                           allowed_tels=allowed_tels) as reader:

        for event in reader:
            assert set(event.r0.tel).issubset(allowed_tels)
            assert set(event.r1.tel).issubset(allowed_tels)
            assert set(event.dl0.tel).issubset(allowed_tels)

    # test that updating the allowed_tels mask works
    new_allowed_tels = {1, 2}
    with SimTelEventSource(input_url=gamma_test_large_path,
                           allowed_tels=allowed_tels) as reader:

        # change allowed_tels after __init__
        reader.allowed_tels = new_allowed_tels
        for event in reader:
            assert set(event.r0.tel).issubset(new_allowed_tels)
            assert set(event.r1.tel).issubset(new_allowed_tels)
            assert set(event.dl0.tel).issubset(new_allowed_tels)
コード例 #30
0
def test_calibscale_and_calibshift(prod5_gamma_simtel_path):

    telid = 25

    with SimTelEventSource(input_url=prod5_gamma_simtel_path,
                           max_events=1) as source:

        for event in source:
            pass

    calib_scale = 2.0

    with SimTelEventSource(input_url=prod5_gamma_simtel_path,
                           max_events=1,
                           calib_scale=calib_scale) as source:

        for event_scaled in source:
            pass

    np.testing.assert_allclose(
        event.r1.tel[telid].waveform[0],
        event_scaled.r1.tel[telid].waveform[0] / calib_scale,
        rtol=0.1,
    )

    calib_shift = 2.0  # p.e.

    with SimTelEventSource(input_url=prod5_gamma_simtel_path,
                           max_events=1,
                           calib_shift=calib_shift) as source:

        for event_shifted in source:
            pass

    np.testing.assert_allclose(
        event.r1.tel[telid].waveform[0],
        event_shifted.r1.tel[telid].waveform[0] - calib_shift,
        rtol=0.1,
    )