From 6321114f55df60d164382fd8b1473429bffb6723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Thu, 14 Sep 2023 18:29:38 +0200 Subject: [PATCH] WIP: Grid from cube --- src/xtgeo/__init__.py | 134 ++++++++++++++++----------------------- src/xtgeo/grid3d/grid.py | 36 ++++++++++- 2 files changed, 89 insertions(+), 81 deletions(-) diff --git a/src/xtgeo/__init__.py b/src/xtgeo/__init__.py index 12a2db174..603784961 100644 --- a/src/xtgeo/__init__.py +++ b/src/xtgeo/__init__.py @@ -10,7 +10,6 @@ import timeit import warnings - try: from ._theversion import version @@ -80,21 +79,18 @@ def _xprint(msg): # _xprint("Import matplotlib etc...DONE") -from xtgeo.common.constants import UNDEF -from xtgeo.common.constants import UNDEF_LIMIT -from xtgeo.common.constants import UNDEF_INT -from xtgeo.common.constants import UNDEF_INT_LIMIT - -from xtgeo.common.exceptions import DateNotFoundError -from xtgeo.common.exceptions import KeywordNotFoundError -from xtgeo.common.exceptions import KeywordFoundNoDateError -from xtgeo.common.exceptions import WellNotFoundError -from xtgeo.common.exceptions import GridNotFoundError -from xtgeo.common.exceptions import BlockedWellsNotFoundError -from xtgeo.cxtgeo._cxtgeo import XTGeoCLibError - -from xtgeo.common.xtgeo_dialog import XTGeoDialog +from xtgeo.common.constants import UNDEF, UNDEF_INT, UNDEF_INT_LIMIT, UNDEF_LIMIT +from xtgeo.common.exceptions import ( + BlockedWellsNotFoundError, + DateNotFoundError, + GridNotFoundError, + KeywordFoundNoDateError, + KeywordNotFoundError, + WellNotFoundError, +) from xtgeo.common.sys import _XTGeoFile +from xtgeo.common.xtgeo_dialog import XTGeoDialog +from xtgeo.cxtgeo._cxtgeo import XTGeoCLibError _xprint("Import common... done") @@ -102,16 +98,11 @@ def _xprint(msg): from xtgeo.roxutils import roxutils from xtgeo.roxutils.roxutils import RoxUtils - -from xtgeo.well import well1 -from xtgeo.well import wells -from xtgeo.well import blocked_well -from xtgeo.well import blocked_wells - -from xtgeo.well.well1 import Well -from xtgeo.well.wells import Wells +from xtgeo.well import blocked_well, blocked_wells, well1, wells from xtgeo.well.blocked_well import BlockedWell from xtgeo.well.blocked_wells import BlockedWells +from xtgeo.well.well1 import Well +from xtgeo.well.wells import Wells _xprint("Import various XTGeo modules... wells...") @@ -126,39 +117,28 @@ def _xprint(msg): _xprint("Import various XTGeo modules... cube...") -from xtgeo.grid3d import grid -from xtgeo.grid3d import grid_property -from xtgeo.grid3d import grid_properties - -from xtgeo.grid3d import Units -from xtgeo.grid3d import GridRelative +from xtgeo.grid3d import GridRelative, Units, grid, grid_properties, grid_property from xtgeo.grid3d.grid import Grid +from xtgeo.grid3d.grid_properties import GridProperties, gridproperties_dataframe from xtgeo.grid3d.grid_property import GridProperty -from xtgeo.grid3d.grid_properties import GridProperties -from xtgeo.grid3d.grid_properties import gridproperties_dataframe _xprint("Import various XTGeo modules... 3D grids...") -from xtgeo.xyz import points -from xtgeo.xyz import polygons - +from xtgeo.metadata.metadata import ( + MetaDataCPGeometry, + MetaDataCPProperty, + MetaDataRegularCube, + MetaDataRegularSurface, + MetaDataWell, +) +from xtgeo.xyz import points, polygons from xtgeo.xyz.points import Points from xtgeo.xyz.polygons import Polygons -from xtgeo.metadata.metadata import MetaDataRegularSurface -from xtgeo.metadata.metadata import MetaDataRegularCube -from xtgeo.metadata.metadata import MetaDataCPGeometry -from xtgeo.metadata.metadata import MetaDataCPProperty -from xtgeo.metadata.metadata import MetaDataWell - - _xprint("Import various XTGeo modules... xyz...") if not ROXAR: - from xtgeo.plot import baseplot - from xtgeo.plot import xsection - from xtgeo.plot import xtmap - from xtgeo.plot import grid3d_slice + from xtgeo.plot import baseplot, grid3d_slice, xsection, xtmap _xprint("Import various XTGeo modules... plots...") @@ -166,43 +146,37 @@ def _xprint(msg): # some function wrappers to initiate objects from imports _xprint("Import various XTGeo wrappers...") -from xtgeo.surface.regular_surface import surface_from_file -from xtgeo.surface.regular_surface import surface_from_roxar -from xtgeo.surface.regular_surface import surface_from_cube -from xtgeo.surface.regular_surface import surface_from_grid3d - -from xtgeo.grid3d.grid import grid_from_file -from xtgeo.grid3d.grid import grid_from_roxar -from xtgeo.grid3d.grid import create_box_grid - -from xtgeo.grid3d.grid_property import gridproperty_from_file -from xtgeo.grid3d.grid_property import gridproperty_from_roxar - +from xtgeo.cube.cube1 import cube_from_file, cube_from_roxar +from xtgeo.grid3d.grid import ( + create_box_grid, + grid_from_cube, + grid_from_file, + grid_from_roxar, +) from xtgeo.grid3d.grid_properties import gridproperties_from_file - -from xtgeo.cube.cube1 import cube_from_file -from xtgeo.cube.cube1 import cube_from_roxar - -from xtgeo.well.well1 import well_from_file -from xtgeo.well.well1 import well_from_roxar - +from xtgeo.grid3d.grid_property import gridproperty_from_file, gridproperty_from_roxar +from xtgeo.surface.regular_surface import ( + surface_from_cube, + surface_from_file, + surface_from_grid3d, + surface_from_roxar, +) +from xtgeo.well.blocked_well import blockedwell_from_file, blockedwell_from_roxar +from xtgeo.well.blocked_wells import blockedwells_from_files, blockedwells_from_roxar +from xtgeo.well.well1 import well_from_file, well_from_roxar from xtgeo.well.wells import wells_from_files - -from xtgeo.well.blocked_well import blockedwell_from_file -from xtgeo.well.blocked_well import blockedwell_from_roxar - -from xtgeo.well.blocked_wells import blockedwells_from_roxar -from xtgeo.well.blocked_wells import blockedwells_from_files - -from xtgeo.xyz.polygons import polygons_from_file -from xtgeo.xyz.polygons import polygons_from_roxar -from xtgeo.xyz.polygons import polygons_from_wells - -from xtgeo.xyz.points import points_from_file -from xtgeo.xyz.points import points_from_roxar -from xtgeo.xyz.points import points_from_surface -from xtgeo.xyz.points import points_from_wells -from xtgeo.xyz.points import points_from_wells_dfrac +from xtgeo.xyz.points import ( + points_from_file, + points_from_roxar, + points_from_surface, + points_from_wells, + points_from_wells_dfrac, +) +from xtgeo.xyz.polygons import ( + polygons_from_file, + polygons_from_roxar, + polygons_from_wells, +) warnings.filterwarnings("default", category=DeprecationWarning, module="xtgeo") diff --git a/src/xtgeo/grid3d/grid.py b/src/xtgeo/grid3d/grid.py index ee78a0361..b1f38edf3 100644 --- a/src/xtgeo/grid3d/grid.py +++ b/src/xtgeo/grid3d/grid.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Module/class for 3D grids (corner point geometry) with XTGeo.""" +from __future__ import annotations import functools import json @@ -163,7 +164,7 @@ def create_box_grid( origin (tuple of float): Startpoint of grid (x, y, z) oricenter (bool): If False, startpoint is node, if True, use cell center increment (tuple of float): Grid increments (xinc, yinc, zinc) - rotation (float): Roations in degrees, anticlock from X axis. + rotation (float): Rotation in degrees, anticlock from X axis. flip (int): If +1, grid origin is lower left and left-handed; if -1, origin is upper left and right-handed (row flip). @@ -184,6 +185,39 @@ def create_box_grid( return Grid(**kwargs) +def grid_from_cube( + cube: xtgeo.Cube, prop_name: str = "seismics", oricenter: bool = True +): + """Create a rectangular 'shoebox' grid from an existing cube. + + The cube values itself will then be stored with name given by property key. + + Since the cube actually is node centered, while grids are cell oriented, + the geometries here are shifted half an increment as default. To avoiud this, use + oricenter=False. + + Args: + cube: The xtgeo Cube instance + prop_name: Name of seismic property, if None then only the grid geometry + will be made + oricenter: Default is True, to treat seismic nodes as cell center values in + a grid. + + .. versionadded:: 3.24 + """ + + grd = create_box_grid( + cube.dimensions, + (cube.xori, cube.yori, cube.zori), + oricenter=oricenter, + increment=(cube.xinc, cube.yinc, cube.zinc), + rotation=cube.rotation, + flip=cube.yflip, + ) + grd.prop + return grd + + # -------------------------------------------------------------------------------------- # Comment on dual porosity grids: #