def new_context(self, storage=tuple(), config=None, register=None, register_all=None, replace=False, **kwargs): """Return a new context with new setting adding to those in this context. :param replace: If True, replaces settings rather than adding them. See Context.__init__ for documentation on other parameters. """ # TODO: Clone rather than pass on storage front-ends ?? if not isinstance(storage, (list, tuple)): storage = [storage] if config is None: config = dict() if register is None: register = [] if not isinstance(register, (tuple, list)): register = [register] if not replace: storage = self.storage + list(storage) config = strax.combine_configs(self.config, config, mode='update') kwargs = strax.combine_configs(self.context_config, kwargs, mode='update') register = list(self._plugin_class_registry.values()) + register return Context(storage=storage, config=config, register=register, register_all=register_all, **kwargs)
def set_context_config(self, context_config=None, mode='update'): """Set new context configuration options :param context_config: dict of new context configuration options :param mode: can be either - update: Add to or override current options in context - setdefault: Add to current options, but do not override - replace: Erase config, then set only these options """ if not hasattr(self, 'context_config'): self.context_config = dict() new_config = strax.combine_configs(old_config=self.context_config, new_config=context_config, mode=mode) for opt in self.takes_config.values(): opt.validate(new_config, set_defaults=True) for k in new_config: if k not in self.takes_config: warnings.warn(f"Unknown config option {k}; will do nothing.") self.context_config = new_config for k in self.context_config: if k not in self.takes_config: warnings.warn(f"Invalid context option {k}; will do nothing.")
def set_config(self, config=None, mode='update'): """Set new configuration options :param config: dict of new options :param mode: can be either - update: Add to or override current options in context - setdefault: Add to current options, but do not override - replace: Erase config, then set only these options """ if not hasattr(self, 'config'): self.config = dict() self.config = strax.combine_configs(old_config=self.config, new_config=config, mode=mode)
def pema_context( base_dir: str, fax_config: str, cmt_run_id_sim: str, config_update: dict = None, raw_dir=None, data_dir=None, raw_types=None, ) -> strax.Context: """ Central context for pema, allows to init from a config. :param base_dir: Where store instructions, :param fax_config: fax configuration file :param cmt_run_id_sim: run_id for CMT (see straxen.contexts.xenonnt_simulation) :param config_update: Setup the config of the context :param raw_dir: Where to store the low level datatypes :param data_dir: Where to store the high level datatypes :param raw_types: Low level datatypes, stored separately from high level datatypes :return: context """ if not os.path.exists(base_dir): raise FileNotFoundError( f'Cannot use {base_dir} as base_dir. It does not exist.') config = dict( detector='XENONnT', check_raw_record_overlaps=False, fax_config=fax_config, cmt_run_id_sim=cmt_run_id_sim, ) if config_update is not None: if not isinstance(config_update, dict): raise ValueError(f'Invalid config update {config_update}') config = strax.combine_configs(config, config_update) st = straxen.contexts.xenonnt_simulation( fax_config=config['fax_config'], cmt_run_id_sim=cmt_run_id_sim, cmt_version='global_v7', ) st.set_config(config) # Disable warning for these options st.set_context_config({ 'free_options': ('n_nveto_pmts', 'channel_map', 'n_mveto_pmts', 'gain_model_nv', 'gain_model_mv', 'cmt_run_id_sim') }) # Setup the plugins for nT # st.register(wfsim.RawRecordsFromFaxNT) st.register_all(pema.match_plugins) st.register_all(straxen.plugins.position_reconstruction) del st._plugin_class_registry['peak_positions_base_nt'] st._plugin_class_registry['peaks'].save_when = strax.SaveWhen.ALWAYS if raw_types is None: raw_types = (wfsim.RawRecordsFromFaxNT.provides + straxen.plugins.pulse_processing.PulseProcessing.provides) # Setup the storage, don't trust any of the stuff we get from xenonnt_simulation st.storage = [] if raw_dir is not None: st.storage += [strax.DataDirectory(raw_dir, take_only=raw_types)] if data_dir is not None: st.storage += [strax.DataDirectory(data_dir, exclude=raw_types)] if not st.storage or not len(st.storage): raise RuntimeError('No storage, provide raw_dir and/or data_dir') return st