def test_sky_models_io(tmp_path): # TODO: maybe change to a test case where we create a model programatically? filename = get_pkg_data_filename("data/examples.yaml") models = SkyModels.from_yaml(filename) models.to_yaml(tmp_path / "tmp.yaml") models = SkyModels.from_yaml(tmp_path / "tmp.yaml") assert_allclose(models.parameters["lat_0"].min, -90.0)
def set_model(self, model=None, filename=""): """Read the model from dict or filename and attach it to datasets. Parameters ---------- model: dict or string Dictionary or string in YAML format with the serialized model. filename : string Name of the model YAML file describing the model. """ if not self._validate_set_model(): return False log.info(f"Reading model.") if isinstance(model, str): model = yaml.safe_load(model) if model: self.model = SkyModels(dict_to_models(model)) elif filename: filepath = make_path(filename) self.model = SkyModels.from_yaml(filepath) else: return False # TODO: Deal with multiple components for dataset in self.datasets.datasets: if isinstance(dataset, MapDataset): dataset.model = self.model else: if len(self.model.skymodels) > 1: raise ValueError( "Can only fit a single spectral model at one time." ) dataset.model = self.model.skymodels[0].spectral_model log.info(self.model)
def test_missing_parameters(): filename = get_pkg_data_filename("data/examples.yaml") models = SkyModels.from_yaml(filename) assert models["source1"].spatial_model.e in models.parameters assert len(models["source1"].spatial_model.parameters) == 6