Skip to content

Commit f57c437

Browse files
authored
Merge pull request #147 from jcrivenaes/xsections
Xsections
2 parents 49a0362 + 7eb4c5c commit f57c437

38 files changed

+2550
-550
lines changed

examples/wellpath_fence_sample.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import xtgeo
2+
import matplotlib.pyplot as plt
3+
4+
x = xtgeo.Polygons("../xtgeo-testdata/polygons/etc/well16.pol")
5+
y = x.copy()
6+
7+
y.rescale(10, constant=True)
8+
9+
idgroupsx = x.dataframe.groupby(x.pname)
10+
idgroupsy = y.dataframe.groupby(y.pname)
11+
12+
plt.figure(figsize=(7, 7))
13+
for id, grp in idgroupsx:
14+
plt.plot(grp[x.xname].values, grp[x.yname].values, label=str(id))
15+
16+
for id, grp in idgroupsy:
17+
plt.plot(grp[y.xname].values, grp[y.yname].values, label=str(id))
18+
plt.show()
19+
20+
print(grp[y.dhname].min(), grp[y.dhname].max())
21+
print(y.dataframe)

src/xtgeo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def _xprint(msg):
112112

113113
from xtgeo.surface import regular_surface
114114
from xtgeo.surface.regular_surface import RegularSurface
115+
from xtgeo.surface.surfaces import Surfaces
115116

116117
_xprint("Import various XTGeo modules... surface...")
117118

src/xtgeo/cube/_cube_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,14 @@ def get_randomline(
269269
zincrement=None,
270270
hincrement=None,
271271
atleast=5,
272-
extend=2,
272+
nextend=2,
273273
sampling="nearest",
274274
):
275275
"""Get a random line from a fence spesification"""
276276

277277
if isinstance(fencespec, xtgeo.Polygons):
278278
logger.info("Estimate hincrement from Polygons instance...")
279-
fencespec = _get_randomline_fence(self, fencespec, hincrement, atleast, extend)
279+
fencespec = _get_randomline_fence(self, fencespec, hincrement, atleast, nextend)
280280
logger.info("Estimate hincrement from Polygons instance... DONE")
281281

