Skip to content

Commit 074d514

Browse files
authored
Merge pull request #140 from jcrivenaes/dev-xsection
Dev xsection
2 parents d97fff5 + e2ed56d commit 074d514

File tree

7 files changed

+184
-75
lines changed

7 files changed

+184
-75
lines changed

docs/usextgeoroxar.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,72 @@ Take a surface in RMS and multiply values with 2:
6969
surf.to_roxar(project, 'TopReek', 'DS_tmp')
7070
7171
72+
Do operations on surfaces, also inside polygons:
73+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
75+
Find the diff maps in time domain, of the main surfaces. Also make a
76+
a version where cut by polygons where surfaces has interp (minimum
77+
common multiplum)
78+
79+
.. code-block:: python
80+
81+
import xtgeo
82+
from fmu.config import utilities as ut
83+
84+
CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")["rms"]
85+
86+
# ========= SETTINGS ===================================================================
87+
88+
PRJ = project # noqa
89+
90+
# input
91+
TSCAT1 = "TS_interp_raw_ow"
92+
PCAT = "TL_interp_raw_approx_outline"
93+
94+
95+
# output
96+
ISCAT1 = "IS_twt_main_interp_raw_ow"
97+
ISCAT2 = "IS_twt_main_interp_raw_ow_cut"
98+
99+
# ========= END SETTINGS ===============================================================
100+
101+
102+
def main():
103+
104+
topmainzones = CFG["horizons"]["TOP_MAINRES"]
105+
mainzones = CFG["zones"]["MAIN_ZONES"]
106+
for znum, mzone in enumerate(mainzones):
107+
108+
surf1 = xtgeo.surface_from_roxar(PRJ, topmainzones[znum], TSCAT1)
109+
surf2 = xtgeo.surface_from_roxar(PRJ, topmainzones[znum + 1], TSCAT1)
110+
111+
diff = surf2.copy()
112+
diff.values -= surf1.values
113+
diff.to_roxar(PRJ, mzone, ISCAT1, stype="zones")
114+
print("Store {} at {}".format(mzone, ISCAT1))
115+
116+
# extract differences inside a polygon and compute min/max values:
117+
118+
poly = xtgeo.polygons_from_roxar(PRJ, topmainzones[znum], PCAT)
119+
surf1.eli_outside(poly)
120+
surf2.eli_outside(poly)
121+
diff2 = surf2.copy()
122+
diff2.values -= surf1.values
123+
print(
124+
"Min and max values inside polygons {} : {} (negative OK) for {}".format(
125+
diff2.values.min(), diff2.values.max(), mzone
126+
)
127+
)
128+
diff2.to_roxar(PRJ, mzone, ISCAT2, stype="zones")
129+
print("Store cut surface {} at {}".format(mzone, ISCAT2))
130+
131+
132+
if __name__ == "__main__":
133+
main()
134+
print("Done, see <{}> and <{}>".format(ISCAT1, ISCAT2))
135+
136+
137+
72138
3D grid data
73139
------------
74140

src/xtgeo/surface/_regsurf_export.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import division, absolute_import
66
from __future__ import print_function
77

8+
import xtgeo
89
import xtgeo.cxtgeo.cxtgeo as _cxtgeo # pylint: disable=import-error
910
from xtgeo.common import XTGeoDialog
1011

@@ -25,7 +26,7 @@ def export_irap_ascii(self, mfile):
2526
zmin = self.values.min()
2627
zmax = self.values.max()
2728

28-
vals = self.get_values1d(fill_value=self.undef)
29+
vals = self.get_values1d(fill_value=xtgeo.UNDEF)
2930
logger.debug("SHAPE %s %s", vals.shape, vals.dtype)
3031

