def display_event(event): """an extremely inefficient display. It creates new instances of CameraDisplay for every event and every camera, and also new axes for each event. It's hacked, but it works """ print("Displaying... please wait (this is an inefficient implementation)") global fig ntels = len(event.dl0.tels_with_data) fig.clear() plt.suptitle("EVENT {}".format(event.dl0.event_id)) for ii, tel_id in enumerate(event.dl0.tels_with_data): print("\t draw cam {}...".format(tel_id)) nn = int(ceil(sqrt(ntels))) ax = plt.subplot(nn, nn, ii + 1) x, y = event.meta.pixel_pos[tel_id] geom = io.guess_camera_geometry(x * u.m, y * u.m) disp = visualization.CameraDisplay(geom, axes=ax, title="CT{0}".format(tel_id)) disp.pixels.set_antialiaseds(False) disp.autoupdate = False disp.set_cmap(random.choice(cmaps)) chan = 0 signals = event.dl0.tel[tel_id].adc_sums[chan] signals -= signals.mean() disp.set_image(signals) disp.add_colorbar()
def initialize_camera(tel_id, filename, file_closed=1): if 'simtel.gz' in filename: if file_closed: ld.clear_lists_camera() load_hessio(filename) nextevent_hessio() else: pass px = h.get_pixel_position(tel_id)[0] py = h.get_pixel_position(tel_id)[1] ld.pixel_posX.append(px) ld.pixel_posY.append(py) ld.camera_class.append( io.guess_camera_geometry(px * u.m, py * u.m).cam_id) #to use this, one has to go through every event of the run... n_channel = h.get_num_channel(tel_id) ld.channel_num = n_channel for chan in range(n_channel): ld.adc_sampels.append(h.get_adc_sample(tel_id, chan).tolist()) if file_closed: close_hessio() elif 'fits' in filename: hdulist = file_closed if file_closed == 1: ld.clear_lists_camera() ld.clear_lists_telescope() hdulist = load_fits(filename) teles = hdulist[1].data ld.telescope = teles["TelID"].tolist() else: pass index = ld.telescope_id.index(tel_id) ld.camera_fov.append(hdulist[1].data[index]["FOV"]) pixel_id_cam = [] index2 = np.where(hdulist[2].data['L0ID'] == index)[0] for i in index2: pixel_id_cam.append(hdulist[2].data[i]['PixelID']) ld.pixel_id.append(pixel_id_cam) if file_closed == 1: close_fits(hdulist)
def initialize_camera(tel_id, filename, file_closed = 1): if 'simtel.gz' in filename: if file_closed: ld.clear_lists_camera() load_hessio(filename) nextevent_hessio() else: pass px = h.get_pixel_position(tel_id)[0] py = h.get_pixel_position(tel_id)[1] ld.pixel_posX.append(px) ld.pixel_posY.append(py) ld.camera_class.append(io.guess_camera_geometry(px*u.m,py*u.m).cam_id) #to use this, one has to go through every event of the run... n_channel = h.get_num_channel(tel_id) ld.channel_num = n_channel for chan in range(n_channel): ld.adc_sampels.append(h.get_adc_sample(tel_id,chan).tolist()) if file_closed: close_hessio() elif 'fits' in filename: hdulist = file_closed if file_closed == 1: ld.clear_lists_camera() ld.clear_lists_telescope() hdulist = load_fits(filename) teles = hdulist[1].data ld.telescope = teles["TelID"].tolist() else: pass index = ld.telescope_id.index(tel_id) ld.camera_fov.append(hdulist[1].data[index]["FOV"]) pixel_id_cam = [] index2 = np.where(hdulist[2].data['L0ID'] == index)[0] for i in index2: pixel_id_cam.append(hdulist[2].data[i]['PixelID']) ld.pixel_id.append(pixel_id_cam) if file_closed == 1: close_fits(hdulist)
# TODO: use io.fits instead and make the table be variable length # TODO: make this a tool (ctapipe-eventio2tels) if __name__ == '__main__': filename = sys.argv.pop(1) h.file_open(filename) event = h.move_to_next_event() next(event) for telid in range(1, h.get_num_telescope()): try: px, py = h.get_pixel_position(telid) camtab = Table(names=['PIX_POS_X', 'PIX_POS_Y'], data=[px * u.m, py * u.m]) camtab.meta['N_PIX'] = h.get_num_pixels(telid) camtab.meta['N_SAMPS'] = h.get_num_samples(telid) camtab.meta['N_TIMES'] = h.get_pixel_timing_num_times_types(telid) camtab.meta['MIR_AREA'] = h.get_mirror_area(telid) geom = io.guess_camera_geometry(px * u.m, py * u.m) camtab.meta['TELCLASS'] = geom.cam_id camtab.meta['PIXTYPE'] = geom.pix_type filename = "cam_{:03d}.fits".format(telid) camtab.write(filename) print("WROTE ", filename) except h.HessioTelescopeIndexError: break