def process(input_path, output_path, hv_path, event_slice): reader = TIOReader(input_path) n_events = reader.n_events n_pixels = reader.n_pixels n_samples = reader.n_samples mapping = reader.mapping mappingtc = reader.tc_mapping mappingsp = MappingSP(mappingtc) waveforms = reader[event_slice] sp_arr = np.vstack(mapping.groupby("superpixel").pixel.apply(np.array)) avg_wfs = waveforms[:, sp_arr].mean((0, 2)) amplitudes = avg_wfs.max(1) hvs = hv_file_reader(hv_path) hv255 = np.where(hvs == 255) df = get_superpixel_mapping(mapping) camera = CameraImage.from_mapping(df) image = amplitudes camera.image = image camera.add_colorbar("Superpixel-Waveform Max (mV)") camera.highlight_pixels(hv255, 'red') camera.save(output_path) lt75 = np.where(amplitudes < 75) print(lt75)
def __init__(self, mapping): sp_mapping = get_superpixel_mapping(mapping) self.fig = plt.figure(figsize=(10, 5)) self.ax_trigger = self.fig.add_subplot(1, 1, 1) self.ci_trigger = self.create_image(sp_mapping, ax=self.ax_trigger, clabel="Trigger") self.n_superpixels = sp_mapping.index.size sp_zero = np.zeros(self.n_superpixels, dtype=bool) self.ci_trigger.image = sp_zero
def plot_superpixel(): """ Make a camera image plot for values that are per superpixel """ from target_calib import CameraConfiguration c = CameraConfiguration("1.1.0") m = c.GetMapping() df = get_superpixel_mapping(get_clp_mapping_from_tc_mapping(m)) camera = CameraImage.from_mapping(df) image = np.zeros(m.GetNSuperPixels()) image[::2] = 1 camera.image = image plt.show()
def main(): # path = get_astri_2019("d2019-06-10_ledflashers/flasher_comparison_May-June/unit0pattern-low_r1.tio") # path = get_astri_2019("d2019-06-10_ledflashers/flasher_comparison_May-June/Run13270_r1.tio") path = get_astri_2019( "d2019-06-10_ledflashers/flasher_comparison_May-June/Run13401_r1.tio") output_dir = path.replace("_r1.tio", "") reader = TIOReader(path, max_events=100) waveforms = reader[:].mean(0) mapping = get_superpixel_mapping(reader.mapping) n_pixels, n_samples = waveforms.shape n_sp = n_pixels // 4 correction = pd.read_csv(join(DIR, "sp_illumination_profile.dat"), sep='\t')['correction'].values sp_waveforms = waveforms.reshape((n_sp, 4, n_samples)).sum(1) sp_waveforms_corrected = sp_waveforms * correction[:, None] amplitude = sp_waveforms_corrected.max(1) median = np.median(amplitude) threshold = median * 1.10 trigger_off = amplitude > threshold # trigger_off[[ # TODO: Remove? # 355, 356, 357, 358, 359, 382, 375, 460, 459, 457, 458, 465, 289, 489, # 502, 254, 247, 154, 144, 56, 46, 39, 24, 25, 76 # ]] = True hv_off = np.zeros(n_sp, dtype=bool) hv_off[[24, 453]] = True print(f"SP Trigger OFF: {np.where(trigger_off)[0].tolist()}") print(f"SP HV OFF: {np.where(hv_off)[0].tolist()}") plot = CameraPlotter(mapping) plot.highlight_pixels(trigger_off, 'yellow') plot.highlight_pixels(hv_off, 'red') plot.plot_waveforms(sp_waveforms) plot.save(join(output_dir, "led.pdf")) plot.plot_waveforms(sp_waveforms_corrected) plot.save(join(output_dir, "uniform.pdf")) df = pd.DataFrame( dict( superpixel=np.arange(n_sp), hv_on=(~hv_off).astype(int), trigger_off=trigger_off.astype(int), )) df.to_csv(join(output_dir, "sp_settings.txt"), sep='\t', index=False)
def __init__(self, mapping): super().__init__() sp_mapping = get_superpixel_mapping(mapping) self.fig = plt.figure(figsize=(10, 5)) self.ax_spmax = self.fig.add_subplot(1, 2, 1) self.ax_trigger = self.fig.add_subplot(1, 2, 2) self.ci_spmax = self.create_image( sp_mapping, ax=self.ax_spmax, clabel="Superpixel-WF Max" ) self.ci_trigger = self.create_image( sp_mapping, ax=self.ax_trigger, clabel="Trigger" ) self.n_superpixels = sp_mapping.index.size sp_zero = np.zeros(self.n_superpixels, dtype=bool) self.ci_spmax.image = sp_zero self.ci_trigger.image = sp_zero self.highlight = self.ci_spmax.highlight_pixels(sp_zero, color='red')
def __init__(self, mapping): super().__init__() sp_mapping = get_superpixel_mapping(mapping) self.fig = plt.figure(figsize=(10, 10)) self.ax_spmax = self.fig.add_subplot(2, 2, 1) self.ax_spargmax = self.fig.add_subplot(2, 2, 2) self.ax_c = self.fig.add_subplot(2, 2, 3) self.ax_t = self.fig.add_subplot(2, 2, 4) self.ci_spmax = self.create_image( sp_mapping, ax=self.ax_spmax, clabel="Above Threshold" ) self.ci_spargmax = self.create_image( sp_mapping, ax=self.ax_spargmax, clabel="SP Argmax" ) self.ci_c = self.create_image( mapping, ax=self.ax_c, clabel="Extracted Charge (Photons)" ) self.ci_t = self.create_image( mapping, ax=self.ax_t, clabel="Pulse Time (ns)" ) self.n_pixels = mapping.index.size self.n_superpixels = sp_mapping.index.size pix_zero = np.zeros(self.n_pixels, dtype=bool) sp_zero = np.zeros(self.n_superpixels, dtype=bool) self.ci_spmax.image = sp_zero self.ci_spargmax.image = sp_zero self.ci_c.image = pix_zero self.ci_t.image = pix_zero self.highlights = dict( sp_max=self.ci_spmax.highlight_pixels(sp_zero, color='red'), sp_argmax=self.ci_spargmax.highlight_pixels(sp_zero, color='red'), c=self.ci_c.highlight_pixels(pix_zero, color='black', linewidth=0.05), t=self.ci_t.highlight_pixels(pix_zero, color='black', linewidth=0.05), )
def __init__(self, ip, port, sampleinterval=0.1, timewindow=10.0, size=(600, 350)): # PyQtGraph stuff self._interval = int(sampleinterval * 1000) self.app = QtGui.QApplication([]) self.win = pg.GraphicsWindow() self.win.setWindowTitle("Triggerpattern viewer") # data self.data = defaultdict( list) # {'hv_current':list(),'hv_voltage':list()} self.time = list() self.plts = {} self.curve_names = list() self.plot_time_window = 10 # self.win.addItem(pg.TextItem(text='HEJHEJHEJ', color=(200, 200, 200), html=None, anchor=(0, 0), border=None, fill=None, angle=0, rotateAxis=None),row=1 ) self.lastframeindicator = pg.LabelItem(text="") self.lastframe = datetime.now() self.win.addItem(self.lastframeindicator) self.gotdataindicator = pg.LabelItem( text='<font color="{}">{}</font>'.format("green", "connected")) self.win.addItem(self.gotdataindicator) self.win.nextRow() self.countersindicator = pg.LabelItem(text="") self.win.addItem(self.countersindicator) self.win.nextRow() self.last_uc_ev = 0 self.missed_counter = 0 self.readout_counter = 0 self._add_plot( "Trigger rate", ("Rate Hz", ""), ("Time", "min"), ["Nominal triggers"], # , "Busy triggers"], ) # self._add_plot( # "Slow signal amplitude", # ("Amplitude", "mV"), # ("Time", "min"), # ["total amplitude", "max amplitude X 10"], # ) self.win.nextRow() self.img = pg.ImageItem(levels=(0, 400)) self.p = self.win.addPlot() self.p.addItem(self.img) self.c = CameraConfiguration("1.1.0") self.m = self.c.GetMapping() from CHECLabPy.plotting.camera import CameraImage, CameraImageImshow from CHECLabPy.utils.mapping import ( get_clp_mapping_from_tc_mapping, get_superpixel_mapping, get_tm_mapping, ) self.sp_mapping = get_superpixel_mapping( get_clp_mapping_from_tc_mapping(self.m)) self.xpix = np.array(self.sp_mapping.xpix) self.ypix = np.array(self.sp_mapping.ypix) self.xmap = np.array(self.sp_mapping.row) self.ymap = np.array(self.sp_mapping.col) print(self.xmap.shape, self.ymap.shape) self.map = np.zeros((24, 24), dtype=np.uint64) for i in range(512): self.map[self.xmap[i], self.ymap[i]] = i self.map = self.map.flatten() from ssdaq.data._dataimpl.trigger_format import ( get_SP2bptrigg_mapping, get_bptrigg2SP_mapping, ) self.bptmap = get_bptrigg2SP_mapping() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateplots) self.timer.start(self._interval) self.tr_listener = subscribers.BasicTriggerSubscriber(port=port, ip=ip) self.tr_listener.start()
def main(): paths = dict( d190502= "/Volumes/ICYBOX/astri_onsky_archive/d2019-06-10_ledflashers/flasher_comparison_May-June/unit0pattern-low_r1.tio", d190508= "/Volumes/ICYBOX/astri_onsky_archive/d2019-06-10_ledflashers/flasher_comparison_May-June/Run13270_r1.tio", d190610= "/Volumes/ICYBOX/astri_onsky_archive/d2019-06-10_ledflashers/flasher_comparison_May-June/Run13401_r1.tio", ) readers = { key: TIOReader(path, max_events=100) for key, path in paths.items() } waveforms = {key: reader[:].mean(0) for key, reader in readers.items()} mapping = get_superpixel_mapping(readers['d190502'].mapping) pixelmasks = dict(d190428T2149=PixelMasks( get_calib_data("pixel_masks/d190428T2149.dat")), ) # Calculate coeff waveforms_coeff = waveforms['d190502'] n_pixels, n_samples = waveforms_coeff.shape n_sp = n_pixels // 4 waveforms_sp = waveforms_coeff.reshape((n_sp, 4, n_samples)).sum(1) coeff = (waveforms_sp.max(1).mean() / waveforms_sp.max(1))[:, None] sp_waveforms = { key: wfs.reshape((n_sp, 4, n_samples)).sum(1) for key, wfs in waveforms.items() } sp_waveforms_cal = {key: wfs * coeff for key, wfs in sp_waveforms.items()} trigger_off = dict() for key, wfs in sp_waveforms_cal.items(): amplitude = wfs.max(1) median = np.median(amplitude) threshold = median * 1.10 trigger_off[key] = amplitude > threshold trigger_off['d190610'][[ 355, 356, 357, 358, 359, 382, 375, 460, 459, 457, 458, 465, 289, 489, 502, 254, 247, 154, 144, 56, 46, 39, 24, 25, 76 ]] = True for key, sp in trigger_off.items(): print(f"{key}: f{np.where(sp)}") plots = GetPlot(mapping) plots['d190428T2149'].highlight_pixels(trigger_off['d190502']) plots['d190428T2149'].plot_waveforms(sp_waveforms['d190502']) plots['d190428T2149'].save(get_plot("d190611_led_flasher/led/d190502.pdf")) plots['d190428T2149'].plot_waveforms(sp_waveforms_cal['d190502']) plots['d190428T2149'].save( get_plot("d190611_led_flasher/coeff/d190502.pdf")) plots['d190428T2149'].reset_pixel_highlight() plots['d190428T2149'].highlight_pixels(trigger_off['d190508']) plots['d190428T2149'].plot_waveforms(sp_waveforms['d190508']) plots['d190428T2149'].save(get_plot("d190611_led_flasher/led/d190508.pdf")) plots['d190428T2149'].plot_waveforms(sp_waveforms_cal['d190508']) plots['d190428T2149'].save( get_plot("d190611_led_flasher/coeff/d190508.pdf")) plots['d190428T2149'].reset_pixel_highlight() plots['d190428T2149'].highlight_pixels(trigger_off['d190610']) plots['d190428T2149'].plot_waveforms(sp_waveforms['d190610']) plots['d190428T2149'].save(get_plot("d190611_led_flasher/led/d190610.pdf")) plots['d190428T2149'].plot_waveforms(sp_waveforms_cal['d190610']) plots['d190428T2149'].save( get_plot("d190611_led_flasher/coeff/d190610.pdf")) plots['d190428T2149'].reset_pixel_highlight() hv_off = [24, 453] hv_off_array = np.zeros(n_sp, dtype=bool) hv_off_array[hv_off] = True trigger_off_array = np.zeros(n_sp, dtype=bool) trigger_off_array[trigger_off['d190610']] = True df = pd.DataFrame( dict( superpixel=np.arange(n_sp), hv_on=(~hv_off_array).astype(int), trigger_off=trigger_off_array.astype(int), )) df.to_csv(get_plot("d190611_led_flasher/hv_list.txt"), sep='\t', index=False)