Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions simpeg/directives/_save_geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) -> dict | None:
"""
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):
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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):
"""
Expand Down
Loading