From 9b854bf7fdc3459e1e8d43943a27af274234b36d Mon Sep 17 00:00:00 2001 From: domfournier Date: Thu, 19 Nov 2026 13:19:09 -0700 Subject: [PATCH 1/2] Allow to pass attributes to the colormap --- simpeg/directives/_save_geoh5.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/simpeg/directives/_save_geoh5.py b/simpeg/directives/_save_geoh5.py index eec024b68f..caaa9bb737 100644 --- a/simpeg/directives/_save_geoh5.py +++ b/simpeg/directives/_save_geoh5.py @@ -11,7 +11,7 @@ from simpeg.maps import IdentityMap from geoh5py.data import FloatData -from geoh5py.data.data_type import ReferencedValueMapType +from geoh5py.data.data_type import DataType, ReferencedValueMapType from geoh5py.groups.property_group import GroupTypeEnum from geoh5py.groups import UIJsonGroup from geoh5py.objects import ObjectBase @@ -171,15 +171,31 @@ def __init__( transforms: list | tuple = (), reshape=None, sorting=None, + data_type_attributes: dict | None = None, **kwargs, ): self.data_type = {} self.transforms = transforms self.sorting = sorting self.reshape = reshape + self.data_type_attributes = data_type_attributes super().__init__(h5_object, **kwargs) + @property + def data_type_attributes(self): + """ + Attributes to be added to the data type of the saved data. + """ + return self._data_type_attributes + + @data_type_attributes.setter + def data_type_attributes(self, value: dict | None): + if not isinstance(value, dict | type(None)): + raise TypeError("'data_type_attributes' must be a dictionary or None") + + self._data_type_attributes = value + @property def reshape(self): """ @@ -293,6 +309,8 @@ def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noq } ) if data_type is None: + self.data_type[component][ii] = data.entity_type + type_name = f"{self._attribute_type}" if component: @@ -301,9 +319,18 @@ def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noq if label: type_name += f"_{label}" - self.data_type[component][ii] = data.entity_type data.entity_type.name = type_name + self._format_data_type(data.entity_type) + + def _format_data_type(self, data_type: DataType): + """ + Apply the data type attributes to the data type of the saved data. + """ + if self.data_type_attributes is not None: + for key, value in self.data_type_attributes.items(): + setattr(data_type, key, value) + class SaveModelGeoH5(SaveArrayGeoH5): """ From fd24b7b433b75824184543db8372af4235b09401 Mon Sep 17 00:00:00 2001 From: domfournier Date: Thu, 19 Nov 2026 13:50:00 -0700 Subject: [PATCH 2/2] Add return type --- simpeg/directives/_save_geoh5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpeg/directives/_save_geoh5.py b/simpeg/directives/_save_geoh5.py index caaa9bb737..a2114368d3 100644 --- a/simpeg/directives/_save_geoh5.py +++ b/simpeg/directives/_save_geoh5.py @@ -183,7 +183,7 @@ def __init__( super().__init__(h5_object, **kwargs) @property - def data_type_attributes(self): + def data_type_attributes(self) -> dict | None: """ Attributes to be added to the data type of the saved data. """