def test_pipeline(): dataset = get_dataset_path("chec_r1.tio") reader = TargetIOEventSource(input_url=dataset, max_events=10) calibrator = CameraCalibrator(eventsource=reader) for event in reader: calibrator.calibrate(event) assert event.r0.tel.keys() == event.dl1.tel.keys()
def test_pipeline(): dataset = get_dataset_path("chec_r1.tio") reader = TargetIOEventSource(input_url=dataset, max_events=10) calibrator = CameraCalibrator(eventsource=reader) for event in reader: calibrator.calibrate(event) assert event.r0.tel.keys() == event.dl1.tel.keys()
def test_pipeline(): from ctapipe.io.sst1meventsource import SST1MEventSource reader = SST1MEventSource(input_url=example_file_path, max_events=10) calibrator = CameraCalibrator(eventsource=reader) for event in reader: calibrator.calibrate(event) assert event.r0.tel.keys() == event.dl1.tel.keys()
def test_pipeline(): from ctapipe.io.sst1meventsource import SST1MEventSource reader = SST1MEventSource(input_url=example_file_path, max_events=10) calibrator = CameraCalibrator(eventsource=reader) for event in reader: calibrator.calibrate(event) assert event.r0.tel.keys() == event.dl1.tel.keys()
def test_view_wf(example_event): viewer = BokehEventViewer() viewer.create() viewer.event = example_event c = CameraCalibrator() c.calibrate(example_event) t = list(example_event.r0.tels_with_data)[0] wf = viewer.waveforms[0] wf.view = 'r1' assert (wf.waveform == example_event.r1.tel[t].waveform[0, 0, :]).all() with pytest.raises(ValueError): wf.view = 'q'
def test_view_camera(example_event): viewer = BokehEventViewer() viewer.create() viewer.event = example_event c = CameraCalibrator() c.calibrate(example_event) t = list(example_event.r0.tels_with_data)[0] cam = viewer.cameras[0] cam.view = 'r1' assert (cam.image == example_event.r1.tel[t].waveform[0, :, 0]).all() with pytest.raises(ValueError): cam.view = 'q'
class EventFileLooper(Tool): name = "EventFileLooper" description = "Loop through the file and apply calibration. Intended as " \ "a test that the routines work, and a benchmark of speed." aliases = Dict(dict(r='EventFileReaderFactory.reader', f='EventFileReaderFactory.input_path', max_events='EventFileReaderFactory.max_events', ped='CameraR1CalibratorFactory.pedestal_path', tf='CameraR1CalibratorFactory.tf_path', pe='CameraR1CalibratorFactory.pe_path', extractor='ChargeExtractorFactory.extractor', extractor_t0='ChargeExtractorFactory.t0', window_width='ChargeExtractorFactory.window_width', window_shift='ChargeExtractorFactory.window_shift', sig_amp_cut_HG='ChargeExtractorFactory.sig_amp_cut_HG', sig_amp_cut_LG='ChargeExtractorFactory.sig_amp_cut_LG', lwt='ChargeExtractorFactory.lwt', clip_amplitude='CameraDL1Calibrator.clip_amplitude', radius='CameraDL1Calibrator.radius', cleaner='WaveformCleanerFactory.cleaner', )) classes = List([EventFileReaderFactory, ChargeExtractorFactory, CameraR1CalibratorFactory, CameraDL1Calibrator, WaveformCleanerFactory ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader = None self.calibrator = None self.geometry = None self.amp_cut = None self.dist_cut = None self.tail_cut = None self.pix_cut = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) reader_factory = EventFileReaderFactory(**kwargs) reader_class = reader_factory.get_class() self.reader = reader_class(**kwargs) self.calibrator = CameraCalibrator(origin=self.reader.origin, **kwargs) first_event = self.reader.get_event(0) self.geometry = Geometry(self.config, self, first_event) self.amp_cut = {"LSTCam": 92.7, "NectarCam": 90.6, "FlashCam": 90.6, "CHEC": 29.3} self.dist_cut = {"LSTCam": 1.74 * u.deg, "NectarCam": 3. * u.deg, "FlashCam": 3. * u.deg, "CHEC": 3.55 * u.deg} self.tail_cut = {"LSTCam": (8, 16), "NectarCam": (7, 14), "FlashCam": (7, 14), "CHEC": (3, 6)} self.pix_cut = {"LSTCam": 5, "NectarCam": 4, "FlashCam": 4, "CHEC": 4} def start(self): # n_events = self.reader.num_events source = self.reader.read() desc = "Looping through file" for event in tqdm(source, desc=desc): #, total=n_events): ev = event.count self.calibrator.calibrate(event) for tel_id in event.r0.tels_with_data: geom = self.geometry.get_camera(tel_id) nom_geom = self.geometry.get_nominal(tel_id) image = event.dl1.tel[tel_id].image[0] # Cleaning cuts = self.tail_cut[geom.cam_id] tc = tailcuts_clean(geom, image, *cuts) if not tc.any(): # self.log.warning('No image') continue # cleaned = np.ma.masked_array(image, mask=~tc) cleaned = image * tc # Hillas try: hillas = hillas_parameters(nom_geom, cleaned) except HillasParameterizationError: # self.log.warning('HillasParameterizationError') continue # embed() fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111) camera = CameraDisplay(nom_geom, ax=ax, image=image, cmap='viridis') camera.add_colorbar() cen_x = u.Quantity(hillas.cen_x).value cen_y = u.Quantity(hillas.cen_y).value length = u.Quantity(hillas.length).value width = u.Quantity(hillas.width).value print(cen_x, cen_y, length, width) camera.add_ellipse(centroid=(cen_x, cen_y), length=length * 2, width=width * 2, angle=hillas.psi.rad) plt.show() def finish(self): pass