def setup(self): if self.output is None: raise ToolConfigurationError( "You need to provide an --output file") if self.output.exists() and not self.overwrite: raise ToolConfigurationError( "Outputfile {self.output} already exists, use `--overwrite` to overwrite" ) self.source = EventSource(parent=self) subarray = self.source.subarray self.calib = CameraCalibrator(subarray=subarray, parent=self) self.ring_fitter = MuonRingFitter(parent=self) self.intensity_fitter = MuonIntensityFitter(subarray=subarray, parent=self) self.cleaning = TailcutsImageCleaner(parent=self, subarray=subarray) self.writer = HDF5TableWriter(self.output, "", add_prefix=True, parent=self, mode="w") self.pixels_in_tel_frame = {} self.field_of_view = {} self.pixel_widths = {} for p in [ "min_pixels", "pedestal", "ratio_width", "completeness_threshold" ]: getattr(self, p).attach_subarray(self.source.subarray)
def setup(self): if self.output is None: raise ToolConfigurationError( 'You need to provide an --output file') if self.output.exists() and not self.overwrite: raise ToolConfigurationError( 'Outputfile {self.output} already exists, use `--overwrite` to overwrite' ) self.source = self.add_component(EventSource.from_config(parent=self)) self.extractor = self.add_component( ImageExtractor.from_name(self.extractor_name, parent=self, subarray=self.source.subarray)) self.calib = self.add_component( CameraCalibrator( subarray=self.source.subarray, parent=self, image_extractor=self.extractor, )) self.ring_fitter = self.add_component(MuonRingFitter(parent=self, )) self.intensity_fitter = self.add_component( MuonIntensityFitter( subarray=self.source.subarray, parent=self, )) self.cleaning = self.add_component( TailcutsImageCleaner( parent=self, subarray=self.source.subarray, )) self.writer = self.add_component( HDF5TableWriter( self.output, "", add_prefix=True, parent=self, mode='w', )) self.pixels_in_tel_frame = {} self.field_of_view = {} self.pixel_widths = {} for p in [ 'min_pixels', 'pedestal', 'ratio_width', 'completeness_threshold' ]: getattr(self, p).attach_subarray(self.source.subarray)
def from_url(cls, input_url, **kwargs): """ Find compatible EventSource for input_url via the `is_compatible` method of the EventSource Parameters ---------- input_url : str Filename or URL pointing to an event file kwargs Named arguments for the EventSource Returns ------- instance Instance of a compatible EventSource subclass """ if input_url == "" or input_url is None: raise ToolConfigurationError( "EventSource: No input_url was specified") detect_and_import_io_plugins() available_classes = non_abstract_children(cls) for subcls in available_classes: if subcls.is_compatible(input_url): return subcls(input_url=input_url, **kwargs) raise ValueError("Cannot find compatible EventSource for \n" "\turl:{}\n" "in available EventSources:\n" "\t{}".format(input_url, [c.__name__ for c in available_classes]))
def setup(self): self.output_path = self.output_path.expanduser().resolve() if self.output_path.exists(): if self.overwrite: self.log.warning("Overwriting %s", self.output_path) self.output_path.unlink() else: raise ToolConfigurationError( f"Output file {self.output_path} exists" ", use the `overwrite` option or choose another `output_path` " ) self.log.debug("output path: %s", self.output_path) Provenance().add_output_file(str(self.output_path), role="DL1/Event") self.source = LSTEventSource( parent=self, pointing_information=False, trigger_information=False, ) # set some config options, these are necessary for this tool, # so we set them here and not via the config system self.source.r0_r1_calibrator.r1_sample_start = 0 self.source.r0_r1_calibrator.r1_sample_end = N_SAMPLES self.source.r0_r1_calibrator.offset = 0 self.source.r0_r1_calibrator.apply_spike_correction = False self.source.r0_r1_calibrator.apply_timelapse_correction = True self.source.r0_r1_calibrator.apply_drs4_pedestal_correction = False n_stats = N_GAINS * N_PIXELS * N_CAPACITORS_PIXEL self.baseline_stats = OnlineStats(n_stats) self.spike0_stats = OnlineStats(n_stats) self.spike1_stats = OnlineStats(n_stats) self.spike2_stats = OnlineStats(n_stats)
def setup(self): if self.events == '': raise ToolConfigurationError( "please specify --input <events file>") self.log.debug("input: %s", self.events) self.source = event_source(self.events) self.calib = CameraCalibrator(parent=self) self.writer = HDF5TableWriter(self.outfile, "muons")
def setup(self): self.source: EventSource = self.add_component( EventSource.from_config(parent=self) ) if self.source.input_url == '': raise ToolConfigurationError("please specify --input <events file>") self.calib = self.add_component(CameraCalibrator(parent=self)) self.writer = self.add_component(HDF5TableWriter(self.outfile, "muons"))
def setup(self): self.filename_dl3 = dl2_to_dl3_filename(self.input_dl2, compress=self.gzip) self.provenance_log = self.output_dl3_path / (self.name + ".provenance.log") Provenance().add_input_file(self.input_dl2) self.event_sel = EventSelector(parent=self) self.cuts = DL3Cuts(parent=self) self.output_file = self.output_dl3_path.absolute() / self.filename_dl3 if self.output_file.exists(): if self.overwrite: self.log.warning(f"Overwriting {self.output_file}") self.output_file.unlink() else: raise ToolConfigurationError( f"Output file {self.output_file} already exists," " use --overwrite to overwrite") if not (self.source_ra or self.source_dec): self.source_pos = SkyCoord.from_name(self.source_name) elif bool(self.source_ra) != bool(self.source_dec): raise ToolConfigurationError( "Either provide both RA and DEC values for the source or none") else: self.source_pos = SkyCoord(ra=self.source_ra, dec=self.source_dec) self.log.debug(f"Output DL3 file: {self.output_file}") try: with fits.open(self.input_irf) as hdul: self.use_energy_dependent_gh_cuts = ( "GH_CUT" not in hdul["EFFECTIVE AREA"].header) except: raise ToolConfigurationError( f"{self.input_irf} does not have EFFECTIVE AREA HDU, " " to check for global cut information in the Header value") if self.source_dep: with fits.open(self.input_irf) as hdul: self.use_energy_dependent_alpha_cuts = ( "AL_CUT" not in hdul["EFFECTIVE AREA"].header)
def setup(self): if self.output_irf_file.absolute().exists(): if self.overwrite: self.log.warning(f"Overwriting {self.output_irf_file}") self.output_irf_file.unlink() else: raise ToolConfigurationError( f"Output file {self.output_irf_file} already exists," " use --overwrite to overwrite" ) filename = self.output_irf_file.name if not (filename.endswith('.fits') or filename.endswith('.fits.gz')): raise ValueError( f"{filename} is not a correct compressed FITS file name" "(use .fits or .fits.gz)." ) if self.input_proton_dl2 and self.input_electron_dl2 is not Undefined: self.only_gamma_irf = False else: self.only_gamma_irf = True self.event_sel = EventSelector(parent=self) self.cuts = DL3Cuts(parent=self) self.data_bin = DataBinning(parent=self) self.mc_particle = { "gamma": { "file": self.input_gamma_dl2, "target_spectrum": CRAB_MAGIC_JHEAP2015, }, } Provenance().add_input_file(self.input_gamma_dl2) self.t_obs = self.irf_obs_time * u.hour # Read and update MC information if not self.only_gamma_irf: self.mc_particle["proton"] = { "file": self.input_proton_dl2, "target_spectrum": IRFDOC_PROTON_SPECTRUM, } self.mc_particle["electron"] = { "file": self.input_electron_dl2, "target_spectrum": IRFDOC_ELECTRON_SPECTRUM, } Provenance().add_input_file(self.input_proton_dl2) Provenance().add_input_file(self.input_electron_dl2) self.provenance_log = self.output_irf_file.parent / ( self.name + ".provenance.log" )
def setup(self): if self.events == '': raise ToolConfigurationError( "please specify --input <events file>") self.log.debug("input: %s", self.events) self.source = EventSourceFactory.produce(input_url=self.events) self.calib = CameraCalibrator(config=self.config, tool=self, eventsource=self.source) self.writer = HDF5TableWriter(self.outfile, "muons")
def setup(self): self.list_files = sorted(self.input_dl3_dir.glob(self.file_pattern)) if len(self.list_files) == 0: raise ToolConfigurationError( f"No files found with pattern {self.file_pattern} in {self.input_dl3_dir}" ) for f in self.list_files: Provenance().add_input_file(f) if not self.output_index_path: self.output_index_path = self.input_dl3_dir self.hdu_index_file = self.output_index_path / self.hdu_index_filename self.obs_index_file = self.output_index_path / self.obs_index_filename self.provenance_log = self.output_index_path / (self.name + ".provenance.log") if self.hdu_index_file.exists(): if self.overwrite: self.log.warning(f"Overwriting {self.hdu_index_file}") self.hdu_index_file.unlink() else: raise ToolConfigurationError( f"Output file {self.hdu_index_file} already exists," "use --overwrite to overwrite" ) if self.obs_index_file.exists(): if self.overwrite: self.log.warning(f"Overwriting {self.obs_index_file}") self.obs_index_file.unlink() else: raise ToolConfigurationError( f"Output file {self.obs_index_file} already exists," " use --overwrite to overwrite" ) self.log.debug("HDU Index file: %s", self.hdu_index_file) self.log.debug("OBS Index file: %s", self.obs_index_file)
def _find_compatible_source(cls, input_url): if input_url == "" or input_url is None: raise ToolConfigurationError("EventSource: No input_url was specified") # validate input url with the traitel validate method # to make sure it's compatible and to raise the correct error input_url = EventSource.input_url.validate(obj=None, value=input_url) available_classes = non_abstract_children(cls) for subcls in available_classes: if subcls.is_compatible(input_url): return subcls raise ValueError( "Cannot find compatible EventSource for \n" "\turl:{}\n" "in available EventSources:\n" "\t{}".format(input_url, [c.__name__ for c in available_classes]) )
def setup(self): """ setup function, called before `start()` """ if self.infile == '': raise ToolConfigurationError( "No 'infile' parameter was specified. ") self.events = Table( names=['EVENT_ID', 'T_REL', 'DELTA_T', 'N_TRIG', 'TRIGGERED_TELS'], dtype=[np.int64, np.float64, np.float64, np.int32, np.uint8]) self.events['TRIGGERED_TELS'].shape = (0, MAX_TELS) self.events['T_REL'].unit = u.s self.events['T_REL'].description = 'Time relative to first event' self.events['DELTA_T'].unit = u.s self.events.meta['INPUT'] = self.infile self._current_trigpattern = np.zeros(MAX_TELS) self._current_starttime = None self._prev_time = None
def setup(self): """ setup function, called before `start()` """ if self.infile == "": raise ToolConfigurationError("No 'infile' parameter was specified. ") self.events = Table( names=["EVENT_ID", "T_REL", "DELTA_T", "N_TRIG", "TRIGGERED_TELS"], dtype=[np.int64, np.float64, np.float64, np.int32, np.uint8], ) self.events["TRIGGERED_TELS"].shape = (0, MAX_TELS) self.events["T_REL"].unit = u.s self.events["T_REL"].description = "Time relative to first event" self.events["DELTA_T"].unit = u.s self.events.meta["INPUT"] = self.infile self._current_trigpattern = np.zeros(MAX_TELS) self._current_starttime = None self._prev_time = None