Ejemplo n.º 1
0
def test_compatible():
    m1_dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    m2_dataset = get_dataset_path(
        "20131004_M2_05029747.003_Y_MagicCrab-W0.40+035.root")
    assert MAGICEventSource.is_compatible(m1_dataset)
    assert MAGICEventSource.is_compatible(m2_dataset)
Ejemplo n.º 2
0
def test_run_info(dataset):
    from ctapipe_io_magic import MAGICEventSource

    with MAGICEventSource(input_url=dataset) as source:
        run_info = MAGICEventSource.get_run_info_from_name(str(source.input_url))
        run_number = run_info[0]
        is_mc = run_info[1]
        telescope = run_info[2]
        datalevel = run_info[3]
        assert run_number == source.run_numbers
        assert run_number == source.obs_ids[0]
        assert is_mc == source.is_simulation
        assert telescope == source.telescope
        assert datalevel == source.mars_datalevel
Ejemplo n.º 3
0
def test_loop_pedestal(dataset):
    from ctapipe_io_magic import MAGICEventSource
    from ctapipe.containers import EventType
    n_events = 10
    with MAGICEventSource(input_url=dataset, max_events=n_events, use_pedestals=True) as source:
        for event in source:
            assert event.trigger.event_type == EventType.SKY_PEDESTAL
Ejemplo n.º 4
0
def test_geom():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')

    with MAGICEventSource(input_url=dataset) as source:
        event = next(source._generator())
        assert source.subarray.tels[1].camera.pix_x.size == 1039
        assert source.subarray.tels[2].camera.pix_x.size == 1039
Ejemplo n.º 5
0
def test_number_of_events(dataset):
    from ctapipe_io_magic import MAGICEventSource

    with MAGICEventSource(input_url=dataset) as source:
        run = source._set_active_run(run_number=source.run_numbers)
        if '_M1_' in dataset.name:
            assert run['data'].n_cosmics_stereo_events_m1 == data_dict[source.input_url.name]['n_events_stereo']
            assert run['data'].n_pedestal_events_m1 == data_dict[source.input_url.name]['n_events_pedestal']
        if '_M2_' in dataset.name:
            assert run['data'].n_cosmics_stereo_events_m2 == data_dict[source.input_url.name]['n_events_stereo']
            assert run['data'].n_pedestal_events_m2 == data_dict[source.input_url.name]['n_events_pedestal']
Ejemplo n.º 6
0
def test_eventcontent():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')

    with MAGICEventSource(input_url=dataset) as source:
        seeker = EventSeeker(source)
        event = seeker[0]
        assert event.dl1.tel[1].image[0] == -0.53125
        assert event.dl1.tel[2].image[0] == 2.2265625
        assert event.dl1.tel[1].pulse_time[0] == 49.125
        assert event.dl1.tel[2].pulse_time[0] == 23.5625
Ejemplo n.º 7
0
    def loadFilesWithMask(self):
        # Use masks? path = "/remote/ceph/group/magic/MAGIC-LST/MARS/CrabNebula/CalibratedWithPointings/2018_03_09/*05070968*00[1-2]*root"

        mask = self.filepath + self.loadFileName_start + "*" + self.loadFileName_end
        # Might need to change this line to work?
        event_factory = MAGICEventSource(input_url=path)
        event_factory.allowed_tels = self.telescopes  # {1, 2}
        event_generator = event_factory._generator()
        # event = next(event_generator)

        for s_event in event_generator:
            # Use event only if M1 and M2 are triggered

            # if 1 in s_event.r0.tels_with_data and 1 in self.telescopes and 2 in s_event.r0.tels_with_data:
            if self.telescopes <= s_event.r0.tels_with_data:
                self.calibrator.calibrate(s_event)
                # print("Oder num: {:d}, event id: {:.0f}, triggered telescopes: {}".format(stereo_event.count, stereo_event.r0.event_id, stereo_event.r0.tels_with_data))
                a = copy.deepcopy(s_event)
                self.eventList.append(a)
        # event_factory.pyhessio.close_file()
        print("New File loaded, file {:d} contains {:d} events".format(
            self.currentFileID, len(self.eventList)))
Ejemplo n.º 8
0
def test_len():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')

    with MAGICEventSource(input_url=dataset) as source:
        count = 0
        for _ in source:
            count += 1

        # assert count == len(source)
        n_stereo_events = source.current_run['data'].n_stereo_events
        assert count == n_stereo_events
Ejemplo n.º 9
0
def test_that_event_is_not_modified_after_loop(dataset):
    from ctapipe_io_magic import MAGICEventSource
    n_events = 10
    with MAGICEventSource(input_url=dataset, max_events=n_events) 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.index.event_id == last_event.index.event_id
Ejemplo n.º 10
0
def test_eventseeker():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')

    with MAGICEventSource(input_url=dataset) as source:
        seeker = EventSeeker(source)
        event = seeker[0]
        assert event.count == 0
        assert event.dl0.event_id == 29795

        event = seeker[2]
        assert event.count == 2
        assert event.r1.event_id == 29798