282282
if not len(fencespec.shape) == 2:
@@ -300,7 +300,7 @@ def get_randomline(
300300
if zincrement is None:
301301
zincrement = self._zinc / 2.0
302302

303-
nzsam = int((zmax - zmin) / zincrement)
303+
nzsam = int((zmax - zmin) / zincrement) + 1
304304

305305
nsamples = xcoords.shape[0] * nzsam
306306

@@ -331,23 +331,25 @@ def get_randomline(
331331
XTGDEBUG,
332332
)
333333

334+
values[values > xtgeo.UNDEF_LIMIT] = np.nan
334335
arr = values.reshape((xcoords.shape[0], nzsam)).T
335336

336337
return (hcoords[0], hcoords[-1], zmin, zmax, arr)
337338

338339

339-
def _get_randomline_fence(self, fencespec, hincrement, atleast, extend):
340+
def _get_randomline_fence(self, fencespec, hincrement, atleast, nextend):
340341
"""Compute a resampled fence from a Polygons instance"""
341342

342343
if hincrement is None:
343344
avgdxdy = 0.5 * (self.xinc + self.yinc)
344345
distance = 0.5 * avgdxdy
345346

346347
logger.info("Getting fence from a Polygons instance...")
347-
return fencespec.get_fence(
348-
distance=distance, atleast=atleast, extend=extend, asnumpy=True
348+
fspec = fencespec.get_fence(
349+
distance=distance, atleast=atleast, nextend=nextend, asnumpy=True
349350
)
350351
logger.info("Getting fence from a Polygons instance... DONE")
352+
return fspec
351353

352354

353355
# copy (update) values from SWIG carray to numpy, 3D array, Fortran order

src/xtgeo/cube/cube1.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,25 +565,25 @@ def get_randomline(
565565
zincrement=None,
566566
hincrement=None,
567567
atleast=5,
568-
extend=2,
568+
nextend=2,
569569
sampling="nearest",
570570
):
571571
"""Get a randomline from a fence spesification.
572572
573-
In prep.
574-
575573
This randomline will be a 2D numpy with depth/time on the vertical
576-
axis, and length along as horizontal axis.
574+
axis, and length along as horizontal axis. Undefined values will have
575+
the np.nan value.
577576
578-
The input fencespec is a 2D numpy where each row is X, Y, Z, HLEN,
577+
The input fencespec is either a 2D numpy where each row is X, Y, Z, HLEN,
579578
where X, Y are UTM coordinates, Z is depth/time, and HLEN is a
580-
length along the fence, or a Polygons instance with HLEN present.
579+
length along the fence, or a Polygons instance.
581580
582-
It is important that the HLEN array has a constant increment and ideally
583-
a sampling that is less than the Cube resolution.
581+
If input fencspec is a numpy 2D, it is important that the HLEN array
582+
has a constant increment and ideally a sampling that is less than the
583+
Cube resolution. If a Polygons() instance, this is automated!
584584
585585
Args:
586-
fencespec (~np.ndarray or :class:`~xtgeo.xyz.polygons.Polygons`):
586+
fencespec (:obj:`~numpy.ndarray` or :class:`~xtgeo.xyz.polygons.Polygons`):
587587
2D numpy with X, Y, Z, HLEN as rows or a xtgeo Polygons() object.
588588
zmin (float): Minimum Z (default is Cube Z minima/origin)
589589
zmax (float): Maximum Z (default is Cube Z maximum)
@@ -593,7 +593,7 @@ def get_randomline(
593593
the distance will be deduced automatically.
594594
atleast (int): Minimum number of horizontal samples (only if
595595
fencespec is a Polygons instance)
596-
extend (int): Extend with extend*hincrement in both ends (only if
596+
nextend (int): Extend with nextend * hincrement in both ends (only if
597597
fencespec is a Polygons instance)
598598
sampling (str): Algorithm, 'nearest' or 'trilinear' (first is
599599
faster, second is more precise for continuous fields)
@@ -604,9 +604,14 @@ def get_randomline(
604604
Raises:
605605
ValueError: Input fence is not according to spec.
606606
607-
.. versionadded:: 2.1.0 support for Polygons() as fencespec, and keywords
607+
.. versionchanged:: 2.1.0 support for Polygons() as fencespec, and keywords
608608
hincrement, atleast and sampling
609609
610+
.. seealso::
611+
Class :class:`~xtgeo.xyz.polygons.Polygons`
612+
The method :meth:`~xtgeo.xyz.polygons.Polygons.get_fence()` which can be
613+
used to pregenerate `fencespec`
614+
610615
"""
611616
if not isinstance(fencespec, (np.ndarray, xtgeo.Polygons)):
612617
raise ValueError("fencespec must be a numpy or a Polygons() object")
@@ -619,7 +624,7 @@ def get_randomline(
619624
zincrement=zincrement,
620625
hincrement=hincrement,
621626
atleast=atleast,
622-
extend=extend,
627+
nextend=nextend,
623628
sampling=sampling,
624629
)
625630
logger.info("Getting randomline... DONE")

src/xtgeo/cxtgeo/clib/src/grd3d_geometrics.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ int grd3d_geometrics(
9191
tmp_y = calloc(ncells, sizeof(double));
9292
tmp_z = calloc(ncells, sizeof(double));
9393

94-
95-
9694
xtgverbose(debug);
9795
xtg_speak(s,2,"Entering %s",s);
9896
xtg_speak(s,3,"NX NY NZ: %d %d %d", nx, ny, nz);
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
***************************************************************************************
3+
*
4+
* NAME:
5+
* grd3d_get_randomline.c
6+
*
7+
* AUTHOR(S):
8+
* Jan C. Rivenaes
9+
*
10+
* DESCRIPTION:
11+
* Given X Y Z vectors, return a a randomline array from a 3D grid property
12+
*
13+
* ARGUMENTS:
14+
* xvec, yvec i Arrays coords XY
15+
* zmin, zmax i Vertical range
16+
* nzsam i Vertical sampling numbering
17+
* mcol, mrow i Number of rows/cols for maps
18+
* xori..rotation i Map settings
19+
* maptopi..mapbasj i Map arrays for I J top/base
20+
* nx ny nz i Grid dimensions
21+
* p_zcorn_v i Grid Zcorn
22+
* p_coord_v i Grid ZCORN
23+
* p_acnum_v i Grid ACTNUM
24+
* p_val_v i 3D Grid values
25+
* p_zcornone_v i Grid ZCORN
26+
* p_acnumone_v i Grid ACTNUM
27+
* value o Randomline array
28+
* option i For later
29+
* debug i Debug level
30+
*
31+
* RETURNS:
32+
* Array length, -1 if fail
33+
*
34+
* TODO/ISSUES/BUGS:
35+
*
36+
* LICENCE:
37+
* cf. XTGeo LICENSE
38+
***************************************************************************************
39+
*/
40+
41+
42+
#include "libxtg.h"
43+
#include "libxtg_.h"
44+
45+
46+
/*
47+
****************************************************************************************
48+
* private function
49+
****************************************************************************************
50+
*/
51+
52+
void _get_ij_range(int *i1, int *i2, int *j1, int *j2, double xc, double yc, int mcol,
53+
int mrow, double xori, double yori, double xinc, double yinc,
54+
int yflip, double rotation, double *maptopi, double *maptopj,
55+
double *mapbasi, double *mapbasj, int debug)
56+
{
57+
char sbn[24] = "_get_ijrange";
58+
long nmap;
59+
int itop, jtop, ibas, jbas, ii1, ii2, jj1, jj2;
60+
61+
xtgverbose(debug);
62+
63+
nmap = mcol * mrow;
64+
65+
/* get map value for I J from x y */
66+
itop = surf_get_z_from_xy(xc, yc, mcol, mrow, xori, yori, xinc, yinc,
67+
yflip, rotation, maptopi, nmap, debug);
68+
jtop = surf_get_z_from_xy(xc, yc, mcol, mrow, xori, yori, xinc, yinc,
69+
yflip, rotation, maptopj, nmap, debug);
70+
ibas = surf_get_z_from_xy(xc, yc, mcol, mrow, xori, yori, xinc, yinc,
71+
yflip, rotation, mapbasi, nmap, debug);
72+
jbas = surf_get_z_from_xy(xc, yc, mcol, mrow, xori, yori, xinc, yinc,
73+
yflip, rotation, mapbasj, nmap, debug);
74+
75+
if (debug > 1) xtg_speak(sbn, 2, "ITOP IBAS JTOP JBAS %d %d %d %d...",
76+
itop, ibas, jtop, jbas);
77+
78+
if (itop <= ibas){
79+
ii1 = itop;
80+
ii2 = ibas;
81+
}
82+
else {
83+
ii1 = ibas;
84+
ii2 = itop;
85+
}
86+
87+
/* extend with one to be sure */
88+
if (ii1 > 1) ii1--;
89+
if (ii2 < mcol) ii2++;
90+
91+
if (jtop <= jbas){
92+
jj1 = jtop;
93+
jj2 = jbas;
94+
}
95+
else {
96+
jj1 = jbas;
97+
jj2 = jtop;
98+
}
99+
100+
/* extend with one to be sure */
101+
if (jj1 > 1) jj1--;
102+
if (jj2 < mrow) jj2++;
103+
104+
*i1 = ii1;
105+
*i2 = ii2;
106+
*j1 = jj1;
107+
*j2 = jj2;
108+
109+
}
110+
111+
/*
112+
****************************************************************************************
113+
* public function
114+
****************************************************************************************
115+
*/
116+
117+
int grd3d_get_randomline(
118+
double *xvec,
119+
long nxvec,
120+
double *yvec,
121+
long nyvec,
122+
double zmin,
123+
double zmax,
124+
int nzsam,
125+
126+
int mcol,
127+
int mrow,
128+
double xori,
129+
double yori,
130+
double xinc,
131+
double yinc,
132+
double rotation,
133+
int yflip,
134+
double *maptopi,
135+
double *maptopj,
136+
double *mapbasi,
137+
double *mapbasj,
138+
139+
int nx,
140+
int ny,
141+
int nz,
142+
double *p_coor_v,
143+
double *p_zcorn_v,
144+
int *p_actnum_v,
145+
double *p_val_v,
146+
double *p_zcornone_v,
147+
int *p_actnumone_v,
148+
149+
double *values,
150+
long nvalues,
151+
152+
int option,
153+
int debug
154+
)
155+
{
156+
/* locals */
157+
char sbn[24] = "grd3d_get_randomline";
158+
int ib, ic, izc, ier, ios, i1, i2, j1, j2, k1, k2;
159+
long ibs1, ibs2;
160+
double zsam, xc, yc, zc;
161+
double value, *p_dummy_v;
162+
163+
xtgverbose(debug);
164+
165+
if (debug > 2) xtg_speak(sbn, 3, "Entering routine %s", sbn);
166+
167+
zsam = (zmax - zmin) / (nzsam - 1);
168+
169+
ib = 0;
170+
171+
ibs1 = -1;
172+
ibs2 = -1;
173+
174+
k1 = 1;
175+
k2 = nz;
176+
177+
xtg_speak(sbn, 2, "Total number of XY poinst and Z points are %d %d", nxvec, nzsam);
178+
179+
for (ic = 0; ic < nxvec; ic++) {
180+
xc = xvec[ic];
181+
yc = yvec[ic];
182+
if (debug > 1) xtg_speak(sbn, 2, "Column %d... X Y %f12.2 %f12.2", ic, xc, yc);
183+
184+
_get_ij_range(&i1, &i2, &j1, &j2, xc, yc, mcol, mrow, xori, yori, xinc, yinc,
185+
yflip, rotation, maptopi, maptopj, mapbasi, mapbasj, debug);
186+
187+
if (debug > 1) xtg_speak(sbn, 2, "I J range %d %d %d %d...", i1, i2, j1, j2);
188+
189+
for (izc = 0; izc < nzsam; izc++) {
190+
191+
zc = zmin + izc * zsam;
192+
193+
/* check the onelayer version of the grid first (speed up) */
194+
ier = grd3d_point_val_crange(xc, yc, zc, nx, ny, 1, p_coor_v,
195+
p_zcornone_v, p_actnumone_v, p_dummy_v, &value,
196+
i1, i2, j1, j2, 1, 1, &ibs1, -1, debug);
197+
198+
199+
if (ier == 0) {
200+
201+
if (debug > 2 && ier == 0) xtg_speak(sbn, 3, "Trying K1 K2 %d %d",
202+
k1, k2);
203+
204+
ios = grd3d_point_val_crange(xc, yc, zc, nx, ny, nz, p_coor_v,
205+
p_zcorn_v, p_actnum_v, p_val_v,
206+
&value, i1, i2, j1, j2, k1, k2,
207+
&ibs2, 0, debug);
208+
209+
if (ios == 0) {
210+
values[ib++] = value;
211+
}
212+
else{
213+
values[ib++] = UNDEF;
214+
}
215+
216+
}
217+
else{
218+
/* outside onelayer cell */
219+
values[ib++] = UNDEF;
220+
continue;
221+
}
222+
}
223+
}
224+
225+
if (debug > 2) xtg_speak(sbn, 3, "Done ...");
226+
227+
return EXIT_SUCCESS;
228+
229+
}

0 commit comments

Comments
 (0)