コード例 #1
0
    def setup(self):
        self.log.info('Configure EventSourceFactory...')

        self.event_source = EventSourceFactory.produce(
            config=self.config, tool=self, product='HESSIOEventSource')
        self.event_source.allowed_tels = self.config['Analysis'][
            'allowed_tels']

        self.calibrator = CameraCalibrator(config=self.config,
                                           tool=self,
                                           eventsource=self.event_source)

        self.writer = HDF5TableWriter(filename=self.outfile,
                                      group_name='image_infos',
                                      overwrite=True)

        # Define Pre-selection for images
        preselcuts = self.config['Preselect']
        self.image_cutflow = CutFlow('Image preselection')
        self.image_cutflow.set_cuts(
            dict(no_sel=None,
                 n_pixel=lambda s: np.count_nonzero(s) < preselcuts['n_pixel'][
                     'min'],
                 image_amplitude=lambda q: q < preselcuts['image_amplitude'][
                     'min']))

        # Define Pre-selection for events
        self.event_cutflow = CutFlow('Event preselection')
        self.event_cutflow.set_cuts(dict(no_sel=None))
コード例 #2
0
    def setup(self):
        self.log.info('Configure EventSourceFactory...')

        self.event_source = EventSourceFactory.produce(
            config=self.config, tool=self, product='SimTelEventSource'
        )
        self.event_source.allowed_tels = self.config['Analysis']['allowed_tels']

        self.calibrator = CameraCalibrator(
            config=self.config, tool=self, eventsource=self.event_source
        )

        self.writer = HDF5TableWriter(
            filename=self.outfile, group_name='image_infos', overwrite=True
        )

        # Define Pre-selection for images
        preselcuts = self.config['Preselect']
        self.image_cutflow = CutFlow('Image preselection')
        self.image_cutflow.set_cuts(dict(
            no_sel=None,
            n_pixel=lambda s: np.count_nonzero(s) < preselcuts['n_pixel']['min'],
            image_amplitude=lambda q: q < preselcuts['image_amplitude']['min']
        ))

        # Define Pre-selection for events
        self.event_cutflow = CutFlow('Event preselection')
        self.event_cutflow.set_cuts(dict(
            no_sel=None
        ))
コード例 #3
0
def test_factory_unknown_reader():
    with pytest.raises(TraitError):
        dataset = get_dataset_path("gamma_test.simtel.gz")
        reader = EventSourceFactory.produce(
            product='UnknownFileReader',
            input_url=dataset
        )
        assert reader is not None
コード例 #4
0
def test_factory_from_reader():
    dataset = get_dataset_path("gamma_test.simtel.gz")
    reader = EventSourceFactory.produce(
        product='SimTelEventSource',
        input_url=dataset
    )
    assert reader.__class__.__name__ == "SimTelEventSource"
    assert reader.input_url == dataset
コード例 #5
0
 def setup(self):
     if self.events == '':
         raise ToolConfigurationError("please specify --input <events file>")
     self.log.debug("input: %s", self.events)
     self.source = EventSourceFactory.produce(input_url=self.events)
     self.calib = CameraCalibrator(
         config=self.config, tool=self, eventsource=self.source
     )
     self.writer = HDF5TableWriter(self.outfile, "muons")
コード例 #6
0
 def setup(self):
     if self.events == '':
         raise ToolConfigurationError(
             "please specify --input <events file>")
     self.log.debug("input: %s", self.events)
     self.source = EventSourceFactory.produce(input_url=self.events)
     self.calib = CameraCalibrator(config=self.config,
                                   tool=self,
                                   eventsource=self.source)
     self.writer = HDF5TableWriter(self.outfile, "muons")
コード例 #7
0
    def setup(self):

        self.event_source = EventSourceFactory.produce(config=self.config,
                                                       tool=self)
        self.event_source.allowed_tels = [
            self.tel,
        ]

        self.calibrator = CameraCalibrator(config=self.config,
                                           tool=self,
                                           eventsource=self.event_source)

        self.log.info('SELECTING EVENTS FROM TELESCOPE {}'.format(self.tel))
コード例 #8
0
    def setup(self):

        self.event_source = EventSourceFactory.produce(
            config=self.config, tool=self
        )
        self.event_source.allowed_tels = [
            self.tel,
        ]

        self.calibrator = CameraCalibrator(
            config=self.config, tool=self, eventsource=self.event_source
        )

        self.log.info(f'SELECTING EVENTS FROM TELESCOPE {self.tel}')
