Skip to content

Commit f72a136

Browse files
authored
Merge pull request #92 from MiraGeoscience/GEOPY-2232
GEOPY-2232: Refactor components of inversion options
2 parents 447de6c + b1aa1cc commit f72a136

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

simpeg/directives/_save_geoh5.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_names(
7777
base_name += f"_{component}"
7878

7979
channel_name = base_name
80-
if channel:
80+
if len(channel) > 0:
8181
channel_name += f"_{channel}"
8282

8383
if self.label is not None:
@@ -86,6 +86,17 @@ def get_names(
8686

8787
return channel_name, base_name
8888

89+
@staticmethod
90+
def _channel_label(channel: int, label: str | float | None) -> str:
91+
"""
92+
Format the channel label.
93+
"""
94+
if isinstance(label, str) and len(label) > 1:
95+
return label
96+
elif isinstance(label, float):
97+
return f"[{channel}]"
98+
return ""
99+
89100
@abstractmethod
90101
def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noqa
91102
"""
@@ -263,8 +274,9 @@ def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noq
263274
if self.sorting is not None:
264275
values = values[self.sorting]
265276

277+
label = self._channel_label(ii, channel)
266278
channel_name, base_name = self.get_names(
267-
component, channel, iteration
279+
component, label, iteration
268280
)
269281

270282
data = h5_object.add_data(
@@ -278,9 +290,7 @@ def write(self, iteration: int, values: list[np.ndarray] = None): # flake8: noq
278290
# Re-assign the data type
279291
if channel not in self.data_type[component].keys():
280292
self.data_type[component][channel] = data.entity_type
281-
type_name = f"{self._attribute_type}_{component}"
282-
if channel:
283-
type_name += f"_{channel}"
293+
type_name = f"{self._attribute_type}_{component}" + f"_{label}"
284294
data.entity_type.name = type_name
285295
else:
286296
data.entity_type = w_s.find_type(
@@ -443,10 +453,10 @@ def write(self, iteration: int, **_):
443453

444454
for component in self.components:
445455
properties = []
446-
for channel in self.channels:
447-
456+
for ii, channel in enumerate(self.channels):
457+
label = self._channel_label(ii, channel)
448458
channel_name, base_name = self.get_names(
449-
component, channel, iteration
459+
component, label, iteration
450460
)
451461
children = [
452462
child
@@ -490,7 +500,7 @@ def __init__(
490500
super().__init__(h5_object, **kwargs)
491501

492502
def get_names(
493-
self, component: str, channel: str, iteration: int
503+
self, component: str, channel: int | None, iteration: int
494504
) -> tuple[str, str]:
495505
"""
496506
Format the data and property_group name.
@@ -545,7 +555,7 @@ def write(self, iteration: int, values: list[np.ndarray] | None = None):
545555
"""
546556
petro_model = self.get_values(values)
547557
petro_model = self.apply_transformations(petro_model).flatten()
548-
channel_name, base_name = self.get_names("petrophysics", "", iteration)
558+
channel_name, _ = self.get_names("petrophysics", "", iteration)
549559
with fetch_active_workspace(self._geoh5, mode="r+") as w_s:
550560
h5_object = w_s.get_entity(self.h5_object)[0]
551561
data = h5_object.add_data(

0 commit comments

Comments
 (0)