Skip to content

Commit

Permalink
♻️ Renamed attributes force_{model|global}_dimension back to
Browse files Browse the repository at this point in the history
overwrite_{model|global}_dimension
♻️ Renamed methods overwrite_{model|global}_dimension to replace_{model|global}_dimension
  • Loading branch information
s-weigand committed Mar 10, 2022
1 parent 6f35baa commit d0d354f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions glotaran/model/dataset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand All @@ -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

Expand All @@ -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):
Expand All @@ -131,16 +131,16 @@ 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

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."""
Expand Down
8 changes: 6 additions & 2 deletions glotaran/model/dataset_model.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions glotaran/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit d0d354f

Please sign in to comment.