-
Notifications
You must be signed in to change notification settings - Fork 58
/
grid3d_crop.py
61 lines (40 loc) · 1.44 KB
/
grid3d_crop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Crop a 3D grid.
"""
import pathlib
import tempfile
import xtgeo
EXPATH1 = pathlib.Path("../../xtgeo-testdata/3dgrids/reek")
GRIDFILEROOT = EXPATH1 / "REEK"
INITPROPS = ["PORO", "PERMX"]
TMPDIR = pathlib.Path(tempfile.gettempdir())
def cropper():
"""Do a cropping of a 3D grid"""
grd = xtgeo.grid_from_file(GRIDFILEROOT, fformat="eclipserun", initprops=INITPROPS)
print(grd.props)
# find current NCOL, NROW and divide into 4 pieces
ncol = grd.ncol
nrow = grd.nrow
nlay = grd.nlay
ncol1 = int(ncol / 2)
nrow1 = int(nrow / 2)
print("Original grid dimensions are {} {} {}".format(ncol, nrow, nlay))
print("Crop ranges are {} {} {}".format(ncol1, nrow1, nlay))
ncolranges = [(1, ncol1), (ncol1 + 1, ncol)]
nrowranges = [(1, nrow1), (nrow1 + 1, nrow)]
for ncr in ncolranges:
nc1, nc2 = ncr
for nrr in nrowranges:
nr1, nr2 = nrr
fname = "_{}-{}_{}-{}".format(nc1, nc2, nr1, nr2)
tmpgrd = grd.copy()
tmpgrd.crop(ncr, nrr, (1, nlay), props="all")
# save to disk as ROFF files
tmpgrd.to_file(TMPDIR / ("grid" + fname + ".roff"))
for prop in tmpgrd.props:
print("{} for {} .. {}".format(prop.name, ncr, nrr))
fname2 = prop.name + fname + ".roff"
fname2 = fname2.lower()
prop.to_file(TMPDIR / fname2)
if __name__ == "__main__":
cropper()