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))
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 ))
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
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
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")
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")
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))
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}')
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)))
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
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 = {}
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
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
def test_factory_incompatible_file(): with pytest.raises(ValueError): dataset = get_dataset_path("optics.ecsv.txt") EventSourceFactory.produce(input_url=dataset)
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
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
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
def test_factory_subclasses(): factory = EventSourceFactory() assert len(factory.subclass_names) > 0