From 41430eecafbada87f381258a9ae555d1e6b3cc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Fri, 22 Sep 2023 15:34:20 +0200 Subject: [PATCH] fixup: _regsurf_cube_window_v3 --- src/xtgeo/surface/_regsurf_cube_window_v3.py | 46 ++++++++------------ 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/xtgeo/surface/_regsurf_cube_window_v3.py b/src/xtgeo/surface/_regsurf_cube_window_v3.py index 4c1265ffc..20e23b737 100644 --- a/src/xtgeo/surface/_regsurf_cube_window_v3.py +++ b/src/xtgeo/surface/_regsurf_cube_window_v3.py @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- -"""Regular surface vs Cube, slice a window interval v3, in pure numpy. - -The _regsurf_ variable refers to the self instance -""" +"""Regular surface vs Cube, slice a window interval v3, in pure numpy.""" from __future__ import annotations import warnings -from typing import Optional, Union +from typing import Optional, Tuple, Union import numpy as np from scipy.interpolate import interp1d @@ -44,8 +41,7 @@ ] ALLATTRS = STATATTRS + SUMATTRS - -# Note: self -> _regsurf_ +# self ~ RegularSurface() instance def _cut_cube_deadtraces(cube: xtgeo.Cube, deadtraces: bool) -> np.ndarray: @@ -77,12 +73,12 @@ def _get_iso_maskthreshold_surface( def _proxy_surf_outside_cube( - _regsurf_: xtgeo.RegularSurface, + self, cube: xtgeo.Cube, ) -> xtgeo.RegularSurface: """Proxy for the part of input surface that is outside the cube area.""" logger.info("Get a proxy for part of original surface being outside the cube") - outside = _regsurf_.copy() + outside = self.copy() outside.values = 0.0 tmp_surf = xtgeo.surface_from_cube(cube, 0.0) @@ -92,24 +88,24 @@ def _proxy_surf_outside_cube( def _upper_lower_surface( - _regsurf_, + self, cube: xtgeo.Cube, zsurf: xtgeo.RegularSurface, other: xtgeo.RegularSurface, other_position: str, zrange: float, -) -> list: +) -> Tuple[xtgeo.RegularSurface, xtgeo.RegularSurface]: """Return upper and lower surface, sampled to cube resolution.""" logger.info("Define surfaces to apply...") - this = zsurf if zsurf is not None else _regsurf_.copy() + this = zsurf if zsurf is not None else self.copy() if other is not None: if other_position.lower() == "below": surf1 = this surf2 = other else: - surf1 = other # avoid changing _regsurf_ instance + surf1 = other # avoid changing self instance surf2 = this else: surf1 = this.copy() @@ -221,7 +217,7 @@ def _expand_attributes(attribute: Union[str, list]) -> list: def _compute_stats( cref: np.ndarray, attr: str, - _regsurf_: xtgeo.RegularSurface, + self: xtgeo.RegularSurface, upper: xtgeo.RegularSurface, masksurf: xtgeo.RegularSurface, sampling: str, @@ -281,7 +277,7 @@ def _compute_stats( else: raise ValueError(f"The attribute name {attr} is not supported") - actual = _regsurf_.copy() + actual = self.copy() sampled = upper.copy() sampled.values = np.ma.masked_invalid(values) @@ -300,7 +296,7 @@ def _compute_stats( def slice_cube_window( - _regsurf_, + self, cube: xtgeo.Cube, zsurf: Optional[xtgeo.RegularSurface] = None, other: Optional[xtgeo.RegularSurface] = None, @@ -322,12 +318,12 @@ def slice_cube_window( cvalues = _cut_cube_deadtraces(cube, deadtraces) upper, lower = _upper_lower_surface( - _regsurf_, cube, zsurf, other, other_position, zrange + self, cube, zsurf, other, other_position, zrange ) outside_proxy = None if not mask: - outside_proxy = _proxy_surf_outside_cube(_regsurf_, cube) + outside_proxy = _proxy_surf_outside_cube(self, cube) masksurf = _get_iso_maskthreshold_surface(upper, lower, maskthreshold) @@ -351,23 +347,19 @@ def slice_cube_window( for attr in use_attrs: if attr in SUMATTRS: # use cval, which is not refined vertically - res = _compute_stats( - cval, attr, _regsurf_, upper, masksurf, sampling, snapxy - ) + res = _compute_stats(cval, attr, self, upper, masksurf, sampling, snapxy) else: - res = _compute_stats( - cref, attr, _regsurf_, upper, masksurf, sampling, snapxy - ) + res = _compute_stats(cref, attr, self, upper, masksurf, sampling, snapxy) if outside_proxy and not snapxy: - res.values = np.ma.where(outside_proxy > 0, _regsurf_.values, res.values) + res.values = np.ma.where(outside_proxy > 0, self.values, res.values) attrs[attr] = res - # if attribute is str, self (_regsurf_) shall be updated and None returned, + # if attribute is str, self shall be updated and None returned, # otherwise a dict of attributes objects shall be returned if isinstance(attrs, dict) and len(attrs) == 1 and isinstance(attribute, str): - _regsurf_.values = attrs[attribute].values + self.values = attrs[attribute].values return None return attrs