3132
ier = _cxtgeo.surf_export_irap_ascii(
@@ -52,7 +53,7 @@ def export_irap_ascii(self, mfile):
5253
def export_irap_binary(self, mfile):
5354
"""Export to Irap RMS binary format."""
5455

55-
vals = self.get_values1d(fill_value=self.undef)
56+
vals = self.get_values1d(fill_value=xtgeo.UNDEF)
5657
ier = _cxtgeo.surf_export_irap_bin(
5758
mfile,
5859
self._ncol,
@@ -76,7 +77,7 @@ def export_irap_binary(self, mfile):
7677
def export_ijxyz_ascii(self, mfile):
7778
"""Export to DSG IJXYZ ascii format."""
7879

79-
vals = self.get_values1d(fill_value=self.undef)
80+
vals = self.get_values1d(fill_value=xtgeo.UNDEF)
8081
ier = _cxtgeo.surf_export_ijxyz(
8182
mfile,
8283
self._ncol,
@@ -117,7 +118,7 @@ def export_zmap_ascii(self, mfile):
117118

118119
yinc = scopy._yinc * scopy._yflip
119120

120-
vals = scopy.get_values1d(order="F", asmasked=False, fill_value=self.undef)
121+
vals = scopy.get_values1d(order="F", asmasked=False, fill_value=xtgeo.UNDEF)
121122

122123
ier = _cxtgeo.surf_export_zmap_ascii(
123124
mfile,

src/xtgeo/surface/_regsurf_oper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import numpy.ma as ma
77

8+
import xtgeo
89
from xtgeo.xyz import Polygons
910
import xtgeo.cxtgeo.cxtgeo as _cxtgeo
1011
from xtgeo.common import XTGeoDialog
@@ -129,7 +130,7 @@ def get_value_from_xy(self, point=(0.0, 0.0)):
129130
XTGDEBUG,
130131
)
131132

132-
if zcoord > self._undef_limit:
133+
if zcoord > xtgeo.UNDEF_LIMIT:
133134
return None
134135

135136
return zcoord
@@ -165,7 +166,7 @@ def get_xy_value_from_ij(self, iloc, jloc, zvalues=None):
165166
else:
166167
raise ValueError("Index i and/or j out of bounds")
167168

168-
if value > self.undef_limit:
169+
if value > xtgeo.UNDEF_LIMIT:
169170
value = None
170171

171172
return xval, yval, value
@@ -308,7 +309,7 @@ def get_fence(self, xyfence):
308309
logger.warning("Seem to be rotten")
309310

310311
xyfence[:, 2] = czarr
311-
xyfence = ma.masked_greater(xyfence, self._undef_limit)
312+
xyfence = ma.masked_greater(xyfence, xtgeo.UNDEF_LIMIT)
312313
xyfence = ma.mask_rows(xyfence)
313314

314315
return xyfence
@@ -325,7 +326,7 @@ def operation_polygons(self, poly, value, opname="add", inside=True):
325326

326327
proxy = self.copy()
327328
proxy.values *= 0.0
328-
vals = proxy.get_values1d(fill_value=self.undef)
329+
vals = proxy.get_values1d(fill_value=xtgeo.UNDEF)
329330

330331
# value could be a scalar or another surface; if another surface,
331332
# must ensure same topology
@@ -397,8 +398,8 @@ def operation_polygons(self, poly, value, opname="add", inside=True):
397398
elif opname == "set":
398399
tmp = value
399400
elif opname == "eli":
400-
tmp = value * 0 + self.undef
401-
tmp = ma.masked_greater(tmp, self.undef_limit)
401+
tmp = value * 0 + xtgeo.UNDEF
402+
tmp = ma.masked_greater(tmp, xtgeo.UNDEF_LIMIT)
402403

403404
self.values[proxyv == proxytarget] = tmp[proxyv == proxytarget]
404405
del tmp

src/xtgeo/surface/_regsurf_roxapi.py

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
# coding: utf-8
22
"""Roxar API functions for XTGeo RegularSurface"""
3-
import numpy as np
4-
53
from xtgeo.common import XTGeoDialog
4+
from xtgeo import RoxUtils
65

76
xtg = XTGeoDialog()
87

98
logger = xtg.functionlogger(__name__)
109

11-
# pylint: disable=protected-access
12-
1310

1411
def import_horizon_roxapi(self, project, name, category, stype, realisation):
1512
"""Import a Horizon surface via ROXAR API spec."""
16-
import roxar # pylint: disable=import-error
1713

18-
if project is not None and isinstance(project, str):
19-
projectname = project
20-
with roxar.Project.open_import(projectname) as proj:
21-
_roxapi_import_surface(self, proj, name, category, stype, realisation)
22-
else:
23-
_roxapi_import_surface(self, project, name, category, stype, realisation)
14+
rox = RoxUtils(project, readonly=True)
15+
16+
proj = rox.project
17+
18+
_roxapi_import_surface(self, proj, name, category, stype, realisation)
19+
20+
rox.safe_close()
2421

2522

2623
def _roxapi_import_surface(self, proj, name, category, stype, realisation):
@@ -39,6 +36,7 @@ def _roxapi_import_surface(self, proj, name, category, stype, realisation):
3936
_roxapi_horizon_to_xtgeo(self, rox)
4037
except KeyError as kwe:
4138
logger.error(kwe)
39+
4240
elif stype == "zones":
4341
if name not in proj.zones:
4442
raise ValueError("Name {} is not within Zones".format(name))
@@ -51,6 +49,19 @@ def _roxapi_import_surface(self, proj, name, category, stype, realisation):
5149
_roxapi_horizon_to_xtgeo(self, rox)
5250
except KeyError as kwe:
5351
logger.error(kwe)
52+
53+
elif stype == "clipboard":
54+
if category:
55+
if "|" in category:
56+
folders = category.split("|")
57+
else:
58+
folders = category.split("/")
59+
rox = proj.clipboard.folders[folders]
60+
else:
61+
rox = proj.clipboard
62+
roxsurf = rox[name].get_grid(realisation)
63+
_roxapi_horizon_to_xtgeo(self, roxsurf)
64+
5465
else:
5566
raise ValueError("Invalid stype")
5667

@@ -64,20 +75,19 @@ def _roxapi_horizon_to_xtgeo(self, rox):
6475
self._xinc, self._yinc = rox.increment
6576
self._rotation = rox.rotation
6677

67-
# since XTGeo is F order, while RMS is C order...
68-
self._values = np.asanyarray(rox.get_values(), order="C")
78+
self._values = rox.get_values()
79+
logger.info("Surface from roxapi to xtgeo... DONE")
6980

7081

7182
def export_horizon_roxapi(self, project, name, category, stype, realisation):
7283
"""Export (store) a Horizon surface to RMS via ROXAR API spec."""
73-
import roxar # pylint: disable=import-error
84+
rox = RoxUtils(project, readonly=False)
7485

75-
if project is not None and isinstance(project, str):
76-
projectname = project
77-
with roxar.Project.open_import(projectname) as proj:
78-
_roxapi_export_surface(self, proj, name, category, stype, realisation)
79-
else:
80-
_roxapi_export_surface(self, project, name, category, stype, realisation)
86+
logger.info("Surface from xtgeo to roxapi...")
87+
_roxapi_export_surface(self, rox.project, name, category, stype, realisation)
88+
89+
logger.info("Surface from xtgeo to roxapi... DONE")
90+
rox.safe_close()
8191

8292

8393
def _roxapi_export_surface(self, proj, name, category, stype, realisation):
@@ -90,9 +100,9 @@ def _roxapi_export_surface(self, proj, name, category, stype, realisation):
90100
)
91101
try:
92102
roxroot = proj.horizons[name][category]
93-
rox = _xtgeo_to_roxapi_grid(self)
94-
rox.set_values(np.asanyarray(self.values, order="C"))
95-
roxroot.set_grid(rox, realisation=realisation)
103+
roxg = _xtgeo_to_roxapi_grid(self)
104+
roxg.set_values(self.values)
105+
roxroot.set_grid(roxg, realisation=realisation)
96106
except KeyError as kwe:
97107
logger.error(kwe)
98108

@@ -105,12 +115,26 @@ def _roxapi_export_surface(self, proj, name, category, stype, realisation):
105115
)
106116
try:
107117
roxroot = proj.zones[name][category]
108-
rox = _xtgeo_to_roxapi_grid(self)
109-
rox.set_values(np.asanyarray(self.values, order="C"))
110-
roxroot.set_grid(rox)
118+
roxg = _xtgeo_to_roxapi_grid(self)
119+
roxg.set_values(self.values)
120+
roxroot.set_grid(roxg)
111121
except KeyError as kwe:
112122
logger.error(kwe)
113123

124+
elif stype == "clipboard":
125+
folders = []
126+
if category:
127+
if "|" in category:
128+
folders = category.split("|")
129+
else:
130+
folders = category.split("/")
131+
if folders:
132+
proj.clipboard.folders.create(folders)
133+
134+
roxroot = proj.clipboard.create_surface(name, folders)
135+
roxg = _xtgeo_to_roxapi_grid(self)
136+
roxg.set_values(self.values)
137+
roxroot.set_grid(roxg)
114138
else:
115139
raise ValueError("Invalid stype")
116140

src/xtgeo/surface/_regsurf_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""RegularSurface utilities (basic low level)"""
22

3+
import xtgeo
34
import xtgeo.cxtgeo.cxtgeo as _cxtgeo
45
from xtgeo.common import XTGeoDialog
56

@@ -31,7 +32,7 @@ def swapaxes(self):
3132
_cxtgeo.doublepointer_assign(yinc, self._yinc)
3233
_cxtgeo.doublepointer_assign(rota, self._rotation)
3334

34-
val = self.get_values1d(fill_value=self.undef)
35+
val = self.get_values1d(fill_value=xtgeo.UNDEF)
3536

3637
ier = _cxtgeo.surf_swapaxes(
3738
ncol, nrow, yflip, self.xori, xinc, self.yori, yinc, rota, val, 0, XTGDEBUG
@@ -81,7 +82,7 @@ def swapaxes(self):
8182
# xvv = np.reshape(xvv, (self._ncol, self._nrow), order='F')
8283

8384
# # make it masked
84-
# xvv = ma.masked_greater(xvv, self._undef_limit)
85+
# xvv = ma.masked_greater(xvv, xtgeo.UNDEF_LIMIT)
8586

8687
# self._values = xvv
8788

@@ -109,7 +110,7 @@ def swapaxes(self):
109110
# sys.exit(9)
110111

111112
# # make a 1D F order numpy array, and update C array
112-
# xvv = ma.filled(self._values, self._undef)
113+
# xvv = ma.filled(self._values, xtgeo.UNDEF)
113114
# xvv = np.reshape(xvv, -1, order='F')
114115

115116
# self._cvalues = _cxtgeo.new_doublearray(nnum)

0 commit comments

Comments
 (0)