def test_factory_for_protozfits_file(): from ctapipe.io.eventsourcefactory import EventSourceFactory from ctapipe.io.sst1meventsource import SST1MEventSource reader = EventSourceFactory.produce(input_url=example_file_path) assert isinstance(reader, SST1MEventSource) assert reader.input_url == example_file_path
def test_factory_for_lst_file(): from ctapipe.io.eventsourcefactory import EventSourceFactory from ctapipe.io.lsteventsource import LSTEventSource reader = EventSourceFactory.produce(input_url=example_file_path) assert isinstance(reader, LSTEventSource) assert reader.input_url == example_file_path
def test_factory_for_nectarcam_file(): from ctapipe.io.eventsourcefactory import EventSourceFactory from ctapipe.io.nectarcameventsource import NectarCAMEventSource reader = EventSourceFactory.produce(input_url=example_file_path) assert isinstance(reader, NectarCAMEventSource) assert reader.input_url == example_file_path
def setup(self): kwargs = dict(config=self.config, tool=self) self.eventsource = EventSourceFactory.produce( input_url=get_dataset("gamma_test.simtel.gz"), **kwargs) self.calibrator = CameraCalibrator(eventsource=self.eventsource, **kwargs) self.plotter = ImagePlotter(**kwargs)
def setup(self): kwargs = dict(config=self.config, tool=self) self.eventsource = EventSourceFactory.produce( input_url=get_dataset_path("gamma_test.simtel.gz"), **kwargs ) self.calibrator = CameraCalibrator( eventsource=self.eventsource, **kwargs ) self.plotter = ImagePlotter(**kwargs)
def test_reconstruction(): """ a test of the complete fit procedure on one event including: • tailcut cleaning • hillas parametrisation • HillasPlane creation • direction fit • position fit in the end, proper units in the output are asserted """ filename = get_dataset_path("gamma_test.simtel.gz") fit = HillasReconstructor() tel_azimuth = {} tel_altitude = {} source = EventSourceFactory.produce(input_url=filename) for event in source: hillas_dict = {} for tel_id in event.dl0.tels_with_data: geom = event.inst.subarray.tel[tel_id].camera tel_azimuth[tel_id] = event.mc.tel[tel_id].azimuth_raw * u.rad tel_altitude[tel_id] = event.mc.tel[tel_id].altitude_raw * u.rad pmt_signal = event.r0.tel[tel_id].image[0] mask = tailcuts_clean(geom, pmt_signal, picture_thresh=10., boundary_thresh=5.) pmt_signal[mask == 0] = 0 try: moments = hillas_parameters(geom, pmt_signal) hillas_dict[tel_id] = moments except HillasParameterizationError as e: print(e) continue if len(hillas_dict) < 2: continue fit_result = fit.predict(hillas_dict, event.inst, tel_azimuth, tel_altitude) print(fit_result) fit_result.alt.to(u.deg) fit_result.az.to(u.deg) fit_result.core_x.to(u.m) assert fit_result.is_valid
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] ])
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) eventsource = EventSourceFactory.produce(**kwargs) self.eventseeker = EventSeeker(eventsource, **kwargs) self.extractor = ChargeExtractorFactory.produce(**kwargs) self.r1 = CameraR1CalibratorFactory.produce(eventsource=eventsource, **kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, **kwargs)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) eventsource = EventSourceFactory.produce(**kwargs) self.eventseeker = EventSeeker(eventsource, **kwargs) self.extractor = ChargeExtractorFactory.produce(**kwargs) self.r1 = CameraR1CalibratorFactory.produce( eventsource=eventsource, **kwargs ) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=self.extractor, **kwargs)
def process_file(input_file, reco_algorithm, n_events=-1, silent=False): event_source = EventSourceFactory.produce( input_url=input_file, max_events=n_events if n_events > 1 else None, product='HESSIOEventSource', ) calibrator = CameraCalibrator(eventsource=event_source, ) telescope_event_information = [] array_event_information = [] for event in tqdm(event_source, disable=silent): if number_of_valid_triggerd_cameras(event) < 2: continue calibrator.calibrate(event) try: image_features, reconstruction, _, _ = process_event( event, reco_algorithm=reco_algorithm) event_features = event_information(event, image_features, reconstruction) array_event_information.append(event_features) telescope_event_information.append(image_features) except TooFewTelescopesException: continue if (len(telescope_event_information) == 0): return None, None, None telescope_events = pd.concat(telescope_event_information) telescope_events.set_index(['run_id', 'array_event_id', 'telescope_id'], drop=True, verify_integrity=True, inplace=True) array_events = pd.DataFrame(array_event_information) array_events.set_index(['run_id', 'array_event_id'], drop=True, verify_integrity=True, inplace=True) run_information = read_simtel_mc_information(input_file) df_runs = pd.DataFrame([run_information]) df_runs.set_index('run_id', drop=True, verify_integrity=True, inplace=True) return df_runs, array_events, telescope_events
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]])
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_from_reader(): dataset = get_dataset_path("gamma_test.simtel.gz") reader = EventSourceFactory.produce(product='HESSIOEventSource', input_url=dataset) assert reader.__class__.__name__ == "HESSIOEventSource" assert reader.input_url == dataset
def test_factory_different_file(): dataset = get_dataset_path("gamma_test_large.simtel.gz") reader = EventSourceFactory.produce(input_url=dataset) assert reader.__class__.__name__ == "HESSIOEventSource" assert reader.input_url == dataset
def start(self): run_list = np.loadtxt('%s/runlist.txt' % self.input_path, unpack=True) plot_cam = False plot_delay = 0.5 disp = None n_events = [] trig_eff = [] n_pe = [] if debug: fig = plt.figure(1) ax = fig.add_subplot(111) for n, run in enumerate(run_list[0]): n_events.append(run_list[3][n]) n_pe.append(run_list[2][n]) # TODO remove need for hardcoded file name if self.calibrator == "TargetIOR1Calibrator": file_name = "%s/Run%05d_r1.tio" % (self.input_path, int(run)) print(file_name) elif self.calibrator == "HESSIOR1Calibrator": file_name = "%s/Run%05d_mc.simtel.gz" % (self.input_path, int(run)) print(file_name) try: source = EventSourceFactory.produce(input_url=file_name, max_events=self.max_events) true_pe = [] # lab_pe = [] peds_all = [] n_trig = 0 for event in tqdm(source): n_trig = +1 # true_pe.append() # self.cal.calibrate(event) # self.dl0.reduce(event) # self.dl1.calibrate(event) # input_pe = run_list[2][n] # try: # input_nsb = run_list[5][n] # except IndexError: # print('File has no column for NSB, setting to 0') # input_nsb = 0 # if self.plot_cam == True: # if disp is None: # geom = event.inst.subarray.tel[self.telescopes].camera # disp = CameraDisplay(geom) # disp.add_colorbar() # plt.show(block=False) # im = event.dl1.tel[self.telescopes].image[0] # disp.image = im # plt.pause(plot_delay) # # teldata = event.r0.tel[self.telescopes].waveform[0] # peds = teldata[:, 0:10].mean(axis=1) # peds2 = teldata[:, 0:10].std(axis=1) # peds_all.append(teldata[:, 0:90]) # # plt.hist(peds,bins=50, alpha=0.4) # # plt.show() # # print(teldata) # # plt.plot(range(len(teldata[100])), teldata[100]) # # plt.show() # # exit() # # print(np.mean(peds_all), np.std(peds_all)) # # exit() # # true_charge_mc = event.mc.tel[self.telescopes].photo_electron_image # # measured_charge = event.dl1.tel[self.telescopes].image[0] # # true_charge_lab = np.asarray([input_pe]*len(measured_charge)) # # true_pe.append(true_charge_mc) # # if self.use_true_pe: # # true_charge=true_charge_mc # # else: # # true_charge=true_charge_lab.astype(int) # # # # self.calculator.add_charges(true_charge, measured_charge) # # if debug: # # plt.errorbar(input_nsb, np.mean(peds_all), np.std(peds_all),color='k') # plt.scatter(input_nsb, np.std(peds_all), marker ='x',color='k') except FileNotFoundError: stop = 0 print('file_not_found') trig_eff.append(n_trig / run_list[3][n]) plt.plot(n_pe, trig_eff) plt.show() if debug: plt.xscale('log') plt.yscale('log') plt.plot([0, 1000], [0, 1000], 'k:') plt.xlabel('Input p.e.') plt.ylabel('True mc p.e.') plt.show()
def test_eventsourcefactory(): dataset = get_dataset_path("chec_r1.tio") source = EventSourceFactory.produce(input_url=dataset) assert source.__class__.__name__ == "TargetIOEventSource" assert source.input_url == dataset