Skip to content

Commit

Permalink
WIP, seism atttrs v3
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Sep 14, 2023
1 parent e33e29b commit f6d07e0
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/xtgeo/surface/_regsurf_cube_window_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

from __future__ import annotations

from typing import Type
import warnings
from typing import Type, Union

import numpy as np
from scipy.interpolate import interp1d

import xtgeo
from xtgeo.common import XTGeoDialog

warnings.filterwarnings(action="ignore", message="All-NaN slice encountered")
warnings.filterwarnings(action="ignore", message="Mean of empty slice")

xtg = XTGeoDialog()

logger = xtg.functionlogger(__name__)
Expand Down Expand Up @@ -41,7 +45,7 @@
# pylint: disable=W0613, W0612


def _cut_cube_deadtraces(cube: Type[xtgeo.Cube]) -> Type[np.ndarray]:
def _cut_cube_deadtraces(cube: xtgeo.Cube) -> np.ndarray:
"""Take the cube numpy values and filter away dead traces as np.nan."""

logger.info("Assign dead traces")
Expand All @@ -58,10 +62,10 @@ def _cut_cube_deadtraces(cube: Type[xtgeo.Cube]) -> Type[np.ndarray]:
def _upper_lower_surface(
self,
cube,
zsurf: Type[xtgeo.RegularSurface],
other: Type[xtgeo.RegularSurface],
other_position,
zrange,
zsurf: xtgeo.RegularSurface,
other: xtgeo.RegularSurface,
other_position: str,
zrange: float,
) -> list:
"""Return upper and lower surface, sampled to cube resolution."""

Expand Down Expand Up @@ -95,14 +99,15 @@ def _upper_lower_surface(
return upper, lower


def _create_depth_cube(cube):
def _create_depth_cube(cube: xtgeo.Cube) -> np.ndarray:
"""Create a cube (np array) where values are cube depths; to be used as filter."""
logger.info("Create a depth cube...")
dcube = cube.values.copy()
darr = [cube.zori + n * cube.zinc for n in range(dcube.shape[2])]
dcube[:, :, :] = darr

logger.info("Created a depth cube starting from %s", np.mean(dcube))

return dcube


Expand Down Expand Up @@ -162,7 +167,7 @@ def _filter_cube_values_upper_lower(cvalues, dvalues, upper, lower):
return cvalues


def _expand_attributes(attribute):
def _expand_attributes(attribute: Union[str, list]) -> list:
"""The 'attribute' may be a name, 'all', or a list of attributes"""
useattrs = None
if isinstance(attribute, str):
Expand All @@ -173,6 +178,11 @@ def _expand_attributes(attribute):
else:
useattrs = attribute

if not all(item in ALLATTRS for item in useattrs):
raise ValueError(
f"One or more values are not a valid, input list is {useattrs}, "
f"allowed list is {ALLATTRS}"
)
return useattrs


Expand Down Expand Up @@ -218,10 +228,12 @@ def _compute_stats(cref, attr, self, upper):
use = cref.copy()
use[cref >= 0] = np.nan
values = np.nansum(use, axis=2)
values = np.ma.masked_greater_equal(values, 0.0)
elif attr == "sumpos":
use = cref.copy()
use[cref < 0] = np.nan
values = np.nansum(use, axis=2)
values = np.ma.masked_less_equal(values, 0.0)
elif attr == "sumabs":
use = cref.copy()
use = np.abs(use)
Expand All @@ -231,7 +243,8 @@ def _compute_stats(cref, attr, self, upper):

actual = self.copy()
sampled = upper.copy()
sampled.values = values

sampled.values = np.ma.masked_invalid(values)
actual.resample(sampled)

logger.info("Compute stats... done")
Expand Down Expand Up @@ -267,7 +280,13 @@ def slice_cube_window(
cref, dref = _refine_cubes_vertically(cvalues, dvalues, ndiv)

cref = _filter_cube_values_upper_lower(cref, dref, upper, lower)

cval = _filter_cube_values_upper_lower(cvalues, dvalues, upper, lower)
print(cval)
c = cube.copy()
c.values = np.nan_to_num(cval, nan=0)

c.to_file("/tmp/cval.segy")

use_attrs = _expand_attributes(attribute)

Expand Down

0 comments on commit f6d07e0

Please sign in to comment.