def configure(self, config=None, opts=None, **kwargs): """Update the configuration of this object with the contents of 'config'. When the same option is defined in multiple inputs the order of precedence is config -> opts -> kwargs.""" if not config is None: self._config = merge_dict(self._config, config) if not opts is None: self.parse_opts(opts) self._config = merge_dict(self._config, kwargs) for k, v in self._config.items(): if v is None or not isinstance(v, str): continue if os.path.isfile(v): self._config[k] = os.path.abspath(v)
def configure(self,config=None,opts=None,**kwargs): """Update the configuration of this object with the contents of 'config'. When the same option is defined in multiple inputs the order of precedence is config -> opts -> kwargs.""" if not config is None: self._config = merge_dict(self._config,config) if not opts is None: self.parse_opts(opts) self._config = merge_dict(self._config,kwargs) for k, v in self._config.items(): if v is None or not isinstance(v,str): continue if os.path.isfile(v): self._config[k] = os.path.abspath(v)
def create(src_name,model_file = None,**kwargs): if model_file is None: model_file = os.path.join(gammatools.PACKAGE_ROOT, 'data/dm_halo_models.yaml') halo_model_lib = yaml.load(open(model_file,'r')) if not src_name in halo_model_lib: raise Exception('Could not find profile: ' + src_name) src = halo_model_lib[src_name] src = merge_dict(src,kwargs,skip_values=[None]) # if rho_rsun is not None: # src['rhor'] = [rho_rsun,8.5] # if gamma is not None: # src['gamma'] = gamma hm = HaloModel(src) if 'jvalue' in src: if len(src['jvalue']) == 1: hm.set_jvalue(Units.parse(src['jvalue'][0]),0.5) else: hm.set_jvalue(Units.parse(src['jvalue'][0]), Units.parse(src['jvalue'][1])) return hm
def create_default_config(cls,key='default_config'): o = {} for base_class in inspect.getmro(cls): if key in base_class.__dict__: o = merge_dict(o,base_class.__dict__[key],add_new_keys=True) # else: # raise Exception('No config dictionary with key %s '%key + # 'in %s'%str(cls)) o = create_options_dict(o) return o
def create_default_config(cls, key='default_config'): o = {} for base_class in inspect.getmro(cls): if key in base_class.__dict__: o = merge_dict(o, base_class.__dict__[key], add_new_keys=True) # else: # raise Exception('No config dictionary with key %s '%key + # 'in %s'%str(cls)) o = create_options_dict(o) return o
def update_default_config(self,default_dict): """Update the defaults dictionary for this class.""" if not isinstance(default_dict,dict) and issubclass(default_dict,Configurable): default_dict = default_dict.default_config elif not isinstance(default_dict,dict): raise Exception('Wrong type for default dict.') new_default_config = create_options_dict(default_dict) default_config = merge_dict(self._default_config,new_default_config, add_new_keys=True) # default_config = create_options_dict(default_config) self._default_config = default_config self._config = self.create_config(self._default_config)
def update_default_config(self, default_dict): """Update the defaults dictionary for this class.""" if not isinstance(default_dict, dict) and issubclass( default_dict, Configurable): default_dict = default_dict.default_config elif not isinstance(default_dict, dict): raise Exception('Wrong type for default dict.') new_default_config = create_options_dict(default_dict) default_config = merge_dict(self._default_config, new_default_config, add_new_keys=True) # default_config = create_options_dict(default_config) self._default_config = default_config self._config = self.create_config(self._default_config)
def update_config(self,config): self._config = merge_dict(self._config,config)
def update_config(self, config): self._config = merge_dict(self._config, config)