コード例 #9
0
ファイル: LoadCTAFile.py プロジェクト: SKellerML/MAGICML
    def loadFile(self, path):
        event_factory = EventSourceFactory.produce(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)))
コード例 #10
0
def test_factory_from_reader():
    dataset = get_dataset_path("gamma_test.simtel.gz")
    reader = EventSourceFactory.produce(product='SimTelEventSource',
                                        input_url=dataset)
    assert reader.__class__.__name__ == "SimTelEventSource"
    assert reader.input_url == dataset
コード例 #11
0
import matplotlib.pyplot as plt
from ctapipe.visualization import ArrayDisplay


# unoptimized cleaning levels, copied from
# https://github.com/tudo-astroparticlephysics/cta_preprocessing
cleaning_level = {
    'LSTCam': (3.5, 7.5, 2),  # ?? (3, 6) for Abelardo...
    'FlashCam': (4, 8, 2),  # there is some scaling missing?
    'ASTRICam': (5, 7, 2),
}


input_url = get_dataset_path('gamma_test_large.simtel.gz')
event_source = EventSourceFactory.produce(input_url=input_url)

calibrator = CameraCalibrator(
    eventsource=event_source,
)

reco = HillasReconstructor()

for event in event_source:
    print('Event', event.count)
    calibrator.calibrate(event)

    # mapping of telescope_id to parameters for stereo reconstruction
    hillas_containers = {}
    pointing_azimuth = {}
    pointing_altitude = {}
コード例 #12
0
def test_factory_incorrect_use():
    with pytest.raises(FileNotFoundError):
        dataset = get_dataset_path("gamma_test_large.simtel.gz")
        factory = EventSourceFactory(input_url=dataset)
        reader = factory.produce()
        assert reader is not None
コード例 #13
0
def test_factory_nonexistant_file():
    with pytest.raises(FileNotFoundError):
        dataset = "/fake_path/fake_file.fake_extension"
        reader = EventSourceFactory.produce(input_url=dataset)
        assert reader is not None
コード例 #14
0
def test_factory_incompatible_file():
    with pytest.raises(ValueError):
        dataset = get_dataset_path("optics.ecsv.txt")
        EventSourceFactory.produce(input_url=dataset)
コード例 #15
0
def test_factory_unknown_file_format():
    with pytest.raises(ValueError):
        dataset = get_dataset_path("optics.ecsv.txt")
        reader = EventSourceFactory.produce(input_url=dataset)
        assert reader is not None
コード例 #16
0
def test_factory_different_file():
    dataset = get_dataset_path("gamma_test_large.simtel.gz")
    reader = EventSourceFactory.produce(input_url=dataset)
    assert reader.__class__.__name__ == "SimTelEventSource"
    assert reader.input_url == dataset
コード例 #17
0
def test_factory_unknown_reader():
    with pytest.raises(TraitError):
        dataset = get_dataset_path("gamma_test.simtel.gz")
        reader = EventSourceFactory.produce(product='UnknownFileReader',
                                            input_url=dataset)
        assert reader is not None
コード例 #18
0
def test_factory_different_file():
    dataset = get_dataset_path("gamma_test_large.simtel.gz")
    reader = EventSourceFactory.produce(input_url=dataset)
    assert reader.__class__.__name__ == "SimTelEventSource"
    assert reader.input_url == dataset
コード例 #19
0
def test_factory_subclasses():
    factory = EventSourceFactory()
    assert len(factory.subclass_names) > 0
コード例 #20
0
def test_factory_incorrect_use():
    with pytest.raises(FileNotFoundError):
        dataset = get_dataset_path("gamma_test_large.simtel.gz")
        factory = EventSourceFactory(input_url=dataset)
        reader = factory.produce()
        assert reader is not None
コード例 #21
0
def test_factory_nonexistant_file():
    with pytest.raises(FileNotFoundError):
        dataset = "/fake_path/fake_file.fake_extension"
        reader = EventSourceFactory.produce(input_url=dataset)
        assert reader is not None
コード例 #22
0
def test_factory_unknown_file_format():
    with pytest.raises(ValueError):
        dataset = get_dataset_path("optics.ecsv.txt")
        reader = EventSourceFactory.produce(input_url=dataset)
        assert reader is not None
コード例 #23
0
def test_factory_incompatible_file():
    with pytest.raises(ValueError):
        dataset = get_dataset_path("optics.ecsv.txt")
        EventSourceFactory.produce(input_url=dataset)