def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) self.reader_uncal = TargetioFileReader(input_path=self.path_uncal, **kwargs) self.reader_cal = TargetioFileReader(input_path=self.path_cal, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.fitter_uncal = CHECMSPEFitter(**kwargs) self.fitter_cal = CHECMSPEFitter(**kwargs) self.fitter_cal.range = [-3, 6] self.fitter_cal.initial = dict(norm=None, eped=0, eped_sigma=0.2, spe=1, spe_sigma=0.5, lambda_=0.2) first_event = self.reader_uncal.get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape
class Comparer(Tool): name = "Comparer" description = "Compare between two files to check the " \ "waveforms are identical." path1 = Unicode("", help="Path to a first file.").tag(config=True) path2 = Unicode("", help="Path to a second file.").tag(config=True) aliases = Dict( dict( p1='Comparer.path1', p2='Comparer.path2', max_events='TargetioFileReader.max_events', )) classes = List([ TargetioFileReader, TargetioR1Calibrator, ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader1 = None self.reader2 = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) if not self.path1 or not self.path2: raise FileNotFoundError("Both paths need to be set") self.reader1 = TargetioFileReader(**kwargs, input_path=self.path1) self.reader2 = TargetioFileReader(**kwargs, input_path=self.path2) assert self.reader1.num_events == self.reader2.num_events def start(self): n_events = self.reader1.num_events source1 = self.reader1.read() source2 = self.reader2.read() desc = "Looping through both files" for ev in trange(n_events, desc=desc): event1 = self.reader1.get_event(ev) event2 = self.reader2.get_event(ev) samples1 = event1.r1.tel[0].pe_samples samples2 = event2.r1.tel[0].pe_samples if (samples1 == 0).all(): samples1 = event1.r0.tel[0].adc_samples if (samples2 == 0).all(): samples2 = event1.r0.tel[0].adc_samples np.testing.assert_almost_equal(samples1, samples2, 1) self.log.info("All events match!") def finish(self): pass
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) if not self.path1 or not self.path2: raise FileNotFoundError("Both paths need to be set") self.reader1 = TargetioFileReader(**kwargs, input_path=self.path1) self.reader2 = TargetioFileReader(**kwargs, input_path=self.path2) assert self.reader1.num_events == self.reader2.num_events
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) if not self.r0_path or not self.r1_path: raise FileNotFoundError("Both r0 and r1 paths need to be set") self.reader_r0 = TargetioFileReader(**kwargs, input_path=self.r0_path) self.reader_r1 = TargetioFileReader(**kwargs, input_path=self.r1_path) self.r1 = TargetioR1Calibrator(**kwargs) assert self.reader_r0.num_events == self.reader_r1.num_events
def __init__(self, config, tool, **kwargs): """ Loop through event files. Parameters ---------- config : traitlets.loader.Config Configuration specified by config file or cmdline arguments. Used to set traitlet values. Set to None if no configuration to pass. tool : ctapipe.core.Tool Tool executable that is calling this component. Passes the correct logger to the component. Set to None if no Tool to pass. kwargs """ super().__init__(config=config, parent=tool, **kwargs) if self.single_file is not None: self.file_list = [self.single_file] if not self.file_list: raise ValueError("Please specify at least one input filepath") self.file_reader_list = [] for fn, fp in enumerate(self.file_list): if self.max_files is not None: if fn >= self.max_files: break fr = TargetioFileReader(config, tool, input_path=fp, max_events=self.max_events) self.file_reader_list.append(fr) self.num_readers = len(self.file_reader_list)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) for key, path in self.event_path_dict.items(): self.reader_dict[key] = TargetioFileReader(input_path=path, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECBrightFitter(**kwargs) self.dead = Dead() first_event = list(self.reader_dict.values())[0].get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape script = "checm_paper_adc2pe_application" self.p_comparison = ADC2PEPlotter(**kwargs, script=script, figure_name="adc2pe_comparison", shape='wide') self.p_tmspread = TMSpreadPlotter(**kwargs, script=script, figure_name="tmspread", shape='wide') self.p_dist = GMDistributionPlotter(**kwargs, script=script, figure_name="gm_distribution", shape='wide')
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) self.fw_calibrator = FWCalibrator(**kwargs) r1_0320 = TargetioR1Calibrator(pedestal_path='/Volumes/gct-jason/data/170320/pedestal/Run04109_ped.tcal', tf_path='/Volumes/gct-jason/data/170320/tf/Run04110-04159_tf.tcal', pe_path='/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_1100.tcal', **kwargs) r1_0319 = TargetioR1Calibrator(pedestal_path='/Volumes/gct-jason/data/170319/linearity/pedestal/Run04051_ped.tcal', tf_path='/Volumes/gct-jason/data/170319/linearity/tf/Run04001-04050_tf.tcal', pe_path='/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_1100.tcal', **kwargs) dfl = [] base_path = "/Volumes/gct-jason/data/170320/linearity/Run{:05}_r0.tio" dfl.append(dict(path=base_path.format(4160), type="LS64", cal=True, level=1250, r1=r1_0320)) dfl.append(dict(path=base_path.format(4161), type="LS64", cal=True, level=1450, r1=r1_0320)) dfl.append(dict(path=base_path.format(4162), type="LS64", cal=True, level=1650, r1=r1_0320)) dfl.append(dict(path=base_path.format(4163), type="LS64", cal=True, level=1850, r1=r1_0320)) dfl.append(dict(path=base_path.format(4164), type="LS64", cal=True, level=2050, r1=r1_0320)) dfl.append(dict(path=base_path.format(4165), type="LS64", cal=True, level=2250, r1=r1_0320)) dfl.append(dict(path=base_path.format(4166), type="LS64", cal=True, level=2450, r1=r1_0320)) dfl.append(dict(path=base_path.format(4167), type="LS64", cal=True, level=2650, r1=r1_0320)) dfl.append(dict(path=base_path.format(4168), type="LS64", cal=True, level=2850, r1=r1_0320)) dfl.append(dict(path=base_path.format(4169), type="LS64", cal=True, level=3050, r1=r1_0320)) base_path = "/Volumes/gct-jason/data/170319/linearity/linearity/Run{:05}_r0.tio" dfl.append(dict(path=base_path.format(3986), type="LS62", cal=True, level=1250, r1=r1_0319)) dfl.append(dict(path=base_path.format(3987), type="LS62", cal=True, level=1450, r1=r1_0319)) dfl.append(dict(path=base_path.format(3988), type="LS62", cal=True, level=1650, r1=r1_0319)) dfl.append(dict(path=base_path.format(3989), type="LS62", cal=True, level=1850, r1=r1_0319)) dfl.append(dict(path=base_path.format(3990), type="LS62", cal=True, level=2050, r1=r1_0319)) dfl.append(dict(path=base_path.format(3991), type="LS62", cal=True, level=2250, r1=r1_0319)) dfl.append(dict(path=base_path.format(3992), type="LS62", cal=True, level=2450, r1=r1_0319)) dfl.append(dict(path=base_path.format(3993), type="LS62", cal=True, level=2650, r1=r1_0319)) dfl.append(dict(path=base_path.format(3994), type="LS62", cal=True, level=2850, r1=r1_0319)) dfl.append(dict(path=base_path.format(3995), type="LS62", cal=True, level=3050, r1=r1_0319)) for d in dfl: d['reader'] = TargetioFileReader(input_path=d['path'], **kwargs) self.df_file = pd.DataFrame(dfl) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.dummy_event = dfl[0]['reader'].get_event(0) telid = list(self.dummy_event.r0.tels_with_data)[0] r1 = self.dummy_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape script = "checm_paper_recovery" self.p_scatter_pix = Scatter(**kwargs, script=script, figure_name="recovery_lookup")
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170319/linearity/linearity/Run03991_r1_pe.tio' # filepath = '/Volumes/gct-jason/data/170320/linearity/Run04164_r1_pe.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.fw_calibrator = FWCalibrator(**kwargs) self.cfmaker = CfMaker(32)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) self.path_dict[ '800'] = '/Volumes/gct-jason/data/170310/hv/Run00904_r1_adc.tio' self.path_dict[ '900'] = '/Volumes/gct-jason/data/170310/hv/Run00914_r1_adc.tio' self.path_dict[ '1000'] = '/Volumes/gct-jason/data/170310/hv/Run00924_r1_adc.tio' self.path_dict[ '1100'] = '/Volumes/gct-jason/data/170310/hv/Run00934_r1_adc.tio' self.path_dict[ '800gm'] = '/Volumes/gct-jason/data/170319/gainmatching/gainmatched/Run03983_r1_adc.tio' self.path_dict[ '900gm'] = '/Volumes/gct-jason/data/170319/gainmatching/gainmatched/Run03984_r1_adc.tio' self.path_dict[ '1000gm'] = '/Volumes/gct-jason/data/170320/linearity/Run04174_r1_adc.tio' #'/Volumes/gct-jason/data/170319/gainmatching/gainmatched/Run03985_r1_adc.tio' # self.path_dict['800'] = '/Volumes/gct-jason/data/170310/hv/Run00904_r1.tio' # self.path_dict['900'] = '/Volumes/gct-jason/data/170310/hv/Run00914_r1.tio' # self.path_dict['1000'] = '/Volumes/gct-jason/data/170310/hv/Run00924_r1.tio' # self.path_dict['1100'] = '/Volumes/gct-jason/data/170310/hv/Run00934_r1.tio' # self.path_dict['800gm'] = '/Volumes/gct-jason/data/170319/gainmatching/gainmatched/Run03983_r1.tio' # self.path_dict['900gm'] = '/Volumes/gct-jason/data/170319/gainmatching/gainmatched/Run03984_r1.tio' # self.path_dict['1000gm'] = '/Volumes/gct-jason/data/170320/linearity/Run04174_r1.tio' ped = '/Volumes/gct-jason/data/170310/pedestal/Run00843_ped.tcal' pedgm = '/Volumes/gct-jason/data/170319/gainmatching/pedestal/Run03932_ped.tcal' tf = '/Volumes/gct-jason/data/170310/tf/Run00844-00893_tf.tcal' for key, val in self.path_dict.items(): # p = ped # if 'gm' in key: # p = pedgm # adc2pe = '/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_{}.tcal'.format(key) # self.r1_dict[key] = TargetioR1Calibrator(pedestal_path=p, # tf_path=tf, # pe_path='', # **kwargs) self.reader_dict[key] = TargetioFileReader(input_path=val, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECBrightFitter(**kwargs) self.dead = Dead() first_event = list(self.reader_dict.values())[0].get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) # Bypass error message when input_path is None if self.input_path is not None: self.file_reader = TargetioFileReader(**kwargs, input_path=self.input_path) self.ped = PedestalSubtractor(**kwargs) self.p_cellspread = PedCellSpread(**kwargs) self.p_pixelspread = PedPixelSpread(**kwargs) self.p_pedselect = PedSelector(**kwargs) self.p_devcellspread = StddevCellSpread(**kwargs) self.p_devpixelspread = StddevPixelSpread(**kwargs) self.p_respixelspread = ResidualPixelSpread(**kwargs) self.p_rescameraspread = ResidualCameraSpread(**kwargs) self.p_reseventspread = ResidualEventSpread(**kwargs) self.p_resselect = ResidualSelector(**kwargs)
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1_adc.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECMSPEFitter(**kwargs) self.fitter.range = [-30, 160] self.dead = Dead() self.fw_calibrator = FWCalibrator(**kwargs) script = "filter_wheel" self.p_attenuation = Scatter(**kwargs, script=script, figure_name="attenuation") self.p_pe = Scatter(**kwargs, script=script, figure_name="pe")
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" data_config = self.config.copy() data_config['WaveformCleanerFactory'] = Config(cleaner='CHECMWaveformCleanerLocal') mc_config = self.config.copy() data_kwargs = dict(config=data_config, tool=self) mc_kwargs = dict(config=mc_config, tool=self) filepath = '/Volumes/gct-jason/data/170330/onsky-mrk501/Run05477_r1.tio' reader = TargetioFileReader(input_path=filepath, **data_kwargs) filepath = '/Users/Jason/Software/outputs/sim_telarray/meudon_cr/simtel_proton_nsb50_thrs30_1petal_rndm015_heide.gz' # filepath = '/Users/Jason/Software/outputs/sim_telarray/meudon_cr/simtel_proton_nsb50_thrs30.gz' reader_mc = HessioFileReader(input_path=filepath, **mc_kwargs) calibrator = CameraCalibrator(origin=reader.origin, **data_kwargs) calibrator_mc = CameraCalibrator(origin=reader_mc.origin, **mc_kwargs) first_event = reader.get_event(0) telid = list(first_event.r0.tels_with_data)[0] pos = first_event.inst.pixel_pos[telid] foclen = first_event.inst.optical_foclen[telid] geom = CameraGeometry.guess(*pos, foclen) first_event = reader_mc.get_event(0) telid = list(first_event.r0.tels_with_data)[0] pos_mc = first_event.inst.pixel_pos[telid] foclen = first_event.inst.optical_foclen[telid] geom_mc = CameraGeometry.guess(*pos_mc, foclen) d1 = dict(type='Data', reader=reader, calibrator=calibrator, pos=pos, geom=geom, t1=20, t2=10) d2 = dict(type='MC', reader=reader_mc, calibrator=calibrator_mc, pos=pos_mc, geom=geom_mc, t1=20, t2=10) self.reader_df = pd.DataFrame([d1, d2]) p_kwargs = data_kwargs p_kwargs['script'] = "checm_paper_hillas" p_kwargs['figure_name'] = "all_images" self.p_allimage = AllImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "all_peak_time_images" self.p_alltimeimage = PeakTimePlotter(**p_kwargs) p_kwargs['figure_name'] = "all_mc_images" self.p_allmcimage = AllImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "zero_width_images" self.p_zwimage = ZeroWidthImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "zero_width_mc_images" self.p_zwmcimage = ZeroWidthImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "muon_images" self.p_muonimage = MuonImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "bright_images" self.p_brightimage = BrightImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "count_image" self.p_countimage = CountPlotter(**p_kwargs) p_kwargs['figure_name'] = "whole_distribution" self.p_whole_dist = WholeDist(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "width_vs_length" self.p_widthvslength = WidthVsLength(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "size_vs_length" self.p_sizevslength = SizeVsLength(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "width_div_length" self.p_widthdivlength = WidthDivLength(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "length_div_size" self.p_lengthdivsize = LengthDivSize(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "pair_plot" self.p_pair = PairPlotter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "pair_mc_plot" self.p_mc_pair = PairPlotter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "length" self.p_length = LengthPlotter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "width" self.p_width = WidthPlotter(**p_kwargs, shape='wide')
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1_adc.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1.tio' self.reader_pe = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECMSPEFitter(**kwargs) self.fitter.range = [-30, 160] self.fitter_pe = CHECMSPEFitter(**kwargs) self.fitter_pe.range = [-1, 6] self.fitter_pe.initial = dict(norm=None, eped=0, eped_sigma=0.2, spe=1, spe_sigma=0.5, lambda_=0.2) self.dead = Dead() script = "checm_paper_adc2pe" self.p_pixelspe = PixelSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_pixel1559") self.p_tmspe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24") self.p_tmspe_pe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24_pe") self.p_adc2pe = ADC2PEPlotter(**kwargs, script=script, figure_name="adc2pe", shape='square') self.p_adc2pe_1100tm = ADC2PE1100VTMPlotter( **kwargs, script=script, figure_name="adc2pe_1100V_tms", shape='wide') self.p_adc2pe_1100tm_stats = ADC2PE1100VTMStatsPlotter( **kwargs, script=script, figure_name="adc2pe_1100V_tms_stats", shape='wide') self.p_eped = Hist(**kwargs, script=script, figure_name="f_eped", shape='square') self.p_eped_sigma = Hist(**kwargs, script=script, figure_name="f_eped_sigma", shape='square') self.p_spe = Hist(**kwargs, script=script, figure_name="f_spe", shape='square') self.p_spe_sigma = Hist(**kwargs, script=script, figure_name="f_spe_sigma", shape='square') self.p_lambda = Hist(**kwargs, script=script, figure_name="f_lambda", shape='square') self.p_enf = Hist(**kwargs, script=script, figure_name="f_enf", shape='square')
class ADC2PEPlots(Tool): name = "ADC2PEPlots" description = "Create plots related to adc2pe" aliases = Dict(dict(max_events='TargetioFileReader.max_events')) classes = List([ TargetioFileReader, TargetioR1Calibrator, ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader = None self.reader_pe = None self.dl0 = None self.dl1 = None self.fitter = None self.fitter_pe = None self.dead = None self.n_pixels = None self.n_samples = None self.spe_path = "/Volumes/gct-jason/data/170314/spe/Run00073_r0/extract_spe/spe.npy" self.gm_path = "/Volumes/gct-jason/data/170310/hv/gain_matching_coeff.npz" self.p_pixelspe = None self.p_tmspe = None self.p_tmspe_pe = None self.p_adc2pe = None self.p_adc2pe_1100tm = None self.p_adc2pe_1100tm_stats = None self.p_eped = None self.p_eped_sigma = None self.p_spe = None self.p_spe_sigma = None self.p_lambda = None self.p_enf = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1_adc.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1.tio' self.reader_pe = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECMSPEFitter(**kwargs) self.fitter.range = [-30, 160] self.fitter_pe = CHECMSPEFitter(**kwargs) self.fitter_pe.range = [-1, 6] self.fitter_pe.initial = dict(norm=None, eped=0, eped_sigma=0.2, spe=1, spe_sigma=0.5, lambda_=0.2) self.dead = Dead() script = "checm_paper_adc2pe" self.p_pixelspe = PixelSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_pixel1559") self.p_tmspe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24") self.p_tmspe_pe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24_pe") self.p_adc2pe = ADC2PEPlotter(**kwargs, script=script, figure_name="adc2pe", shape='square') self.p_adc2pe_1100tm = ADC2PE1100VTMPlotter( **kwargs, script=script, figure_name="adc2pe_1100V_tms", shape='wide') self.p_adc2pe_1100tm_stats = ADC2PE1100VTMStatsPlotter( **kwargs, script=script, figure_name="adc2pe_1100V_tms_stats", shape='wide') self.p_eped = Hist(**kwargs, script=script, figure_name="f_eped", shape='square') self.p_eped_sigma = Hist(**kwargs, script=script, figure_name="f_eped_sigma", shape='square') self.p_spe = Hist(**kwargs, script=script, figure_name="f_spe", shape='square') self.p_spe_sigma = Hist(**kwargs, script=script, figure_name="f_spe_sigma", shape='square') self.p_lambda = Hist(**kwargs, script=script, figure_name="f_lambda", shape='square') self.p_enf = Hist(**kwargs, script=script, figure_name="f_enf", shape='square') def start(self): n_events = self.reader.num_events first_event = self.reader.get_event(0) telid = list(first_event.r0.tels_with_data)[0] n_pixels, n_samples = first_event.r1.tel[telid].pe_samples[0].shape ### SPE values from fit _______________________________________________ # Prepare storage array dl1 = np.zeros((n_events, n_pixels)) dl1_pe = np.zeros((n_events, n_pixels)) hist_pix1559 = None edges_pix1559 = None between_pix1559 = None fit_pix1559 = None fitx_pix1559 = None hist_tm24 = np.zeros((64, self.fitter.nbins)) edges_tm24 = np.zeros((64, self.fitter.nbins + 1)) between_tm24 = np.zeros((64, self.fitter.nbins)) hist_tm24_pe = np.zeros((64, self.fitter.nbins)) edges_tm24_pe = np.zeros((64, self.fitter.nbins + 1)) between_tm24_pe = np.zeros((64, self.fitter.nbins)) f_eped = np.zeros(n_pixels) f_eped_sigma = np.zeros(n_pixels) f_spe = np.zeros(n_pixels) f_spe_sigma = np.zeros(n_pixels) f_lambda = np.zeros(n_pixels) source = self.reader.read() desc = "Looping through file" for event in tqdm(source, total=n_events, desc=desc): index = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1[index] = event.dl1.tel[telid].image source = self.reader_pe.read() desc = "Looping through file (pe)" for event in tqdm(source, total=n_events, desc=desc): index = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1_pe[index] = event.dl1.tel[telid].image desc = "Fitting pixels" for pix in trange(n_pixels, desc=desc): tm = pix // 64 tmpix = pix % 64 if not self.fitter.apply(dl1[:, pix]): self.log.warning("Pixel {} couldn't be fit".format(pix)) continue if pix == 1559: hist_pix1559 = self.fitter.hist edges_pix1559 = self.fitter.edges between_pix1559 = self.fitter.between fit_pix1559 = self.fitter.fit fitx_pix1559 = self.fitter.fit_x if tm == 24: hist_tm24[tmpix] = self.fitter.hist edges_tm24[tmpix] = self.fitter.edges between_tm24[tmpix] = self.fitter.between f_eped[pix] = self.fitter.coeff['eped'] f_eped_sigma[pix] = self.fitter.coeff['eped_sigma'] f_spe[pix] = self.fitter.coeff['spe'] f_spe_sigma[pix] = self.fitter.coeff['spe_sigma'] f_lambda[pix] = self.fitter.coeff['lambda_'] f_eped = checm_dac_to_volts(f_eped) f_eped_sigma = checm_dac_to_volts(f_eped_sigma) f_spe = checm_dac_to_volts(f_spe) f_spe_sigma = checm_dac_to_volts(f_spe_sigma) f_eped = self.dead.mask1d(f_eped).compressed() f_eped_sigma = self.dead.mask1d(f_eped_sigma).compressed() f_spe = self.dead.mask1d(f_spe).compressed() f_spe_sigma = self.dead.mask1d(f_spe_sigma).compressed() f_lambda = self.dead.mask1d(f_lambda).compressed() edges_pix1559 = checm_dac_to_volts(edges_pix1559) between_pix1559 = checm_dac_to_volts(between_pix1559) fitx_pix1559 = checm_dac_to_volts(fitx_pix1559) edges_tm24 = checm_dac_to_volts(edges_tm24) between_tm24 = checm_dac_to_volts(edges_tm24) desc = "Fitting pixels (pe)" for pix in trange(n_pixels, desc=desc): tm = pix // 64 tmpix = pix % 64 if tm != 24: continue if not self.fitter_pe.apply(dl1_pe[:, pix]): self.log.warning("Pixel {} couldn't be fit".format(pix)) continue hist_tm24_pe[tmpix] = self.fitter_pe.hist edges_tm24_pe[tmpix] = self.fitter_pe.edges between_tm24_pe[tmpix] = self.fitter_pe.between ### SPE values for each hv setting ____________________________________ kwargs = dict(config=self.config, tool=self, spe_path=self.spe_path, gain_matching_path=self.gm_path) a2p = TargetioADC2PECalibrator(**kwargs) hv_dict = dict() hv_dict['800'] = [800] * 2048 hv_dict['900'] = [900] * 2048 hv_dict['1000'] = [1000] * 2048 hv_dict['1100'] = [1100] * 2048 hv_dict['800gm'] = [a2p.gm800[i // 64] for i in range(2048)] hv_dict['900gm'] = [a2p.gm900[i // 64] for i in range(2048)] hv_dict['1000gm'] = [a2p.gm1000[i // 64] for i in range(2048)] df_list = [] for key, l in hv_dict.items(): hv = int(key.replace("gm", "")) gm = 'gm' in key gm_t = 'Gain-matched' if 'gm' in key else 'Non-gain-matched' for pix in range(n_pixels): if pix in self.dead.dead_pixels: continue adc2pe = a2p.get_adc2pe_at_hv(l[pix], pix) df_list.append( dict(key=key, hv=hv, gm=gm, gm_t=gm_t, pixel=pix, tm=pix // 64, spe=1 / adc2pe)) df = pd.DataFrame(df_list) df = df.sort_values(by='gm', ascending=True) df = df.assign(spe_mv=checm_dac_to_volts(df['spe'])) # Create figures self.p_pixelspe.create(hist_pix1559, edges_pix1559, between_pix1559, fit_pix1559, fitx_pix1559) self.p_tmspe.create(hist_tm24, edges_tm24, between_tm24, "V ns") self.p_tmspe_pe.create(hist_tm24_pe, edges_tm24_pe, between_tm24_pe, "p.e.", 1) self.p_adc2pe.create(df) self.p_adc2pe_1100tm.create(df) self.p_adc2pe_1100tm_stats.create(df) self.p_eped.create(f_eped, "Pedestal (V ns)") self.p_eped_sigma.create(f_eped_sigma, "Pedestal Sigma (V ns)") self.p_spe.create(f_spe, "SPE (V ns)") self.p_spe_sigma.create(f_spe_sigma, "SPE Sigma (V ns)") self.p_lambda.create(f_lambda, "Illumination (Photoelectrons)") enf = np.sqrt(f_spe_sigma**2 - f_eped_sigma**2) / f_spe self.p_enf.create(enf, "Relative SPE Width") def finish(self): # Save figures self.p_pixelspe.save() self.p_tmspe.save() self.p_tmspe_pe.save() self.p_adc2pe.save() self.p_adc2pe_1100tm.save() self.p_adc2pe_1100tm_stats.save() self.p_eped.save() self.p_eped_sigma.save() self.p_spe.save() self.p_spe_sigma.save() self.p_lambda.save() self.p_enf.save()
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170322/led/Run04345_r0.tio' self.reader_led = TargetioFileReader(input_path=filepath, **kwargs) filepath = '/Volumes/gct-jason/data/170320/linearity/Run04167_r0.tio' self.reader_laser = TargetioFileReader(input_path=filepath, **kwargs) extractor = LocalPeakIntegrator(**kwargs) self.r1_led = TargetioR1Calibrator( pedestal_path= '/Volumes/gct-jason/data/170322/pedestal/Run04240_ped.tcal', tf_path='/Volumes/gct-jason/data/170322/tf/Run04277-04327_tf.tcal', pe_path= '/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_800gm_c1.tcal', **kwargs, ) self.r1_laser = TargetioR1Calibrator( pedestal_path= '/Volumes/gct-jason/data/170320/pedestal/Run04109_ped.tcal', tf_path='/Volumes/gct-jason/data/170320/tf/Run04110-04159_tf.tcal', pe_path= '/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_1100.tcal', **kwargs, ) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, **kwargs) self.dead = Dead() self.n_events_led = self.reader_led.num_events first_event = self.reader_led.get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape p_kwargs = kwargs p_kwargs['script'] = "checm_paper_timing" p_kwargs['figure_name'] = "led_eid_vs_fci" self.p_led_eidvsfci = Scatter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_time_vs_tack" self.p_led_timevstack = Scatter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_bp_vs_tack" self.p_led_bpvstack = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_eid_vs_t" self.p_led_eidvst = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_eid_vs_tgrad" self.p_led_eidvstgrad = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_t_vs_tgrad" self.p_led_tvstgrad = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_t_vs_charge" self.p_led_tvscharge = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_tgrad_vs_charge" self.p_led_tgradvscharge = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_eid{}_wavg".format( self.eoi) self.p_led_1deoicomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_allevents_wavg".format( self.eoi) self.p_led_1dcomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_eid{}".format(self.eoi) self.p_led_1deoicomp = WaveformHist1DInt(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_allevents".format( self.eoi) self.p_led_1dcomp = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_image_tgrad_eid{}".format(self.eoi) self.p_led_imageeoitgrad = ImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "laser_1D_comparison_eid{}_wavg".format( self.eoi) self.p_laser_1deoicomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_allevents_wavg".format( self.eoi) self.p_laser_1dcomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_eid{}".format(self.eoi) self.p_laser_1deoicomp = WaveformHist1DInt(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_allevents".format( self.eoi) self.p_laser_1dcomp = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_finalmethod" self.p_laser_1d_final = WaveformHist1D(**p_kwargs, shape='square') p_kwargs['figure_name'] = "laser_1D_finalmethod_pix" self.p_laser_1d_final_pix = WaveformHist1D(**p_kwargs, shape='square') p_kwargs['figure_name'] = "laser_image_tgrad_eid{}".format(self.eoi) self.p_laser_imageeoitgrad = ImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "laser_fwhm_allevents" self.p_laser_fwhm = WaveformHist1DInt(**p_kwargs, shape='wide')
class TimingExtractor(Tool): name = "TimingExtractor" description = "Loop through a file to extract the timing information" aliases = Dict(dict(max_events='TargetioFileReader.max_events', )) classes = List([ TargetioFileReader, ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader_led = None self.reader_laser = None self.r1_led = None self.r1_laser = None self.dl0 = None self.dl1 = None self.dead = None self.df = None self.n_events_led = None self.n_pixels = None self.n_samples = None self.p_led_eidvsfci = None self.p_led_timevstack = None self.p_led_bpvstack = None self.p_led_eidvst = None self.p_led_eidvstgrad = None self.p_led_tvstgrad = None self.p_led_tvscharge = None self.p_led_tgradvscharge = None self.p_led_1deoicomp_wavg = None self.p_led_1dcomp_wavg = None self.p_led_1deoicomp = None self.p_led_1dcomp = None self.p_led_imageeoitgrad = None self.p_laser_1deoicomp_wavg = None self.p_laser_1dcomp_wavg = None self.p_laser_1deoicomp = None self.p_laser_1dcomp = None self.p_laser_1d_final = None self.p_laser_1d_final_pix = None self.p_laser_imageeoitgrad = None self.p_laser_fwhm = None self.eoi = 4 def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170322/led/Run04345_r0.tio' self.reader_led = TargetioFileReader(input_path=filepath, **kwargs) filepath = '/Volumes/gct-jason/data/170320/linearity/Run04167_r0.tio' self.reader_laser = TargetioFileReader(input_path=filepath, **kwargs) extractor = LocalPeakIntegrator(**kwargs) self.r1_led = TargetioR1Calibrator( pedestal_path= '/Volumes/gct-jason/data/170322/pedestal/Run04240_ped.tcal', tf_path='/Volumes/gct-jason/data/170322/tf/Run04277-04327_tf.tcal', pe_path= '/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_800gm_c1.tcal', **kwargs, ) self.r1_laser = TargetioR1Calibrator( pedestal_path= '/Volumes/gct-jason/data/170320/pedestal/Run04109_ped.tcal', tf_path='/Volumes/gct-jason/data/170320/tf/Run04110-04159_tf.tcal', pe_path= '/Users/Jason/Software/CHECAnalysis/targetpipe/adc2pe/adc2pe_1100.tcal', **kwargs, ) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, **kwargs) self.dead = Dead() self.n_events_led = self.reader_led.num_events first_event = self.reader_led.get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape p_kwargs = kwargs p_kwargs['script'] = "checm_paper_timing" p_kwargs['figure_name'] = "led_eid_vs_fci" self.p_led_eidvsfci = Scatter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_time_vs_tack" self.p_led_timevstack = Scatter(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_bp_vs_tack" self.p_led_bpvstack = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_eid_vs_t" self.p_led_eidvst = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_eid_vs_tgrad" self.p_led_eidvstgrad = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_t_vs_tgrad" self.p_led_tvstgrad = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_t_vs_charge" self.p_led_tvscharge = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_tgrad_vs_charge" self.p_led_tgradvscharge = Hist2D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_eid{}_wavg".format( self.eoi) self.p_led_1deoicomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_allevents_wavg".format( self.eoi) self.p_led_1dcomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_eid{}".format(self.eoi) self.p_led_1deoicomp = WaveformHist1DInt(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_1D_comparison_allevents".format( self.eoi) self.p_led_1dcomp = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "led_image_tgrad_eid{}".format(self.eoi) self.p_led_imageeoitgrad = ImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "laser_1D_comparison_eid{}_wavg".format( self.eoi) self.p_laser_1deoicomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_allevents_wavg".format( self.eoi) self.p_laser_1dcomp_wavg = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_eid{}".format(self.eoi) self.p_laser_1deoicomp = WaveformHist1DInt(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_comparison_allevents".format( self.eoi) self.p_laser_1dcomp = WaveformHist1D(**p_kwargs, shape='wide') p_kwargs['figure_name'] = "laser_1D_finalmethod" self.p_laser_1d_final = WaveformHist1D(**p_kwargs, shape='square') p_kwargs['figure_name'] = "laser_1D_finalmethod_pix" self.p_laser_1d_final_pix = WaveformHist1D(**p_kwargs, shape='square') p_kwargs['figure_name'] = "laser_image_tgrad_eid{}".format(self.eoi) self.p_laser_imageeoitgrad = ImagePlotter(**p_kwargs) p_kwargs['figure_name'] = "laser_fwhm_allevents" self.p_laser_fwhm = WaveformHist1DInt(**p_kwargs, shape='wide') def start(self): # df_list = [] # # dead = self.dead.get_pixel_mask() # kernel = general_gaussian(3, p=1.0, sig=1) # x_base = np.arange(self.n_samples) # x_interp = np.linspace(0, self.n_samples - 1, 300) # ind = np.indices((self.n_pixels, x_interp.size))[1] # r_ind = ind[:, ::-1] # ind_x = x_interp[ind] # r_ind_x = x_interp[r_ind] # # readers = [self.reader_led, self.reader_laser] # r1s = [self.r1_led, self.r1_laser] # run_type = ['led', 'laser'] # # for reader, r1_cal, rt in zip(readers, r1s, run_type): # run = reader.filename # n_events = reader.num_events # source = reader.read() # desc = "Processing Events for {} run".format(rt) # for event in tqdm(source, total=n_events, desc=desc): # ev = event.count # event_id = event.r0.event_id # time = event.trig.gps_time.value # tack = event.meta['tack'] # fci = np.copy(event.r0.tel[0].first_cell_ids) # bp = event.r0.tel[0].blockphase # # r1_cal.calibrate(event) # self.dl0.reduce(event) # self.dl1.calibrate(event) # r0 = event.r0.tel[0].adc_samples[0] # r1 = event.r1.tel[0].pe_samples[0] # dl1 = event.dl1.tel[0].image[0] # # smooth_flat = np.convolve(r1.ravel(), kernel, "same") # smoothed = np.reshape(smooth_flat, r1.shape) # samples_std = np.std(r1, axis=1) # smooth_baseline_std = np.std(smoothed, axis=1) # with np.errstate(divide='ignore', invalid='ignore'): # smoothed *= (samples_std / smooth_baseline_std)[:, None] # smoothed[~np.isfinite(smoothed)] = 0 # r1 = smoothed # # f = interpolate.interp1d(x_base, r1, kind=3, axis=1) # r1 = f(x_interp) # # grad = np.gradient(r1)[1] # # saturated = np.any(r0 < 10, 1) # low_pe = np.all(r1 < 10, 1) # mask = dead | saturated | low_pe # # t_max = x_interp[np.argmax(r1, 1)] # t_start = t_max - 2 # t_end = t_max + 2 # t_window = (ind_x >= t_start[..., None]) & (ind_x < t_end[..., None]) # t_windowed = np.ma.array(r1, mask=~t_window) # t_windowed_ind = np.ma.array(ind_x, mask=~t_window) # t_avg = np.ma.average(t_windowed_ind, weights=t_windowed, axis=1) # # t_grad_max = x_interp[np.argmax(grad, 1)] # t_grad_start = t_grad_max - 2 # t_grad_end = t_grad_max + 2 # t_grad_window = (ind_x >= t_grad_start[..., None]) & (ind_x < t_grad_end[..., None]) # t_grad_windowed = np.ma.array(grad, mask=~t_grad_window) # t_grad_windowed_ind = np.ma.array(ind_x, mask=~t_grad_window) # t_grad_avg = np.ma.average(t_grad_windowed_ind, weights=t_grad_windowed, axis=1) # # max_ = np.max(r1, axis=1) # reversed_ = r1[:, ::-1] # peak_time_i = np.ones(r1.shape) * t_max[:, None] # mask_before = np.ma.masked_less(ind_x, peak_time_i).mask # mask_after = np.ma.masked_greater(r_ind_x, peak_time_i).mask # masked_bef = np.ma.masked_array(r1, mask_before) # masked_aft = np.ma.masked_array(reversed_, mask_after) # half_max = max_/2 # d_l = np.diff(np.sign(half_max[:, None] - masked_aft)) # d_r = np.diff(np.sign(half_max[:, None] - masked_bef)) # t_l = x_interp[r_ind[0, np.argmax(d_l, axis=1) + 1]] # t_r = x_interp[ind[0, np.argmax(d_r, axis=1) + 1]] # fwhm = t_r - t_l # # # if (t_grad > 60).any(): # # print(event_id) # # # if event_id == 23: # continue # # d = dict(run=run, # type=rt, # index=ev, # id=event_id, # time=time, # tack=tack, # fci=fci, # bp=bp, # mask=mask, # dl1=dl1, # t=t_max, # t_grad=t_grad_max, # t_avg=t_avg, # t_grad_avg=t_grad_avg, # fwhm=fwhm # ) # df_list.append(d) # # self.df = pd.DataFrame(df_list) # store = pd.HDFStore('/Users/Jason/Downloads/timing.h5') # store['df'] = self.df store = pd.HDFStore('/Users/Jason/Downloads/timing.h5') self.df = store['df'] def finish(self): # LED DATA df = self.df.loc[self.df['type'] == 'led'] eid = df['id'] time = df['time'] tack = df['tack'] fci = np.ma.vstack(df['fci']) bp = np.ma.vstack(df['bp']) dl1 = np.ma.vstack(df['dl1']) t_avg = np.ma.vstack(df['t_avg']) t_grad_avg = np.ma.vstack(df['t_grad_avg']) t = np.ma.vstack(df['t']) t_grad = np.ma.vstack(df['t_grad']) mask = np.vstack(df['mask']) # bp.mask = mask dl1.mask = mask t_avg.mask = mask t_grad_avg.mask = mask t.mask = mask t_grad.mask = mask # Scatter self.p_led_eidvsfci.create(eid, fci, 'Event ID', 'First Cell ID') self.p_led_timevstack.create(time, tack, 'Time', 'Tack') # 2D histograms eid_pix = eid[:, None] * np.ma.ones((eid.size, self.n_pixels)) eid_pix.mask = mask eid_pix_c = eid_pix.compressed() tack_pix = tack[:, None] * np.ma.ones((tack.size, self.n_pixels)) # tack_pix.mask = mask tack_pix_c = tack_pix.compressed() bp_c = bp.compressed() dl1_c = dl1.compressed() t_c = t_avg.compressed() t_grad_c = t_grad_avg.compressed() n_bp = int(bp_c.max() - bp_c.min()) n_t = int(t_c.max() - t_c.min()) n_tgrad = int(t_grad_c.max() - t_grad_c.min()) self.p_led_bpvstack.create(bp_c, n_bp, tack_pix_c, self.n_events_led, 'Blockphase', 'Tack') self.p_led_eidvst.create(eid_pix_c, self.n_events_led, t_c, n_t, 'Event ID', 'Peak Time') self.p_led_eidvstgrad.create(eid_pix_c, self.n_events_led, t_grad_c, n_tgrad, 'Event ID', 'Gradient Peak Time') self.p_led_tvstgrad.create(t_c, n_t, t_grad_c, n_tgrad, 'Peak Time', 'Gradient Peak Time') self.p_led_tvscharge.create(t_c, n_t, dl1_c, 100, 'Peak Time', 'Charge (p.e.)') self.p_led_tgradvscharge.create(t_grad_c, n_tgrad, dl1_c, 100, 'Gradient Peak Time', 'Charge (p.e.)') # 1D histograms wavg index = eid[eid == self.eoi].index[0] eoi_t = t_avg[index].compressed() eoi_tgrad = t_grad_avg[index].compressed() self.p_led_1deoicomp_wavg.create( eoi_tgrad, "Gradient Peak Time", "Peak Time Method Comparison (EventID = {})".format(self.eoi)) self.p_led_1deoicomp_wavg.add(eoi_t, "Peak Time") t_shifted = (t_avg - t_avg.mean(1)[:, None]).compressed() t_grad_shifted = (t_grad_avg - t_grad_avg.mean(1)[:, None]).compressed() self.p_led_1dcomp_wavg.create( t_shifted, "Peak Time", "Peak Time Method Comparison (all events, shifted by mean of each event)" ) self.p_led_1dcomp_wavg.add(t_grad_shifted, "Gradient Peak Time") # 1D histograms index = eid[eid == self.eoi].index[0] eoi_t = t[index].compressed() eoi_tgrad = t_grad[index].compressed() self.p_led_1deoicomp.create( eoi_tgrad, "Gradient Peak Time", "Peak Time Method Comparison (EventID = {})".format(self.eoi)) self.p_led_1deoicomp.add(eoi_t, "Peak Time") t_shifted = (t - t.mean(1)[:, None]).compressed() t_grad_shifted = (t_grad - t_grad.mean(1)[:, None]).compressed() self.p_led_1dcomp.create( t_shifted, "Peak Time", "Peak Time Method Comparison (all events, shifted by mean of each event)" ) self.p_led_1dcomp.add(t_grad_shifted, "Gradient Peak Time") # Camera Image eoi_tgrad = t_grad[index] self.p_led_imageeoitgrad.create(eoi_tgrad, "Gradient Peak Time", "Gradient Peak Time Across Camera") # LASER DATA df = self.df.loc[self.df['type'] == 'laser'] eid = df['id'] time = df['time'] tack = df['tack'] fci = np.ma.vstack(df['fci']) bp = np.ma.vstack(df['bp']) dl1 = np.ma.vstack(df['dl1']) t_avg = np.ma.vstack(df['t_avg']) t_grad_avg = np.ma.vstack(df['t_grad_avg']) t = np.ma.vstack(df['t']) t_grad = np.ma.vstack(df['t_grad']) fwhm = np.ma.vstack(df['fwhm']) mask = np.vstack(df['mask']) # bp.mask = mask dl1.mask = mask t_avg.mask = mask t_grad_avg.mask = mask t.mask = mask t_grad.mask = mask fwhm.mask = mask # 1D histograms wavg index = eid[eid == self.eoi].index[0] eoi_t = t_avg[index].compressed() eoi_tgrad = t_grad_avg[index].compressed() self.p_laser_1deoicomp_wavg.create( eoi_tgrad, "Gradient Peak Time", "Peak Time Method Comparison (EventID = {})".format(self.eoi)) self.p_laser_1deoicomp_wavg.add(eoi_t, "Peak Time") t_shifted = (t_avg - t_avg.mean(1)[:, None]).compressed() t_grad_shifted = (t_grad_avg - t_grad_avg.mean(1)[:, None]).compressed() self.p_laser_1dcomp_wavg.create( t_shifted, "Peak Time", "Peak Time Method Comparison (all events, shifted by mean of each event)" ) self.p_laser_1dcomp_wavg.add(t_grad_shifted, "Gradient Peak Time") self.p_laser_1dcomp_wavg.ax.set_xlim([-5, 5]) # 1D histograms index = eid[eid == self.eoi].index[0] eoi_t = t[index].compressed() eoi_tgrad = t_grad[index].compressed() self.p_laser_1deoicomp.create( eoi_tgrad, "Gradient Peak Time", "Peak Time Method Comparison (EventID = {})".format(self.eoi)) self.p_laser_1deoicomp.add(eoi_t, "Peak Time") t_shifted = (t - t.mean(1)[:, None]).compressed() t_grad_shifted = (t_grad - t_grad.mean(1)[:, None]).compressed() self.p_laser_1dcomp.create( t_shifted, "Peak Time", "Peak Time Method Comparison (all events, shifted by mean of each event)" ) self.p_laser_1dcomp.add(t_grad_shifted, "Gradient Peak Time") # Camera Image eoi_tgrad = t_grad[index] self.p_laser_imageeoitgrad.create(eoi_tgrad, "Gradient Peak Time", "Gradient Peak Time Across Camera") # 1D histograms fwhm fwhm = fwhm.compressed() fwhm = fwhm[fwhm > 0] self.p_laser_fwhm.create(fwhm, "FWHM", "FWHM Distribution") # 1D histograms t_shifted = (t - t.mean(1)[:, None]).compressed() self.p_laser_1d_final.create(t_shifted, "Peak Time", "Smoothed Local Peak Time (all events)") # 1D histograms pixel t_shifted = (t - t.mean(1)[:, None]) t_shifted_pix = t_shifted[:, 1825].compressed() self.p_laser_1d_final_pix.create( t_shifted_pix, "Pixel 1825", "Smoothed Local Peak Time (all events)", 10) t_shifted_pix = t_shifted[:, 1203].compressed() self.p_laser_1d_final_pix.add(t_shifted_pix, "Pixel 1203", 10) # self.p_led_eidvsfci.save() # self.p_led_timevstack.save() # self.p_led_bpvstack.save() # self.p_led_eidvst.save() # self.p_led_eidvstgrad.save() # self.p_led_tvstgrad.save() # self.p_led_tvscharge.save() # self.p_led_tgradvscharge.save() self.p_led_1deoicomp_wavg.save() self.p_led_1dcomp_wavg.save() self.p_led_1deoicomp.save() self.p_led_1dcomp.save() self.p_led_imageeoitgrad.save() self.p_laser_1deoicomp_wavg.save() self.p_laser_1dcomp_wavg.save() self.p_laser_1deoicomp.save() self.p_laser_1dcomp.save() self.p_laser_1d_final.save() self.p_laser_1d_final_pix.save() self.p_laser_imageeoitgrad.save() self.p_laser_fwhm.save()
class R0R1Comparer(Tool): name = "R0R1Comparer" description = "Compare between an r0 and r1 file to check the " \ "calibration applied is identical." r0_path = Unicode("", help="Path to an r0 file.").tag(config=True) r1_path = Unicode("", help="Path to an r1 file.").tag(config=True) aliases = Dict( dict( r0='R0R1Comparer.r0_path', r1='R0R1Comparer.r1_path', max_events='TargetioFileReader.max_events', ped='TargetioR1Calibrator.pedestal_path', tf='TargetioR1Calibrator.tf_path', pe='TargetioR1Calibrator.pe_path', )) classes = List([ TargetioFileReader, TargetioR1Calibrator, ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader_r0 = None self.reader_r1 = None self.r1 = None self.dl0 = None self.dl1 = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) if not self.r0_path or not self.r1_path: raise FileNotFoundError("Both r0 and r1 paths need to be set") self.reader_r0 = TargetioFileReader(**kwargs, input_path=self.r0_path) self.reader_r1 = TargetioFileReader(**kwargs, input_path=self.r1_path) self.r1 = TargetioR1Calibrator(**kwargs) assert self.reader_r0.num_events == self.reader_r1.num_events def start(self): n_events = self.reader_r0.num_events source_r0 = self.reader_r0.read() source_r1 = self.reader_r1.read() desc = "Looping through both files" for ev in trange(n_events, desc=desc): event_r0 = self.reader_r0.get_event(ev) event_r1 = self.reader_r1.get_event(ev) self.r1.calibrate(event_r0) self.r1.calibrate(event_r1) samples_r0 = event_r0.r1.tel[0].pe_samples samples_r1 = event_r1.r1.tel[0].pe_samples np.testing.assert_almost_equal(samples_r0, samples_r1, 1) self.log.info("All events match!") def finish(self): pass
class FFGenerator(Tool): name = "FFGenerator" description = "Generate Flat Fielding file" aliases = Dict(dict()) classes = List([]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader = None self.dl0 = None self.dl1 = None self.fitter = None self.dead = None self.fw_calibrator = None self.cfmaker = None self.fw_pos = 2250 directory = join(realpath(dirname(__file__)), "../adc2pe") self.output_path = join(directory, "ff.tcal") if not exists(directory): self.log.info("Creating directory: {}".format(directory)) makedirs(directory) def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170319/linearity/linearity/Run03991_r1_pe.tio' # filepath = '/Volumes/gct-jason/data/170320/linearity/Run04164_r1_pe.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.fw_calibrator = FWCalibrator(**kwargs) self.cfmaker = CfMaker(32) def start(self): n_events = self.reader.num_events first_event = self.reader.get_event(0) telid = list(first_event.r0.tels_with_data)[0] n_pixels, n_samples = first_event.r1.tel[telid].pe_samples[0].shape dl1 = np.zeros((n_events, n_pixels)) ff = np.zeros(n_pixels) fw_illumination = self.fw_calibrator.get_illumination(self.fw_pos) source = self.reader.read() desc = "Looping through file" for event in tqdm(source, total=n_events, desc=desc): index = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1[index] = event.dl1.tel[telid].image desc = "Fitting pixels" for pix in trange(n_pixels, desc=desc): if pix in self.dead.dead_pixels: continue charge = np.mean(dl1[:, pix]) ff[pix] = fw_illumination / charge self.cfmaker.SetAll(ff.astype(np.float32)) self.cfmaker.Save(self.output_path, False) self.log.info("FF tcal created: {}".format(self.output_path)) self.cfmaker.Clear() def finish(self): pass
def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) self.fw_calibrator = FWCalibrator(**kwargs) dfl = [] base_path = "/Volumes/gct-jason/data/170322/led/Run{:05}_r1_adc.tio" base_path_pe = "/Volumes/gct-jason/data/170322/led/Run{:05}_r1_pe.tio" dfl.append( dict(path=base_path.format(4333), type="LED", cal=False, level=0)) dfl.append( dict(path=base_path.format(4334), type="LED", cal=False, level=1)) dfl.append( dict(path=base_path.format(4335), type="LED", cal=False, level=2)) dfl.append( dict(path=base_path.format(4336), type="LED", cal=False, level=3)) dfl.append( dict(path=base_path.format(4337), type="LED", cal=False, level=4)) dfl.append( dict(path=base_path.format(4338), type="LED", cal=False, level=5)) dfl.append( dict(path=base_path.format(4339), type="LED", cal=False, level=6)) dfl.append( dict(path=base_path.format(4340), type="LED", cal=False, level=7)) dfl.append( dict(path=base_path.format(4341), type="LED", cal=False, level=8)) dfl.append( dict(path=base_path.format(4342), type="LED", cal=False, level=9)) dfl.append( dict(path=base_path.format(4343), type="LED", cal=False, level=10)) dfl.append( dict(path=base_path.format(4344), type="LED", cal=False, level=11)) dfl.append( dict(path=base_path.format(4345), type="LED", cal=False, level=12)) dfl.append( dict(path=base_path.format(4346), type="LED", cal=False, level=13)) dfl.append( dict(path=base_path.format(4347), type="LED", cal=False, level=14)) dfl.append( dict(path=base_path.format(4348), type="LED", cal=False, level=15)) dfl.append( dict(path=base_path.format(4349), type="LED", cal=False, level=16)) dfl.append( dict(path=base_path.format(4350), type="LED", cal=False, level=17)) dfl.append( dict(path=base_path.format(4351), type="LED", cal=False, level=18)) dfl.append( dict(path=base_path.format(4352), type="LED", cal=False, level=19)) dfl.append( dict(path=base_path.format(4353), type="LED", cal=False, level=20)) dfl.append( dict(path=base_path.format(4354), type="LED", cal=False, level=21)) dfl.append( dict(path=base_path.format(4355), type="LED", cal=False, level=22)) dfl.append( dict(path=base_path.format(4356), type="LED", cal=False, level=23)) dfl.append( dict(path=base_path.format(4357), type="LED", cal=False, level=24)) dfl.append( dict(path=base_path.format(4358), type="LED", cal=False, level=25)) dfl.append( dict(path=base_path.format(4359), type="LED", cal=False, level=26)) dfl.append( dict(path=base_path.format(4360), type="LED", cal=False, level=27)) dfl.append( dict(path=base_path.format(4361), type="LED", cal=False, level=28)) dfl.append( dict(path=base_path.format(4362), type="LED", cal=False, level=29)) dfl.append( dict(path=base_path.format(4363), type="LED", cal=False, level=30)) dfl.append( dict(path=base_path.format(4364), type="LED", cal=False, level=31)) dfl.append( dict(path=base_path.format(4365), type="LED", cal=False, level=32)) dfl.append( dict(path=base_path.format(4366), type="LED", cal=False, level=33)) dfl.append( dict(path=base_path.format(4367), type="LED", cal=False, level=34)) dfl.append( dict(path=base_path.format(4368), type="LED", cal=False, level=35)) dfl.append( dict(path=base_path.format(4369), type="LED", cal=False, level=36)) dfl.append( dict(path=base_path.format(4370), type="LED", cal=False, level=37)) dfl.append( dict(path=base_path.format(4371), type="LED", cal=False, level=38)) dfl.append( dict(path=base_path.format(4372), type="LED", cal=False, level=39)) dfl.append( dict(path=base_path_pe.format(4333), type="LED", cal=True, level=0)) dfl.append( dict(path=base_path_pe.format(4334), type="LED", cal=True, level=1)) dfl.append( dict(path=base_path_pe.format(4335), type="LED", cal=True, level=2)) dfl.append( dict(path=base_path_pe.format(4336), type="LED", cal=True, level=3)) dfl.append( dict(path=base_path_pe.format(4337), type="LED", cal=True, level=4)) dfl.append( dict(path=base_path_pe.format(4338), type="LED", cal=True, level=5)) dfl.append( dict(path=base_path_pe.format(4339), type="LED", cal=True, level=6)) dfl.append( dict(path=base_path_pe.format(4340), type="LED", cal=True, level=7)) dfl.append( dict(path=base_path_pe.format(4341), type="LED", cal=True, level=8)) dfl.append( dict(path=base_path_pe.format(4342), type="LED", cal=True, level=9)) dfl.append( dict(path=base_path_pe.format(4343), type="LED", cal=True, level=10)) dfl.append( dict(path=base_path_pe.format(4344), type="LED", cal=True, level=11)) dfl.append( dict(path=base_path_pe.format(4345), type="LED", cal=True, level=12)) dfl.append( dict(path=base_path_pe.format(4346), type="LED", cal=True, level=13)) dfl.append( dict(path=base_path_pe.format(4347), type="LED", cal=True, level=14)) dfl.append( dict(path=base_path_pe.format(4348), type="LED", cal=True, level=15)) dfl.append( dict(path=base_path_pe.format(4349), type="LED", cal=True, level=16)) dfl.append( dict(path=base_path_pe.format(4350), type="LED", cal=True, level=17)) dfl.append( dict(path=base_path_pe.format(4351), type="LED", cal=True, level=18)) dfl.append( dict(path=base_path_pe.format(4352), type="LED", cal=True, level=19)) dfl.append( dict(path=base_path_pe.format(4353), type="LED", cal=True, level=20)) dfl.append( dict(path=base_path_pe.format(4354), type="LED", cal=True, level=21)) dfl.append( dict(path=base_path_pe.format(4355), type="LED", cal=True, level=22)) dfl.append( dict(path=base_path_pe.format(4356), type="LED", cal=True, level=23)) dfl.append( dict(path=base_path_pe.format(4357), type="LED", cal=True, level=24)) dfl.append( dict(path=base_path_pe.format(4358), type="LED", cal=True, level=25)) dfl.append( dict(path=base_path_pe.format(4359), type="LED", cal=True, level=26)) dfl.append( dict(path=base_path_pe.format(4360), type="LED", cal=True, level=27)) dfl.append( dict(path=base_path_pe.format(4361), type="LED", cal=True, level=28)) dfl.append( dict(path=base_path_pe.format(4362), type="LED", cal=True, level=29)) dfl.append( dict(path=base_path_pe.format(4363), type="LED", cal=True, level=30)) dfl.append( dict(path=base_path_pe.format(4364), type="LED", cal=True, level=31)) dfl.append( dict(path=base_path_pe.format(4365), type="LED", cal=True, level=32)) dfl.append( dict(path=base_path_pe.format(4366), type="LED", cal=True, level=33)) dfl.append( dict(path=base_path_pe.format(4367), type="LED", cal=True, level=34)) dfl.append( dict(path=base_path_pe.format(4368), type="LED", cal=True, level=35)) dfl.append( dict(path=base_path_pe.format(4369), type="LED", cal=True, level=36)) dfl.append( dict(path=base_path_pe.format(4370), type="LED", cal=True, level=37)) dfl.append( dict(path=base_path_pe.format(4371), type="LED", cal=True, level=38)) dfl.append( dict(path=base_path_pe.format(4372), type="LED", cal=True, level=39)) for d in dfl: d['reader'] = TargetioFileReader(input_path=d['path'], **kwargs) self.df_file = pd.DataFrame(dfl) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.dummy_event = dfl[0]['reader'].get_event(0) telid = list(self.dummy_event.r0.tels_with_data)[0] r1 = self.dummy_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape script = "checm_paper_led" self.p_scatter_led = Scatter(**kwargs, script=script, figure_name="scatter_led", shape='wide') self.p_scatter_led_width = Scatter(**kwargs, script=script, figure_name="scatter_led_width", shape='wide')
class TargetCalibPedestalExplorer(Tool): name = "TargetCalibPedestalExplorer" description = "Plot the TargetCalib pedestal using bokeh" input_path = Unicode(None, allow_none=True, help='Path to the input file containing ' 'events.').tag(config=True) ped_stddev_path = Unicode(None, allow_none=True, help='Path to the stddev numpy file created by ' 'generate_pedestal.py').tag(config=True) aliases = Dict( dict(f='TargetCalibPedestalExplorer.input_path', max_events='TargetioFileReader.max_events', P='PedestalSubtractor.pedestal_path', stddev='TargetCalibPedestalExplorer.ped_stddev_path')) classes = List([TargetioFileReader, PedestalSubtractor]) def __init__(self, **kwargs): super().__init__(**kwargs) self.file_reader = None self.extractor = None self.calibrator = None self.plotter = None self.ped = None self.p_cellspread = None self.p_pixelspread = None self.p_pedselect = None self.p_devcellspread = None self.p_devpixelspread = None self.p_respixelspread = None self.p_rescameraspread = None self.p_reseventspread = None self.p_resselect = None self.layout = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) # Bypass error message when input_path is None if self.input_path is not None: self.file_reader = TargetioFileReader(**kwargs, input_path=self.input_path) self.ped = PedestalSubtractor(**kwargs) self.p_cellspread = PedCellSpread(**kwargs) self.p_pixelspread = PedPixelSpread(**kwargs) self.p_pedselect = PedSelector(**kwargs) self.p_devcellspread = StddevCellSpread(**kwargs) self.p_devpixelspread = StddevPixelSpread(**kwargs) self.p_respixelspread = ResidualPixelSpread(**kwargs) self.p_rescameraspread = ResidualCameraSpread(**kwargs) self.p_reseventspread = ResidualEventSpread(**kwargs) self.p_resselect = ResidualSelector(**kwargs) def start(self): # Get Ped ped = self.ped.get_ped() # Get Ped Stddev ped_stddev = None if self.ped_stddev_path: self.log.info("Loading pedestal stddev file: {}".format( self.ped_stddev_path)) ped_stddev = np.load(self.ped_stddev_path) # Get Events residuals = None cells = None n_modules = None n_cells = None pixel_pos = None foclen = None if self.file_reader: n_events = self.file_reader.num_events first_event = self.file_reader.get_event(0) first_wf = first_event.r0.tel[0].adc_samples[0] n_pix, n_samples = first_wf.shape n_modules = first_event.meta['n_modules'] n_cells = first_event.meta['n_cells'] pixel_pos = first_event.inst.pixel_pos[0] foclen = first_event.inst.optical_foclen[0] residuals = np.zeros((n_events, n_pix, n_samples), dtype=np.float32) cells = np.zeros((n_events, n_pix, n_samples)) source = self.file_reader.read() for event in source: index = event.count self.ped.apply(event, residuals[index]) fci = event.r0.tel[0].first_cell_ids cells[index] = (np.arange(n_samples)[None, :] + fci[:, None]) % n_cells # TEMP!!!!!!!! Remove channel 4 # ped[0, 4] = 0 # # Mask zero values # ped = np.ma.masked_where(ped == 0, ped) # mask_3d = ped.mask # if mask_3d: # mask_3d = np.zeros(ped.shape, dtype=bool) # shape_2d = [mask_3d.shape[0] * mask_3d.shape[1], mask_3d.shape[2]] # mask_2d = mask_3d.reshape(shape_2d) # if ped_stddev is not None: # ped_stddev = np.ma.masked_array(ped_stddev, mask_2d) # Create bokeh figures self.p_cellspread.create(ped) self.p_pixelspread.create(ped) self.p_pedselect.create(ped, ped_stddev) if ped_stddev is not None: self.p_devcellspread.create(ped_stddev) self.p_devpixelspread.create(ped_stddev) if residuals is not None: self.p_respixelspread.create(residuals) self.p_rescameraspread.create(residuals, pixel_pos, foclen) self.p_reseventspread.create(residuals) self.p_resselect.create(residuals, cells, n_modules, n_cells) # Get bokeh layouts l_cellspread = self.p_cellspread.layout l_pixelspread = self.p_pixelspread.layout l_pedselect = self.p_pedselect.layout l_devcellspread = self.p_devcellspread.layout l_devpixelspread = self.p_devpixelspread.layout l_respixelspread = self.p_respixelspread.layout l_rescameraspread = self.p_rescameraspread.layout l_reseventspread = self.p_reseventspread.layout l_resselect = self.p_resselect.layout # Get widgets # Layout layout_list = [[l_cellspread], [l_pixelspread], [l_pedselect]] if ped_stddev is not None: layout_list.append([l_devcellspread]) layout_list.append([l_devpixelspread]) if residuals is not None: layout_list.append([l_respixelspread]) layout_list.append([l_rescameraspread]) layout_list.append([l_reseventspread]) layout_list.append([l_resselect]) self.layout = layout(layout_list, sizing_mode="scale_width") def finish(self): curdoc().add_root(self.layout) curdoc().title = "Pedestal"
class FWInvestigator(Tool): name = "FWInvestigator" description = "Investigate the FW" aliases = Dict(dict()) classes = List([]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader = None self.dl0 = None self.dl1 = None self.fitter = None self.dead = None self.fw_calibrator = None directory = join(realpath(dirname(__file__)), "../targetpipe/io") self.fw_txt_path = join(directory, "FW.txt") self.fw_storage_path = join(directory, "FW.h5") self.fw_storage_path_spe = join(directory, "FW_spe_LS62.h5") self.spe_fw = 1210 self.p_attenuation = None self.p_pe = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) filepath = '/Volumes/gct-jason/data/170314/spe/Run00073_r1_adc.tio' self.reader = TargetioFileReader(input_path=filepath, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.fitter = CHECMSPEFitter(**kwargs) self.fitter.range = [-30, 160] self.dead = Dead() self.fw_calibrator = FWCalibrator(**kwargs) script = "filter_wheel" self.p_attenuation = Scatter(**kwargs, script=script, figure_name="attenuation") self.p_pe = Scatter(**kwargs, script=script, figure_name="pe") # self.p_tmspe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24") # self.p_tmspe_pe = TMSPEFitPlotter(**kwargs, script=script, figure_name="spe_fit_tm24_pe") # self.p_adc2pe = ADC2PEPlotter(**kwargs, script=script, figure_name="adc2pe", shape='wide') # self.p_adc2pe_1100tm = ADC2PE1100VTMPlotter(**kwargs, script=script, figure_name="adc2pe_1100V_tms", shape='wide') # self.p_adc2pe_1100tm_stats = ADC2PE1100VTMStatsPlotter(**kwargs, script=script, figure_name="adc2pe_1100V_tms_stats", shape='wide') def start(self): n_events = self.reader.num_events first_event = self.reader.get_event(0) telid = list(first_event.r0.tels_with_data)[0] n_pixels, n_samples = first_event.r1.tel[telid].pe_samples[0].shape dl1 = np.zeros((n_events, n_pixels)) lambda_ = np.zeros(n_pixels) source = self.reader.read() desc = "Looping through file" for event in tqdm(source, total=n_events, desc=desc): index = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1[index] = event.dl1.tel[telid].image desc = "Fitting pixels" for pix in trange(n_pixels, desc=desc): if not self.fitter.apply(dl1[:, pix]): self.log.warning("Pixel {} couldn't be fit".format(pix)) continue lambda_[pix] = self.fitter.coeff['lambda_'] lambda_ = self.dead.mask1d(lambda_) avg_lamda = np.mean(lambda_) columns = ['position', 'attenuation_mean', 'attenuation_rms'] df = pd.read_table(self.fw_txt_path, sep=' ', names=columns, usecols=[0, 1, 2], skiprows=1) df = df.groupby('position').apply(np.mean) self.fw_calibrator.df = df self.fw_calibrator.save(self.fw_storage_path) self.fw_calibrator.set_calibration(self.spe_fw, avg_lamda) df = self.fw_calibrator.df x = df['position'] y = df['attenuation_mean'] y_err = df['attenuation_rms'] self.p_attenuation.create(x, y, y_err, '', "Postion", "Attenuation", "Filter Wheel Attenuation") x = df['position'] y = df['pe'] y_err = df['pe_err'] self.p_pe.create(x, y, y_err, '', "Postion", "Illumination (p.e.)", "Filter Wheel Calibrated") self.p_pe.ax.set_yscale('log') self.p_pe.ax.get_yaxis().set_major_formatter(FuncFormatter(lambda y, _: '{:g}'.format(y))) def finish(self): # Save figures self.p_attenuation.save() self.p_pe.save() self.fw_calibrator.save(self.fw_storage_path_spe)
class FitComparer(Tool): name = "ADC2PEPlots" description = "Create plots related to adc2pe" aliases = Dict(dict(max_events='TargetioFileReader.max_events')) classes = List([ TargetioFileReader, ]) def __init__(self, **kwargs): super().__init__(**kwargs) self.reader_uncal = None self.reader_cal = None self.dl0 = None self.dl1 = None self.dead = None self.fitter_uncal = None self.fitter_cal = None self.n_pixels = None self.n_samples = None self.path_uncal = "/Volumes/gct-jason/data/170314/spe/Run00073_r1_adc.tio" self.path_cal = "/Volumes/gct-jason/data/170314/spe/Run00073_r1.tio" self.p_comparison = None self.p_tmspread = None self.p_dist = None def setup(self): self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]" kwargs = dict(config=self.config, tool=self) self.reader_uncal = TargetioFileReader(input_path=self.path_uncal, **kwargs) self.reader_cal = TargetioFileReader(input_path=self.path_cal, **kwargs) cleaner = CHECMWaveformCleanerAverage(**kwargs) extractor = AverageWfPeakIntegrator(**kwargs) self.dl0 = CameraDL0Reducer(**kwargs) self.dl1 = CameraDL1Calibrator(extractor=extractor, cleaner=cleaner, **kwargs) self.dead = Dead() self.fitter_uncal = CHECMSPEFitter(**kwargs) self.fitter_cal = CHECMSPEFitter(**kwargs) self.fitter_cal.range = [-3, 6] self.fitter_cal.initial = dict(norm=None, eped=0, eped_sigma=0.2, spe=1, spe_sigma=0.5, lambda_=0.2) first_event = self.reader_uncal.get_event(0) telid = list(first_event.r0.tels_with_data)[0] r1 = first_event.r1.tel[telid].pe_samples[0] self.n_pixels, self.n_samples = r1.shape def start(self): n_events = self.reader_uncal.num_events dl1_uncal = np.zeros((n_events, self.n_pixels)) dl1_cal = np.zeros((n_events, self.n_pixels)) source_uncal = self.reader_uncal.read() desc = 'Looping through events: uncal' for event in tqdm(source_uncal, total=n_events, desc=desc): ev = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1_uncal[ev] = event.dl1.tel[0].image[0] source_cal = self.reader_cal.read() desc = 'Looping through events: cal' for event in tqdm(source_cal, total=n_events, desc=desc): ev = event.count self.dl0.reduce(event) self.dl1.calibrate(event) dl1_cal[ev] = event.dl1.tel[0].image[0] # np.save("/Users/Jason/Downloads/dl1_uncal.npy", dl1_uncal) # np.save("/Users/Jason/Downloads/dl1_cal.npy", dl1_cal) # # dl1_uncal = np.load("/Users/Jason/Downloads/dl1_uncal.npy") # dl1_cal = np.load("/Users/Jason/Downloads/dl1_cal.npy") for pix in range(self.n_pixels): if not self.fitter_uncal.apply(dl1_uncal[:, pix]): self.log.warning("Pixel {} couldn't be fit".format(pix)) continue if not self.fitter_cal.apply(dl1_cal[:, pix]): self.log.warning("Pixel {} couldn't be fit".format(pix)) continue gain_uncal = self.fitter_uncal.coeff['spe'] gain_cal = self.fitter_cal.coeff['spe'] lambda_uncal = self.fitter_uncal.coeff['lambda_'] lambda_cal = self.fitter_cal.coeff['lambda_'] print("Pixel {}: Gain Uncal {:.3} Gain Cal {:.3} " "Lambda Uncal {:.3} Lambda Cal {:.3}".format( pix, gain_uncal, gain_cal, lambda_uncal, lambda_cal)) def finish(self): pass