def test_eventseeker(): dataset = get_dataset_path("chec_r1.tio") with TargetIOEventSource(input_url=dataset) as source: seeker = EventSeeker(source) event = seeker[0] assert source._event_index == 0 assert source._event_id == 2 assert event.count == 0 assert event.r1.event_id == 2 assert (round(source._r1_samples[0, 0, 0]) == -274) event = seeker['2'] assert source._event_index == 0 assert source._event_id == 2 assert event.count == 0 assert event.r1.event_id == 2 assert (round(source._r1_samples[0, 0, 0]) == -274) event = seeker[-1] assert event.count == len(seeker) - 1 with TargetIOEventSource(input_url=dataset, max_events=3) as source: with pytest.raises(IndexError): seeker = EventSeeker(source) _ = seeker[5]
def test_eventseeker(): with SimTelEventSource(input_url=dataset, back_seekable=True) as reader: seeker = EventSeeker(event_source=reader) event = seeker.get_event_index(1) assert event.count == 1 event = seeker.get_event_index(0) assert event.count == 0 event = seeker.get_event_id(31007) assert event.index.event_id == 31007 with pytest.raises(IndexError): seeker.get_event_index(200) with pytest.raises(TypeError): seeker.get_event_index("1") with pytest.raises(TypeError): seeker.get_event_index("t") with pytest.raises(TypeError): seeker.get_event_index(dict()) with SimTelEventSource(input_url=dataset, max_events=5, back_seekable=True) as reader: seeker = EventSeeker(event_source=reader) with pytest.raises(IndexError): event = seeker.get_event_index(5) assert event is not None
def test_eventseeker(): dataset = get_dataset_path("gamma_test.simtel.gz") kwargs = dict(config=None, tool=None, input_url=dataset) with SimTelEventSource(**kwargs) as reader: seeker = EventSeeker(reader=reader) event = seeker[1] assert event.r0.tels_with_data == {11, 21, 24, 26, 61, 63, 118, 119} event = seeker[0] assert event.r0.tels_with_data == {38, 47} event = seeker['409'] assert event.r0.event_id == 409 assert event.r0.tels_with_data == {11, 21, 24, 26, 61, 63, 118, 119} tel_list = [{38, 47}, {11, 21, 24, 26, 61, 63, 118, 119}] events = seeker[0:2] events_tels = [e.r0.tels_with_data for e in events] assert events_tels == tel_list events = seeker[[0, 1]] events_tels = [e.r0.tels_with_data for e in events] assert events_tels == tel_list events = seeker[['408', '409']] events_tels = [e.r0.tels_with_data for e in events] assert events_tels == tel_list assert len(seeker) == 9 with pytest.raises(IndexError): event = seeker[200] assert event is not None with pytest.raises(ValueError): event = seeker['t'] assert event is not None with pytest.raises(TypeError): event = seeker[dict()] assert event is not None with SimTelEventSource(**kwargs, max_events=5) as reader: seeker = EventSeeker(reader=reader) with pytest.raises(IndexError): event = seeker[5] assert event is not None class StreamFileReader(SimTelEventSource): def is_stream(self): return True with StreamFileReader(**kwargs) as reader: with pytest.raises(IOError): seeker = EventSeeker(reader=reader) assert seeker is not None
def test_eventseeker(): with SimTelEventSource(input_url=dataset, back_seekable=True) as reader: seeker = EventSeeker(reader=reader) event = seeker[1] assert event.count == 1 event = seeker[0] assert event.count == 0 event = seeker["31007"] assert event.index.event_id == 31007 events = seeker[0:2] for i, event in enumerate(events): assert event.count == i events = seeker[[0, 1]] for i, event in enumerate(events): assert event.count == i ids = ["23703", "31007"] events = seeker[ids] for i, event in zip(ids, events): assert event.index.event_id == int(i) with pytest.raises(IndexError): event = seeker[200] with pytest.raises(ValueError): event = seeker["t"] with pytest.raises(TypeError): event = seeker[dict()] with SimTelEventSource( input_url=dataset, max_events=5, back_seekable=True ) as reader: seeker = EventSeeker(reader=reader) with pytest.raises(IndexError): event = seeker[5] assert event is not None class StreamFileReader(SimTelEventSource): def is_stream(self): return True with StreamFileReader(input_url=dataset) as reader: with pytest.raises(IOError): seeker = EventSeeker(reader=reader)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" event_source = EventSource(parent=self) self.subarray = event_source.subarray self.eventseeker = EventSeeker(event_source, parent=self) self.calibrate = CameraCalibrator(parent=self, subarray=self.subarray)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" self.reader = EventSource.from_config(parent=self) self.seeker = EventSeeker(self.reader, parent=self) self.extractor = ImageExtractor.from_name(self.extractor_product, parent=self) self.dl0 = CameraDL0Reducer(parent=self) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, parent=self) self.viewer = BokehEventViewer(parent=self) # Setup widgets self.viewer.create() self.viewer.enable_automatic_index_increment() self.create_previous_event_widget() self.create_next_event_widget() self.create_event_index_widget() self.create_goto_event_index_widget() self.create_event_id_widget() self.create_goto_event_id_widget() self.create_telid_widget() self.create_channel_widget() self.create_dl1_widgets() self.update_dl1_widget_values() # Setup layout self.layout = layout([[self.viewer.layout], [ self.w_previous_event, self.w_next_event, self.w_goto_event_index, self.w_goto_event_id ], [self.w_event_index, self.w_event_id], [self.w_telid, self.w_channel], [self.wb_extractor]])
def test_event(): """ an example event for algorithm testing""" filename = get_dataset_path('gamma_test.simtel.gz') with HESSIOEventSource(input_url=filename) as reader: seeker = EventSeeker(reader) event = seeker['409'] yield event
def test_eventseeker_edit(): with SimTelEventSource(input_url=dataset, back_seekable=True) as reader: seeker = EventSeeker(event_source=reader) event = seeker.get_event_index(1) assert event.count == 1 event.count = 2 assert event.count == 2 event = seeker.get_event_index(1) assert event.count == 1
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" event_source = self.add_component(EventSource.from_config(parent=self)) self.eventseeker = self.add_component( EventSeeker(event_source, parent=self)) self.extractor = self.add_component( ImageExtractor.from_name(self.extractor_product, parent=self)) self.calibrate = self.add_component( CameraCalibrator(parent=self, image_extractor=self.extractor))
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" event_source = EventSource.from_config(parent=self) self.eventseeker = EventSeeker(event_source, parent=self) self.extractor = ImageExtractor.from_name( self.extractor_product, parent=self, ) self.dl0 = CameraDL0Reducer(parent=self) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, parent=self)
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
def _global_example_event(): """ helper to get a single event from a MC file. Don't use this fixture directly, rather use `test_event` """ filename = get_dataset_path('gamma_test.simtel.gz') print("******************** LOAD TEST EVENT ***********************") with SimTelEventSource(input_url=filename) as reader: seeker = EventSeeker(reader) event = seeker['409'] return event
def test_eventseeker(): dataset = get_dataset_path( "20131004_M1_05029747.003_Y_MagicCrab-W0.40+035.root") dataset = dataset.replace('_M1_', '_M*_') with MAGICEventSourceROOT(input_url=dataset) as source: seeker = EventSeeker(source) event = seeker[0] assert event.count == 0 assert event.dl0.event_id == 29795.0 event = seeker[2] assert event.count == 2 assert event.r1.event_id == 29798.0
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) event_source = EventSource.from_config(**kwargs) self.eventseeker = EventSeeker(event_source, **kwargs) self.extractor = ChargeExtractor.from_name(self.extractor_product, **kwargs) self.r1 = CameraR1Calibrator.from_eventsource(eventsource=event_source, **kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, **kwargs)
def test_eventseeker_simtel(): # Ensure the EventSeeker can forward seek even if back-seeking is not possible with SimTelEventSource(input_url=dataset, back_seekable=False) as reader: seeker = EventSeeker(event_source=reader) event = seeker.get_event_index(1) assert event.count == 1 event = seeker.get_event_index(1) assert event.count == 1 event = seeker.get_event_index(2) assert event.count == 2 event = seeker.get_event_index(2) assert event.count == 2 event = seeker.get_event_index(4) assert event.count == 4 with pytest.raises(IOError): seeker.get_event_index(1) event = seeker.get_event_index(5) assert event.count == 5
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) default_url = get_dataset_path("gamma_test.simtel.gz") EventSourceFactory.input_url.default_value = default_url self.reader = EventSourceFactory.produce(**kwargs) self.seeker = EventSeeker(self.reader, **kwargs) self.extractor = ChargeExtractorFactory.produce(**kwargs) self.cleaner = WaveformCleanerFactory.produce(**kwargs) self.r1 = CameraR1CalibratorFactory.produce(eventsource=self.reader, **kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, cleaner=self.cleaner, **kwargs) self.viewer = BokehEventViewer(**kwargs) # Setup widgets self.viewer.create() self.viewer.enable_automatic_index_increment() self.create_previous_event_widget() self.create_next_event_widget() self.create_event_index_widget() self.create_goto_event_index_widget() self.create_event_id_widget() self.create_goto_event_id_widget() self.create_telid_widget() self.create_channel_widget() self.create_dl1_widgets() self.update_dl1_widget_values() # Setup layout self.layout = layout([[self.viewer.layout], [ self.w_previous_event, self.w_next_event, self.w_goto_event_index, self.w_goto_event_id ], [self.w_event_index, self.w_event_id], [self.w_telid, self.w_channel], [self.wb_extractor]])