From 816ab354e0d26a51a128cdb0685ea5776b4f0df1 Mon Sep 17 00:00:00 2001 From: domfournier Date: Mon, 7 Oct 2024 13:24:22 -0700 Subject: [PATCH 1/3] Clean up directive --- simpeg/directives/directives.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/simpeg/directives/directives.py b/simpeg/directives/directives.py index f88f5517f2..00052e39c1 100644 --- a/simpeg/directives/directives.py +++ b/simpeg/directives/directives.py @@ -2987,23 +2987,22 @@ class SaveIterationsGeoH5(InversionDirective): Saves inversion results to a geoh5 file """ - def __init__(self, h5_object, **kwargs): + def __init__(self, h5_object, dmisfit=None, **kwargs): self.data_type = {} self._association = None self.attribute_type = "model" self._label = None self.channels = [""] self.components = [""] - self._h5_object = None - self._workspace = None self._transforms: list = [] self.save_objective_function = False self.sorting = None self._reshape = None self.h5_object = h5_object self._joint_index = None + super().__init__( - inversion=None, dmisfit=None, reg=None, verbose=False, **kwargs + inversion=None, dmisfit=dmisfit, reg=None, verbose=False, **kwargs ) def initialize(self): @@ -3085,9 +3084,10 @@ def get_values(self, values: list[np.ndarray] | None): prop = self.stack_channels(dpred) elif self.attribute_type == "sensitivities": - for directive in self.inversion.directiveList.dList: - if isinstance(directive, directives.UpdateSensitivityWeights): - prop = self.reshape(np.sum(directive.JtJdiag, axis=0) ** 0.5) + + prop = np.zeros_like(self.invProb.model) + for fun in self.dmisfit.objfcts: + prop += fun.getJtJdiag(self.invProb.model) return prop From 06c0312c490061544a55b261ec91b477ae43e80c Mon Sep 17 00:00:00 2001 From: domfournier Date: Tue, 8 Oct 2024 16:23:30 -0700 Subject: [PATCH 2/3] Add checker for not None misfit --- simpeg/directives/directives.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/simpeg/directives/directives.py b/simpeg/directives/directives.py index 00052e39c1..368750a11d 100644 --- a/simpeg/directives/directives.py +++ b/simpeg/directives/directives.py @@ -2987,10 +2987,10 @@ class SaveIterationsGeoH5(InversionDirective): Saves inversion results to a geoh5 file """ - def __init__(self, h5_object, dmisfit=None, **kwargs): + def __init__(self, h5_object, dmisfit=None, attribute_type: str = "model", **kwargs): self.data_type = {} self._association = None - self.attribute_type = "model" + self.attribute_type = attribute_type self._label = None self.channels = [""] self.components = [""] @@ -3001,6 +3001,11 @@ def __init__(self, h5_object, dmisfit=None, **kwargs): self.h5_object = h5_object self._joint_index = None + if attribute_type == "sensitivities" and dmisfit is None: + raise ValueError( + "To save sensitivities, the data misfit object must be provided." + ) + super().__init__( inversion=None, dmisfit=dmisfit, reg=None, verbose=False, **kwargs ) From 4c7f681072b86e6241d465db9f0ba6086b67b2b4 Mon Sep 17 00:00:00 2001 From: domfournier Date: Wed, 9 Oct 2024 11:06:55 -0700 Subject: [PATCH 3/3] Update simpeg/directives/directives.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- simpeg/directives/directives.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simpeg/directives/directives.py b/simpeg/directives/directives.py index 368750a11d..5cdaba6152 100644 --- a/simpeg/directives/directives.py +++ b/simpeg/directives/directives.py @@ -2987,7 +2987,9 @@ class SaveIterationsGeoH5(InversionDirective): Saves inversion results to a geoh5 file """ - def __init__(self, h5_object, dmisfit=None, attribute_type: str = "model", **kwargs): + def __init__( + self, h5_object, dmisfit=None, attribute_type: str = "model", **kwargs + ): self.data_type = {} self._association = None self.attribute_type = attribute_type