Ejemplo n.º 11
0
def test_loop():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')
    with MAGICEventSource(input_url=dataset) as source:
        count = 0
        for event in source:
            assert event.r0.tels_with_data == {1, 2}
            assert event.count == count
            count += 1

        for event in source:
            # Check generator has restarted from beginning
            assert event.count == 0
            break
Ejemplo n.º 12
0
def test_that_event_is_not_modified_after_loop():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    dataset = dataset.replace('_M1_', '_M*_')

    # with MAGICEventSource(input_url=dataset, max_events=3) as source:
    with MAGICEventSource(input_url=dataset) 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
Ejemplo n.º 13
0
def test_loop(dataset):
    from ctapipe_io_magic import MAGICEventSource
    n_events = 10
    with MAGICEventSource(input_url=dataset, max_events=n_events) as source:
        for i, event in enumerate(source):
            assert event.count == i
            if "_M1_" in dataset.name:
                assert event.trigger.tels_with_trigger == [1]
            if "_M2_" in dataset.name:
                assert event.trigger.tels_with_trigger == [2]

        assert (i + 1) == n_events

        for event in source:
            # Check generator has restarted from beginning
            assert event.count == 0
            break
Ejemplo n.º 14
0
    def loadFile(self, path):
        # Use masks? path = "/remote/ceph/group/magic/MAGIC-LST/MARS/CrabNebula/CalibratedWithPointings/2018_03_09/*05070968*00[1-2]*root"

        # might need to change this line to work?
        #try:
        if True:
            if self.load_option == LoadOption.raw_sim or self.load_option == LoadOption.raw_data:
                event_factory = event_source(input_url=path)
                event_factory.allowed_tels = self.telescopes  #{1, 2}
                event_generator = event_factory._generator()
                if self.pedestals_only:
                    print(
                        "Warning: Pedestals only available for real data, not for simulation data."
                    )

            elif self.load_option == LoadOption.cal_sim or self.load_option == LoadOption.cal_data:
                #event_factory.allowed_tels = self.telescopes #{1, 2}
                if self.pedestals_only:
                    event_factory = MAGICEventSource(input_url=path)
                    pedestal_event_generator1 = event_factory._pedestal_event_generator(
                        telescope='M1')
                    pedestal_event_generator2 = event_factory._pedestal_event_generator(
                        telescope='M2')
                else:
                    event_factory = MAGICEventSource(input_url=path)
                    event_generator = event_factory._generator()

        else:  #except Exception as e:
            print("Error 194: File does not exist: " + path + " or ")
            print("Error: %s" % str(e))
            return False
        # event = next(event_generator)
        if self.pedestals_only:
            ped_available = True
            while ped_available:
                try:
                    p1 = next(pedestal_event_generator1, None)
                    p2 = next(pedestal_event_generator2, None)
                except:
                    print("Errror:")
                    p1 = None
                    p2 = None

                if p1 is None or p2 is None:
                    ped_available = False
                else:
                    a1 = copy.deepcopy(p1)
                    a2 = copy.deepcopy(p2)
                    self.eventList.append({1: a1, 2: a2})
        else:
            for s_event in event_generator:
                # Use event only if M1 and M2 are triggered
                #if 1 in s_event.r0.tels_with_data and 1 in self.telescopes and 2 in s_event.r0.tels_with_data:
                if self.telescopes <= s_event.r0.tels_with_data:
                    if self.calibrate:
                        self.calibrator(s_event)
                    # print("Oder num: {:d}, event id: {:.0f}, triggered telescopes: {}".format(stereo_event.count, stereo_event.r0.event_id, stereo_event.r0.tels_with_data))
                    a = copy.deepcopy(s_event)
                    if not self.use_cut or apply_cut(a, self.cut_value,
                                                     self.load_option):
                        self.eventList.append(a)
                        #print("Accepted. ",len(self.eventList))

        #event_factory.pyhessio.close_file()
        print("New File loaded, file {:d} contains {:d} events".format(
            14, len(self.eventList)))
        return True
Ejemplo n.º 15
0
def test_stream(dataset):
    from ctapipe_io_magic import MAGICEventSource
    with MAGICEventSource(input_url=dataset) as source:
        assert not source.is_stream
Ejemplo n.º 16
0
def test_compatible(dataset):
    from ctapipe_io_magic import MAGICEventSource
    assert MAGICEventSource.is_compatible(dataset)
Ejemplo n.º 17
0
def test_geom(dataset):
    from ctapipe_io_magic import MAGICEventSource

    with MAGICEventSource(input_url=dataset) as source:
        assert source.subarray.tels[1].camera.geometry.pix_x.size == 1039
        assert source.subarray.tels[2].camera.geometry.pix_x.size == 1039
Ejemplo n.º 18
0
def test_stream():
    dataset = get_dataset_path(
        "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root")
    with MAGICEventSource(input_url=dataset) as source:
        assert not source.is_stream