diff --git a/ogstools/meshplotlib/core.py b/ogstools/meshplotlib/core.py index 47911216d309f629d759613f1e2e926724731889..028de6e77d7f177b04c2bfd90c088ffded20362a 100644 --- a/ogstools/meshplotlib/core.py +++ b/ogstools/meshplotlib/core.py @@ -657,21 +657,7 @@ def plot_diff( mesh_property = get_preset(mesh_property, data_shape) diff_mesh = deepcopy(mesh1) diff_mesh[mesh_property.data_name] -= mesh2[mesh_property.data_name] - data_property = mesh_property.replace(output_unit=mesh_property.data_unit) - diff_unit = str( - ( - data_property.transform(1, strip_unit=False) - - data_property.transform(1, strip_unit=False) - ).units - ) - diff_property = mesh_property.replace( - data_unit=diff_unit, - output_unit=diff_unit, - output_name=mesh_property.output_name + " difference", - bilinear_cmap=True, - cmap=mesh_property.cmap if mesh_property.bilinear_cmap else "coolwarm", - ) - return plot(diff_mesh, diff_property, fig=fig, ax=ax) + return plot(diff_mesh, mesh_property.delta, fig=fig, ax=ax) def plot_limit( diff --git a/ogstools/propertylib/property.py b/ogstools/propertylib/property.py index 60142cccde6a8c1bf24ceb9d423c30a345cda6ec..ff983d56396334c71dc13ae8dbf8e249919294b1 100644 --- a/ogstools/propertylib/property.py +++ b/ogstools/propertylib/property.py @@ -125,6 +125,24 @@ class Property: """ return "%" if self.output_unit == "percent" else self.output_unit + @property + def delta(self) -> "Property": + "returns: A property relating to the difference in a quantity." + data_property = self.replace(output_unit=self.data_unit) + diff_unit = str( + ( + data_property.transform(1, strip_unit=False) + - data_property.transform(1, strip_unit=False) + ).units + ) + return self.replace( + data_unit=diff_unit, + output_unit=diff_unit, + output_name=self.output_name + " difference", + bilinear_cmap=True, + cmap=self.cmap if self.bilinear_cmap else "coolwarm", + ) + def is_mask(self) -> bool: """ Check if the property is a mask.