def test_targetio_calibrator(): pytest.importorskip("target_calib") url_r0 = get_dataset("targetmodule_r0.tio") url_r1 = get_dataset("targetmodule_r1.tio") pedpath = get_dataset("targetmodule_ped.tcal") source_r0 = TargetIOEventSource(input_url=url_r0) source_r1 = TargetIOEventSource(input_url=url_r1) r1c = CameraR1CalibratorFactory.produce(eventsource=source_r0) event_r0 = source_r0._get_event_by_index(0) event_r1 = source_r1._get_event_by_index(0) r1c.calibrate(event_r0) assert_array_equal(event_r0.r0.tel[0].waveform, event_r0.r1.tel[0].waveform) r1c = CameraR1CalibratorFactory.produce( eventsource=source_r0, pedestal_path=pedpath ) r1c.calibrate(event_r0) assert_array_almost_equal(event_r0.r1.tel[0].waveform, event_r1.r1.tel[0].waveform, 1)
def test_geom(): dataset = get_dataset("chec_r1.tio") with TargetIOEventSource(input_url=dataset) as source: event = source._get_event_by_index(0) assert event.inst.subarray.tels[0].camera.pix_x.size == 2048 dataset = get_dataset("targetmodule_r1.tio") with TargetIOEventSource(input_url=dataset) as source: event = source._get_event_by_index(0) assert event.inst.subarray.tels[0].camera.pix_x.size == 64
def get_array_layout(instrument_name): """ Returns the array layout for the given instrument as an `astropy.table.Table` object. """ name = instrument_name.lower() try: layoutfile = get_dataset('{}_arraylayout.fits'.format(name)) except KeyError: layoutfile = get_dataset('{}_arraylayout.fits.gz'.format(name)) return load_array_layout_from_file(layoutfile)
def test_event_id(): url = get_dataset("chec_r1.tio") source = TargetIOEventSource(input_url=url) event_id = 2 source._get_event_by_id(event_id) assert(event_id == source._tio_reader.fCurrentEventID) assert(round(source._r1_samples[0, 0, 0]) == -274)
def get_test_event(): filename = get_dataset('gamma_test.simtel.gz') source = hessio_event_source(filename, requested_event=409, use_event_id=True) event = next(source) return event
def test_array_draw(): filename = get_dataset("gamma_test.simtel.gz") cam_geom = {} source = hessio_event_source(filename, max_events=2) r1 = HESSIOR1Calibrator() dl0 = CameraDL0Reducer() calibrator = CameraDL1Calibrator() for event in source: array_pointing = SkyCoord( event.mcheader.run_array_direction[1] * u.rad, event.mcheader.run_array_direction[0] * u.rad, frame=AltAz) # array_view = ArrayPlotter(instrument=event.inst, # system=TiltedGroundFrame( # pointing_direction=array_pointing)) hillas_dict = {} r1.calibrate(event) dl0.reduce(event) calibrator.calibrate(event) # calibrate the events # store MC pointing direction for the array for tel_id in event.dl0.tels_with_data: pmt_signal = event.dl1.tel[tel_id].image[0] geom = deepcopy(event.inst.subarray.tel[tel_id].camera) fl = event.inst.subarray.tel[tel_id].optics.equivalent_focal_length # Transform the pixels positions into nominal coordinates camera_coord = CameraFrame(x=geom.pix_x, y=geom.pix_y, z=np.zeros(geom.pix_x.shape) * u.m, focal_length=fl, rotation=90 * u.deg - geom.cam_rotation) nom_coord = camera_coord.transform_to( NominalFrame(array_direction=array_pointing, pointing_direction=array_pointing)) geom.pix_x = nom_coord.x geom.pix_y = nom_coord.y mask = tailcuts_clean(geom, pmt_signal, picture_thresh=10., boundary_thresh=5.) try: moments = hillas_parameters(geom, pmt_signal * mask) hillas_dict[tel_id] = moments nom_coord = NominalPlotter(hillas_parameters=hillas_dict, draw_axes=True) nom_coord.draw_array() except HillasParameterizationError as e: print(e) continue
def from_name(cls, camera_id='NectarCam', version=None): """ Construct a CameraGeometry using the name of the camera and array. This expects that there is a resource in the `ctapipe_resources` module called "[array]-[camera].camgeom.fits.gz" or "[array]-[camera]-[ version].camgeom.fits.gz" Parameters ---------- camera_id: str name of camera (e.g. 'NectarCam', 'LSTCam', 'GCT', 'SST-1M') array_id: str array identifier (e.g. 'CTA', 'HESS') version: camera version id (currently unused) Returns ------- new CameraGeometry """ if version is None: verstr = '' else: verstr = "-{:03d}".format(version) filename = get_dataset("{camera_id}{verstr}.camgeom.fits.gz".format( camera_id=camera_id, verstr=verstr)) return CameraGeometry.from_table(filename)
def test_hessio_file_reader(): dataset = get_dataset("gamma_test.simtel.gz") kwargs = dict(config=None, tool=None, input_url=dataset) with HESSIOEventSource(**kwargs) as reader: assert reader.is_compatible(dataset) assert not reader.is_stream for event in reader: if event.count == 0: assert event.r0.tels_with_data == {38, 47} elif event.count == 1: assert event.r0.tels_with_data == { 11, 21, 24, 26, 61, 63, 118, 119 } else: break for event in reader: # Check generator has restarted from beginning assert event.count == 0 break # test that max_events works: max_events = 5 with HESSIOEventSource(**kwargs, max_events=max_events) as reader: count = 0 for _ in reader: count += 1 assert count == max_events # test that the allowed_tels mask works: with HESSIOEventSource(**kwargs, allowed_tels={3, 4}) as reader: for event in reader: assert event.r0.tels_with_data.issubset(reader.allowed_tels)
def from_name(cls, camera_id='NectarCam', version=None): """ Construct a CameraGeometry using the name of the camera and array. This expects that there is a resource in the `ctapipe_resources` module called "[array]-[camera].camgeom.fits.gz" or "[array]-[camera]-[ version].camgeom.fits.gz" Parameters ---------- camera_id: str name of camera (e.g. 'NectarCam', 'LSTCam', 'GCT', 'SST-1M') array_id: str array identifier (e.g. 'CTA', 'HESS') version: camera version id (currently unused) Returns ------- new CameraGeometry """ if version is None: verstr = '' else: verstr = "-{:03d}".format(version) filename = get_dataset("{camera_id}{verstr}.camgeom.fits.gz" .format(camera_id=camera_id, verstr=verstr)) return CameraGeometry.from_table(filename)
def test_FitGammaHillas(): ''' a test of the complete fit procedure on one event including: • tailcut cleaning • hillas parametrisation • GreatCircle creation • direction fit • position fit in the end, proper units in the output are asserted ''' filename = get_dataset("gamma_test.simtel.gz") fit = HillasReconstructor() cam_geom = {} tel_phi = {} tel_theta = {} source = hessio_event_source(filename) for event in source: hillas_dict = {} for tel_id in event.dl0.tels_with_data: if tel_id not in cam_geom: cam_geom[tel_id] = CameraGeometry.guess( event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], event.inst.optical_foclen[tel_id]) tel_phi[tel_id] = event.mc.tel[tel_id].azimuth_raw * u.rad tel_theta[tel_id] = (np.pi/2-event.mc.tel[tel_id].altitude_raw)*u.rad pmt_signal = event.r0.tel[tel_id].adc_sums[0] mask = tailcuts_clean(cam_geom[tel_id], pmt_signal, picture_thresh=10., boundary_thresh=5.) pmt_signal[mask == 0] = 0 try: moments = hillas_parameters(event.inst.pixel_pos[tel_id][0], event.inst.pixel_pos[tel_id][1], 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_phi, tel_theta) 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 return
def test_eventseeker(): dataset = get_dataset("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.r0.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.r0.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_hessio_event_source(): filename = get_dataset("gamma_test.simtel.gz") source = hessio_event_source(filename) event = next(source) tels = event.dl0.tels_with_data print(tels) assert tels == {38, 47}
def test_eventsource_override_r1(): dataset = get_dataset("gamma_test.simtel.gz") eventsource = HESSIOEventSource(input_url=dataset) calibrator = CameraCalibrator( eventsource=eventsource, r1_product="NullR1Calibrator" ) assert isinstance(calibrator.r1, NullR1Calibrator)
def test_get_run_id(): filename = get_dataset("gamma_test.simtel.gz") print(filename) gen = hessio_event_source(filename) event = next(gen) tels = event.dl0.tels_with_data print(tels) assert tels == {38, 47}
def test_factory_from_eventsource_override(): dataset = get_dataset("gamma_test.simtel.gz") eventsource = HESSIOEventSource(input_url=dataset) calibrator = CameraR1CalibratorFactory.produce( eventsource=eventsource, product="NullR1Calibrator" ) assert isinstance(calibrator, NullR1Calibrator)
def test_event_file_reader_factory(): dataset = get_dataset("gamma_test.simtel.gz") factory = EventFileReaderFactory(None, None) factory.input_path = dataset cls = factory.get_class() file = cls(None, None) num_events = file.num_events assert (num_events == 9)
def test_get_run_id(): filename = get_dataset("gamma_test.simtel.gz") print(filename) gen = hessio_event_source(filename) event = next(gen) tels = event.dl0.tels_with_data print(tels) assert tels == {38, 47}
def test_event_file_reader_factory(): dataset = get_dataset("gamma_test.simtel.gz") factory = EventFileReaderFactory(None, None) factory.input_path = dataset cls = factory.get_class() file = cls(None, None) num_events = file.num_events assert(num_events == 9)
def generate_input_containers(): # Get event from hessio file, append them into input_containers input_filename = get_dataset("gamma_test.simtel.gz") gen = hessio_event_source(input_filename, max_events=3) input_containers = [] for event in gen: input_containers.append(deepcopy(event)) return input_containers
def generate_input_containers(): # Get event from hessio file, append them into input_containers input_filename = get_dataset("gamma_test.simtel.gz") gen = hessio_event_source(input_filename, max_events=3) input_containers = [] for event in gen: input_containers.append(deepcopy(event)) return input_containers
def test_event(): """ an example event for algorithm testing""" filename = get_dataset('gamma_test.simtel.gz') with HESSIOEventSource(input_url=filename) as reader: seeker = EventSeeker(reader) event = seeker['409'] yield event
def test_hessio_file_reader(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) assert file.directory == dirname(dataset) assert file.extension == ".gz" assert file.filename == "gamma_test.simtel" source = file.read() event = next(source) assert event.r0.tels_with_data == {38, 47}
def test_dump_triggers(tmpdir): outfile = tmpdir.join("triggers.fits") tool = DumpTriggersTool(infile=get_dataset("gamma_test_large.simtel.gz"), outfile=str(outfile)) tool.run(argv=[]) assert outfile.exists()
def test_get_event(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) event = file.get_event(2) assert event.count == 2 assert event.r0.event_id == 803 event = file.get_event(803, True) assert event.count == 2 assert event.r0.event_id == 803
def test_get_event(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) event = file.get_event(2) assert event.count == 2 assert event.r0.event_id == 803 event = file.get_event(803, True) assert event.count == 2 assert event.r0.event_id == 803
def test_get_num_events(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) num_events = file.num_events assert(num_events == 9) file.max_events = 2 num_events = file.num_events assert (num_events == 2)
def test_get_num_events(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) num_events = file.num_events assert (num_events == 9) file.max_events = 2 num_events = file.num_events assert (num_events == 2)
def test_singlemodule_r0(): url = get_dataset("targetmodule_r0.tio") source = TargetIOEventSource(input_url=url) event = source._get_event_by_index(0) assert(source._r1_samples.shape[1] == 64) assert(round(source._r0_samples[0, 0, 0]) == 600) assert(round(source._r1_samples[0, 0, 0]) == 0) assert(event.r0.tels_with_data == {0}) assert(event.r0.tel[0].waveform[0, 0, 0] == source._r0_samples[0, 0, 0])
def test_hessio_file_reader(): dataset = get_dataset("gamma_test.simtel.gz") file = HessioFileReader(None, None, input_path=dataset) assert file.directory == dirname(dataset) assert file.extension == ".gz" assert file.filename == "gamma_test.simtel" source = file.read() event = next(source) assert event.r0.tels_with_data == {38, 47}
def test_reconstruction(): """ a test of the complete fit procedure on one event including: • tailcut cleaning • hillas parametrisation • GreatCircle creation • direction fit • position fit in the end, proper units in the output are asserted """ filename = get_dataset("gamma_test.simtel.gz") fit = HillasReconstructor() tel_phi = {} tel_theta = {} source = hessio_event_source(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_phi[tel_id] = event.mc.tel[tel_id].azimuth_raw * u.rad tel_theta[tel_id] = (np.pi / 2 - 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_phi, tel_theta) 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 return
def test_array_draw(): filename = get_dataset("gamma_test.simtel.gz") cam_geom = {} source = hessio_event_source(filename, max_events=2) r1 = HessioR1Calibrator(None, None) dl0 = CameraDL0Reducer(None, None) calibrator = CameraDL1Calibrator(None, None) for event in source: array_pointing = SkyCoord(event.mcheader.run_array_direction[1] * u.rad, event.mcheader.run_array_direction[0] * u.rad, frame=AltAz) # array_view = ArrayPlotter(instrument=event.inst, # system=TiltedGroundFrame( # pointing_direction=array_pointing)) hillas_dict = {} r1.calibrate(event) dl0.reduce(event) calibrator.calibrate(event) # calibrate the events # store MC pointing direction for the array for tel_id in event.dl0.tels_with_data: pmt_signal = event.dl1.tel[tel_id].image[0] geom = event.inst.subarray.tel[tel_id].camera fl = event.inst.subarray.tel[tel_id].optics.effective_focal_length # Transform the pixels positions into nominal coordinates camera_coord = CameraFrame(x=geom.pix_x, y=geom.pix_y, z=np.zeros(geom.pix_x.shape) * u.m, focal_length=fl, rotation=90 * u.deg - geom.cam_rotation) nom_coord = camera_coord.transform_to( NominalFrame(array_direction=array_pointing, pointing_direction=array_pointing)) mask = tailcuts_clean(geom, pmt_signal, picture_thresh=10., boundary_thresh=5.) try: moments = hillas_parameters(nom_coord.x, nom_coord.y, pmt_signal * mask) hillas_dict[tel_id] = moments nom_coord = NominalPlotter(hillas_parameters=hillas_dict, draw_axes=True) nom_coord.draw_array() except HillasParameterizationError as e: print(e) continue
def test_chec_r1(): url = get_dataset("chec_r1.tio") source = TargetIOEventSource(input_url=url) event = source._get_event_by_index(0) assert(source._r0_samples is None) assert(source._r1_samples.shape[1] == 2048) assert(round(source._r1_samples[0, 0, 0]) == -274) assert(event.r0.tels_with_data == {0}) assert(event.r0.tel[0].waveform is None) assert(event.r1.tel[0].waveform[0, 0, 0] == source._r1_samples[0, 0, 0])
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 init(self): self.log.debug('%self.filename' % "--- SimTelArrayReader init {}---") try: in_file = get_dataset(self.filename) self.source = hessio_event_source(in_file, max_events=3) self.log.debug('%self.filename %self.source' % '{} successfully opened {}') except Exception: self.log.error('could not open ' + in_file) return False return True
def test_dump_instrument(tmpdir): tmpdir.chdir() tool = DumpInstrumentTool( infile=get_dataset("gamma_test_large.simtel.gz"), ) tool.run(argv=[]) print(tmpdir.listdir()) assert tmpdir.join('FlashCam.camgeom.fits.gz').exists()
def test_len(): dataset = get_dataset("chec_r1.tio") with TargetIOEventSource(input_url=dataset) as source: count = 0 for _ in source: count += 1 assert count == len(source) with TargetIOEventSource(input_url=dataset, max_events=3) as reader: assert len(reader) == 3
def test_jsonToFits(): backup = sys.argv full_config_name = get_dataset('config.json') sys.argv = ['test_json_2_fits.py', '--config_f=' + full_config_name] app = MyApp() app.initialize() app.start() tmp = tempfile.NamedTemporaryFile() app.json_to_fits(str(tmp.name)) sys.argv = backup
def test_jsonToFits(): backup = sys.argv full_config_name = get_dataset('config.json') sys.argv = ['test_json_2_fits.py', '--config_file=' + full_config_name] app = MyApp() app.initialize() app.start() tmp = tempfile.NamedTemporaryFile() app.jsonToFits(tmp) sys.argv = backup
def init(self): self.log.debug("--- SimTelArrayReader init {}---".format(self.filename)) try: in_file = get_dataset(self.filename) self.source = hessio_event_source(in_file,max_events=3) self.log.debug('{} successfully opened {}'.format(self.filename,self.source)) except: self.log.error('could not open ' + in_file) return False return True
def test_get_specific_event(): dataset = get_dataset("gamma_test.simtel.gz") source = hessio_event_source(dataset, requested_event=2) event = next(source) assert event.count == 2 assert event.dl0.event_id == 803 source = hessio_event_source(dataset, requested_event=803, use_event_id=True) event = next(source) assert event.count == 2 assert event.dl0.event_id == 803
def test_that_event_is_not_modified_after_loop(): dataset = get_dataset("chec_r1.tio") with TargetIOEventSource(input_url=dataset, max_events=2) as source: for event in source: last_event = copy.deepcopy(event) # now `event` should be identical with the deepcopy of itself from # inside the loop. # Unfortunately this does not work: # assert last_event == event # So for the moment we just compare event ids assert event.r0.event_id == last_event.r0.event_id
def test_get_specific_event(): dataset = get_dataset("gamma_test.simtel.gz") source = hessio_event_source(dataset, requested_event=2) event = next(source) assert event.count == 2 assert event.dl0.event_id == 803 source = hessio_event_source(dataset, requested_event=803, use_event_id=True) event = next(source) assert event.count == 2 assert event.dl0.event_id == 803
def get_atmosphere_profile_table(atmosphere_name='paranal'): """ Get an atmosphere profile table Parameters ---------- atmosphere_name: str identifier of atmosphere profile Returns ------- astropy.table.Table containing atmosphere profile with at least columns 'altitude' (m), and 'thickness' (g cm-2) as well as others. """ return Table.read(get_dataset('{}.atmprof.fits.gz'.format(atmosphere_name)))
def test_eventplotter(): dataset = get_dataset("gamma_test.simtel.gz") source = hessio_event_source(dataset, max_events=1) event = next(source) data = event.r0.tel[38].adc_samples[0] plotter = CameraPlotter(event) camera = plotter.draw_camera(38, data[:, 0]) assert camera is not None np.testing.assert_array_equal(camera.image, data[:, 0]) plotter.draw_camera_pixel_ids(38, [0, 1, 2]) waveform = plotter.draw_waveform(data[0, :]) assert waveform is not None np.testing.assert_array_equal(waveform.get_ydata(), data[0, :]) line = plotter.draw_waveform_positionline(0) assert line is not None np.testing.assert_array_equal(line.get_xdata(), [0, 0])
def get_test_event(): filename = get_dataset('gamma_test.simtel.gz') source = hessio_event_source(filename, requested_event=409, use_event_id=True) event = next(source) return event
Created on Thu Nov 19 11:43:50 2015 @author: zornju Example of using the instrument module and reading data from a hessio, a fits, and a sim_telarray-config file. """ from ctapipe.instrument import InstrumentDescription as ID from ctapipe.utils import get_dataset import matplotlib.pyplot as plt import os if __name__ == '__main__': filename1 = get_dataset('PROD2_telconfig.fits.gz') filename2 = get_dataset('gamma_test.simtel.gz') filename3 = get_dataset('CTA-ULTRA6-SCT.cfg') tel1,cam1,opt1 = ID.load(filename1) tel2,cam2,opt2 = ID.load(filename2) tel3,cam3,opt3 = ID.load(filename3) tel4,cam4,opt4 = ID.load() #To check which tables are in the dictionaries, do: print('Print the name of the tables present in the dictionaries taken',\ 'from the fits file:') print(tel1.keys(),cam1.keys(),opt1.keys()) print('As you can see, in the fits file, only the first dictionary is',\ 'filled with tables.') print('------------------------------------------------------------------')
def main(): script = os.path.splitext(os.path.basename(__file__))[0] log.info("[SCRIPT] {}".format(script)) parser = argparse.ArgumentParser( description='Display each event in the file', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-f', '--file', dest='input_path', action='store', default=get_dataset('gamma_test.simtel.gz'), help='path to the input file') parser.add_argument('-O', '--origin', dest='origin', action='store', #was .origin_list() default='hessio', help='origin of the file') parser.add_argument('-D', dest='display', action='store_true', default=False, help='display the camera events') parser.add_argument('-t', '--telescope', dest='tel', action='store', type=int, default=None, help='telecope to view. Default = All') parser.add_argument('--pdf', dest='output_path', action='store', default=None, help='path to store a pdf output of the plots') parser.add_argument('--calib-help', dest='calib_help', action='store_true', default=False, help='display the arguments used for the camera ' 'calibration') args, excess_args = parser.parse_known_args() #params, unknown_args = calibration_parameters(excess_args, # args.origin, # args.calib_help) r1 = HessioR1Calibrator(None, None) dl0 = CameraDL0Reducer(None, None) dl1 = CameraDL1Calibrator(None, None) log.debug("[file] Reading file") #input_file = InputFile(args.input_path, args.origin) #source = input_file.read() source = hessio_event_source(args.input_path) geom_dict = {} # plot_dict = {} muoneff = [] impactp = [] ringwidth = [] plot_dict = {'MuonEff':muoneff,'ImpactP':impactp,'RingWidth':ringwidth} numev = 0 for event in source: print("Event Number",numev) r1.calibrate(event) dl0.reduce(event) dl1.calibrate(event) muon_evt = analyze_muon_event(event) numev += 1 #Test display #Flag 1 for true (wish to display) #plot_muon_event(event,muon_evt) # display_telescope(muon_evt, muon_evt[0].tel_id, 1, geom_dict, pp, fig) if muon_evt[0] is not None and muon_evt[1] is not None: plot_muon_event(event,muon_evt,None,args) plot_dict['MuonEff'].append(muon_evt[1].optical_efficiency_muon) plot_dict['ImpactP'].append(muon_evt[1].impact_parameter.value) plot_dict['RingWidth'].append(muon_evt[1].ring_width.value) display_muon_plot(muon_evt) #Store and or Plot muon parameters here #if numev > 50: #for testing purposes - kill early # break t = Table([muoneff, impactp, ringwidth], names=('MuonEff','ImpactP','RingWidth'), meta={'name': 'muon analysis results'}) t['ImpactP'].unit = 'm' t['RingWidth'].unit = 'deg' # print('plotdict',plot_dict) t.write(str(args.output_path)+'_muontable.fits',overwrite=True) #NEED this to overwrite plot_muon_efficiency(args.output_path) log.info("[COMPLETE]")
plt.subplot(1, 2, 1) plt.scatter(pixid, peds) plt.title("Pedestals for event {}".format(event.r0.event_id)) plt.subplot(1, 2, 2) plt.scatter(pixid, pedvars) plt.title("Ped Variances for event {}".format(event.r0.event_id)) if __name__ == '__main__': # if a filename is specified, use it, otherwise load sample data if len(sys.argv) > 1: filename = sys.argv.pop(1) else: filename = get_dataset("gamma_test.simtel.gz") # set a fixed window (for now from samples 20 to the end), which may not # be appropriate for all telescopes (this should eventually be # chosen based on the telescope type, since some have shorter # sample windows: start = 15 end = None # None means through sample # loop over all events, all telescopes and all channels and call # the calc_peds function defined above to do some work: for event in hessio_event_source(filename): for telid in event.r0.tels_with_data: for chan in range(event.r0.tel[telid].adc_samples.shape[0]):
disp[-1].add_colorbar(label=" [{} ADC cts]".format(gain_label[i])) plt.pause(0.1) pp.savefig(fig) pp.close() if __name__ == '__main__': # Declare and parse command line option parser = argparse.ArgumentParser( description='Tel_id, pixel id and number of event to compute.') parser.add_argument('--f', dest='filename', required=False, default=get_dataset('gamma_test_large.simtel.gz'), help='filename <MC file name>') parser.add_argument('--d', dest='display', action='store_true', required=False,help='display the camera events') parser.add_argument('--tel', dest='tel_id', action='store', required=False, default=None, help='Telescope ID to display') parser.add_argument('--pdf', dest='pdffilename', action='store', required=False, default="./tmp.pdf", help='PDF output filename') args = parser.parse_args() if args.display: plt.show(block=False)