Skip to content

Commit

Permalink
fixup: _regsurf_cube_window_v3
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Sep 22, 2023
1 parent 824d6d4 commit 41430ee
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions src/xtgeo/surface/_regsurf_cube_window_v3.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,8 +41,7 @@
]
ALLATTRS = STATATTRS + SUMATTRS


# Note: self -> _regsurf_
# self ~ RegularSurface() instance


def _cut_cube_deadtraces(cube: xtgeo.Cube, deadtraces: bool) -> np.ndarray:
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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

0 comments on commit 41430ee

Please sign in to comment.