From d0d354faea96d730b001f825d3e2dfc9f3f451aa Mon Sep 17 00:00:00 2001 From: s-weigand Date: Thu, 27 Jan 2022 11:44:09 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Renamed=20attributes=20for?= =?UTF-8?q?ce=5F{model|global}=5Fdimension=20back=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit overwrite_{model|global}_dimension ♻️ Renamed methods overwrite_{model|global}_dimension to replace_{model|global}_dimension --- .../baseline/test/test_baseline_megacomplex.py | 2 +- .../test/test_coherent_artifact.py | 2 +- .../spectral/test/test_spectral_model.py | 6 +++--- glotaran/model/dataset_model.py | 16 ++++++++-------- glotaran/model/dataset_model.pyi | 8 ++++++-- glotaran/model/model.py | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/glotaran/builtin/megacomplexes/baseline/test/test_baseline_megacomplex.py b/glotaran/builtin/megacomplexes/baseline/test/test_baseline_megacomplex.py index f19f0d226..45572d9fb 100644 --- a/glotaran/builtin/megacomplexes/baseline/test/test_baseline_megacomplex.py +++ b/glotaran/builtin/megacomplexes/baseline/test/test_baseline_megacomplex.py @@ -46,7 +46,7 @@ def test_baseline(): pixel = np.asarray([0]) coords = {"time": time, "pixel": pixel} dataset_model = model.dataset["dataset1"].fill(model, parameter) - dataset_model.overwrite_global_dimension("pixel") + dataset_model.replace_global_dimension("pixel") dataset_model.set_coordinates(coords) matrix = calculate_matrix(dataset_model, {}) compartments = matrix.clp_labels diff --git a/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py b/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py index a7f8accca..843a5a267 100644 --- a/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py +++ b/glotaran/builtin/megacomplexes/coherent_artifact/test/test_coherent_artifact.py @@ -89,7 +89,7 @@ def test_coherent_artifact(spectral_dependence: str): coords = {"time": time, "spectral": spectral} dataset_model = model.dataset["dataset1"].fill(model, parameters) - dataset_model.overwrite_global_dimension("spectral") + dataset_model.replace_global_dimension("spectral") dataset_model.set_coordinates(coords) matrix = calculate_matrix(dataset_model, {"spectral": 1}) compartments = matrix.clp_labels diff --git a/glotaran/builtin/megacomplexes/spectral/test/test_spectral_model.py b/glotaran/builtin/megacomplexes/spectral/test/test_spectral_model.py index 0764ad87a..0fa6dbfbf 100644 --- a/glotaran/builtin/megacomplexes/spectral/test/test_spectral_model.py +++ b/glotaran/builtin/megacomplexes/spectral/test/test_spectral_model.py @@ -95,7 +95,7 @@ class OneCompartmentModelInvertedAxis: axis = {"time": time, "spectral": spectral} decay_dataset_model = decay_model.dataset["dataset1"].fill(decay_model, decay_parameters) - decay_dataset_model.overwrite_global_dimension("spectral") + decay_dataset_model.replace_global_dimension("spectral") decay_dataset_model.set_coordinates(axis) matrix = calculate_matrix(decay_dataset_model, {}) decay_compartments = matrix.clp_labels @@ -157,7 +157,7 @@ class OneCompartmentModelNegativeSkew: axis = {"time": time, "spectral": spectral} decay_dataset_model = decay_model.dataset["dataset1"].fill(decay_model, decay_parameters) - decay_dataset_model.overwrite_global_dimension("spectral") + decay_dataset_model.replace_global_dimension("spectral") decay_dataset_model.set_coordinates(axis) matrix = calculate_matrix(decay_dataset_model, {}) decay_compartments = matrix.clp_labels @@ -261,7 +261,7 @@ class ThreeCompartmentModel: axis = {"time": time, "spectral": spectral} decay_dataset_model = decay_model.dataset["dataset1"].fill(decay_model, decay_parameters) - decay_dataset_model.overwrite_global_dimension("spectral") + decay_dataset_model.replace_global_dimension("spectral") decay_dataset_model.set_coordinates(axis) matrix = calculate_matrix(decay_dataset_model, {}) decay_compartments = matrix.clp_labels diff --git a/glotaran/model/dataset_model.py b/glotaran/model/dataset_model.py index 9a74e40a2..85d86dc47 100644 --- a/glotaran/model/dataset_model.py +++ b/glotaran/model/dataset_model.py @@ -70,8 +70,8 @@ def has_global_megacomplexes(self) -> bool: def get_model_dimension(self) -> str: """Returns the dataset model's model dimension.""" - if self.force_model_dimension is not None: - return self.force_model_dimension + if self.overwrite_model_dimension is not None: + return self.overwrite_model_dimension if not hasattr(self, "_model_dimension"): if not self.has_megacomplexes(): raise ValueError(f"No megacomplex set for dataset model '{self.label}'") @@ -95,7 +95,7 @@ def finalize_data(self, dataset: xr.Dataset) -> None: self, dataset, is_full_model=is_full_model, as_global=True ) - def overwrite_model_dimension(self, model_dimension: str) -> None: + def replace_model_dimension(self, model_dimension: str) -> None: """Overwrites the dataset model's model dimension.""" self._model_dimension = model_dimension @@ -106,8 +106,8 @@ def overwrite_model_dimension(self, model_dimension: str) -> None: # e.g. in FLIM, x, y dimension may get 'flattened' to a MultiIndex 'pixel' def get_global_dimension(self) -> str: """Returns the dataset model's global dimension.""" - if self.force_global_dimension is not None: - return self.force_global_dimension + if self.overwrite_global_dimension is not None: + return self.overwrite_global_dimension if not hasattr(self, "_global_dimension"): if self.has_global_model(): if isinstance(self.global_megacomplex[0], str): @@ -131,7 +131,7 @@ def get_global_dimension(self) -> str: ) return self._global_dimension - def overwrite_global_dimension(self, global_dimension: str) -> None: + def replace_global_dimension(self, global_dimension: str) -> None: """Overwrites the dataset model's global dimension.""" self._global_dimension = global_dimension @@ -139,8 +139,8 @@ def swap_dimensions(self) -> None: """Swaps the dataset model's global and model dimension.""" global_dimension = self.get_model_dimension() model_dimension = self.get_global_dimension() - self.overwrite_global_dimension(global_dimension) - self.overwrite_model_dimension(model_dimension) + self.replace_global_dimension(global_dimension) + self.replace_model_dimension(model_dimension) def set_data(self, dataset: xr.Dataset) -> DatasetModel: """Sets the dataset model's data.""" diff --git a/glotaran/model/dataset_model.pyi b/glotaran/model/dataset_model.pyi index 96cd84ed0..6b2971807 100644 --- a/glotaran/model/dataset_model.pyi +++ b/glotaran/model/dataset_model.pyi @@ -16,6 +16,10 @@ def create_dataset_model_type(properties: dict[str, Any]) -> type[DatasetModel]: class DatasetModel: label: str + clp_guidance: str | None + overwrite_model_dimension: str | None + overwrite_global_dimension: str | None + group: str megacomplex: list[str] megacomplex_scale: list[Parameter] | None global_megacomplex: list[str] @@ -30,9 +34,9 @@ class DatasetModel: ) -> Generator[tuple[Parameter | int | None, Megacomplex | str], None, None]: ... def get_model_dimension(self) -> str: ... def finalize_data(self, dataset: xr.Dataset) -> None: ... - def overwrite_model_dimension(self, model_dimension: str) -> None: ... + def replace_model_dimension(self, model_dimension: str) -> None: ... def get_global_dimension(self) -> str: ... - def overwrite_global_dimension(self, global_dimension: str) -> None: ... + def replace_global_dimension(self, global_dimension: str) -> None: ... def swap_dimensions(self) -> None: ... def set_data(self, dataset: xr.Dataset) -> DatasetModel: ... def get_data(self) -> np.ndarray: ... diff --git a/glotaran/model/model.py b/glotaran/model/model.py index 9f853f951..2d5014832 100644 --- a/glotaran/model/model.py +++ b/glotaran/model/model.py @@ -35,8 +35,8 @@ default_dataset_properties = { "clp_guidance": {"type": str, "allow_none": True}, - "force_model_dimension": {"type": str, "allow_none": True}, - "force_global_dimension": {"type": str, "allow_none": True}, + "overwrite_model_dimension": {"type": str, "allow_none": True}, + "overwrite_global_dimension": {"type": str, "allow_none": True}, "group": {"type": str, "default": "default"}, "megacomplex": {"type": List[str], "allow_none": True}, "megacomplex_scale": {"type": List[Parameter], "allow_none": True},