def test_cube_slice_w_dead_traces_trilinear(): """Get cube slice trilinear aka Auto4D input, with scrambled data with dead traces to be ignored, various YFLIP cases.""" cube1 = Cube(xcub2) surf1 = xtgeo.surface_from_cube(cube1, 1000.0) cells = [(18, 12)] surf1.slice_cube(cube1, sampling='trilinear', snapxy=True, deadtraces=True) plotfile = ojn(td, 'slice_tri1_dead.png') title = 'Cube with dead traces; trilinear; UNDEF at dead traces' surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) ndead = (cube1.traceidcodes == 2).sum() for cell in cells: icell, jcell = cell assert surf1.values[icell, jcell] == \ pytest.approx(cube1.values[icell, jcell, 0], 0.1) assert ma.count_masked(surf1.values) == ndead # swap cube only surf2 = surf1.copy() surf2.values = 1000.0 cube2 = cube1.copy() cube2.swapaxes() surf2.slice_cube(cube2, sampling='trilinear', deadtraces=True) plotfile = ojn(td, 'slice_tri1__dead_cubeswap.png') surf2.quickplot(filename=plotfile, minmax=(-10000, 10000)) assert ma.count_masked(surf2.values) == ndead assert surf2.values.mean() == surf1.values.mean()
def test_cube_attr_mean_two_surfaces_multiattr(load_cube_rsgy1): """Get cube attribute (mean) between two surfaces, many attr at the same time. """ logger.info("Loading surfaces {} {}".format(RTOP1, RBAS1)) xs1 = RegularSurface(RTOP1) xs2 = RegularSurface(RBAS1) logger.info("Loading cube {}".format(RSGY1)) kube = load_cube_rsgy1 xss = xs1.copy() xss.slice_cube_window( kube, other=xs2, other_position="below", attribute="rms", sampling="trilinear", showprogress=True, ) logger.debug(xss.values.mean()) xsx = xs1.copy() attrs = xsx.slice_cube_window( kube, other=xs2, other_position="below", attribute=["max", "mean", "min", "rms"], sampling="trilinear", showprogress=True, ) logger.debug(attrs["rms"].values.mean()) assert xss.values.mean() == attrs["rms"].values.mean() assert xss.values.std() == attrs["rms"].values.std() for attr in attrs.keys(): logger.info("Working with %s", attr) xxx = attrs[attr] xxx.to_file(ojn(td, "surf_slice_cube_2surf_" + attr + "multi.gri")) minmax = (None, None) if attr == "mean": minmax = (-0.1, 0.1) xxx.quickplot( filename=ojn(td, "surf_slice_cube_2surf_" + attr + "multi.png"), colortable="jet", minmax=minmax, title="Reek two surfs mean multiattr: " + attr, infotext="Method: trilinear, 2 surfs multiattr " + attr, )
def test_cube_attr_mean_two_surfaces_multiattr(load_cube_rsgy1): """Get cube attribute (mean) between two surfaces, many attr at the same time. """ logger.info('Loading surfaces {} {}'.format(rtop1, rbas1)) xs1 = RegularSurface(rtop1) xs2 = RegularSurface(rbas1) logger.info('Loading cube {}'.format(rsgy1)) kube = load_cube_rsgy1 xss = xs1.copy() xss.slice_cube_window(kube, other=xs2, other_position='below', attribute='rms', sampling='trilinear', showprogress=True) logger.debug(xss.values.mean()) xsx = xs1.copy() attrs = xsx.slice_cube_window(kube, other=xs2, other_position='below', attribute=['max', 'mean', 'min', 'rms'], sampling='trilinear', showprogress=True) logger.debug(attrs['rms'].values.mean()) assert xss.values.mean() == attrs['rms'].values.mean() assert xss.values.std() == attrs['rms'].values.std() for attr in attrs.keys(): logger.info('Working with %s', attr) xxx = attrs[attr] xxx.to_file(ojn(td, 'surf_slice_cube_2surf_' + attr + 'multi.gri')) minmax = (None, None) if attr == 'mean': minmax = (-0.1, 0.1) xxx.quickplot(filename=ojn( td, 'surf_slice_cube_2surf_' + attr + 'multi.png'), colortable='jet', minmax=minmax, title='Reek two surfs mean multiattr: ' + attr, infotext='Method: trilinear, 2 surfs multiattr ' + attr)
def test_get_surface_from_grd3d_zones(): """Sample a surface from a 3D grid, using zones""" surf = xtgeo.surface.RegularSurface(rtop1) grd = xtgeo.grid3d.Grid(rgrd2, fformat='roff') surf.values = 1700 zone = xtgeo.grid3d.GridProperty(rprop2, fformat='roff', name='Zone', grid=grd) # slice grd3d surf.slice_grid3d(grd, zone, sbuffer=1) surf.to_file(ojn(td, 'surf_slice_grd3d_reek_zone.gri')) surf.quickplot(filename=ojn(td, 'surf_slice_grd3d_reek_zone.png'))
def test_surface_from_grd3d_layer(): """Create a surface from a 3D grid layer""" surf = xtgeo.surface.RegularSurface() grd = xtgeo.grid3d.Grid(rgrd2, fformat='roff') # grd = xtgeo.Grid("../xtgeo-testdata-equinor/data/3dgrids/gfb/gullfaks_gg.roff") surf.from_grid3d(grd) surf.fill() surf.to_file(ojn(td, 'surf_from_grid3d_top.gri')) tmp = surf.copy() surf.quickplot(filename=ojn(td, 'surf_from_grid3d_top.png')) surf.from_grid3d(grd, template=tmp, mode="i") surf.to_file(ojn(td, 'surf_from_grid3d_top_icell.gri')) surf.quickplot(filename=ojn(td, 'surf_from_grid3d_top_icell.png')) surf.from_grid3d(grd, template=tmp, mode="j") surf.fill() surf.to_file(ojn(td, 'surf_from_grid3d_top_jcell.gri')) surf.quickplot(filename=ojn(td, 'surf_from_grid3d_top_jcell.png')) surf.from_grid3d(grd, template=tmp, mode="depth", where="3_base") surf.to_file(ojn(td, 'surf_from_grid3d_3base.gri')) surf.quickplot(filename=ojn(td, 'surf_from_grid3d_3base.png'))
def test_cube_slice_w_ignore_dead_traces_trilinear(): """Get cube slice trilinear aka Auto4D input, with scrambled data with dead traces to be ignored, various YFLIP cases.""" cube1 = Cube(XCUB2) surf1 = RegularSurface() surf1.from_cube(cube1, 1000.0) cells = [(18, 12), (20, 2), (0, 4)] surf1.slice_cube(cube1, sampling="trilinear", snapxy=True, deadtraces=False) plotfile = ojn(td, "slice_tri1.png") title = "Cube with dead traces; trilinear; keep as is at dead traces" surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) for cell in cells: icell, jcell = cell assert surf1.values[icell, jcell] == pytest.approx(cube1.values[icell, jcell, 0], abs=0.1) assert ma.count_masked(surf1.values) == 0 # shall be no masked cells
def test_get_surface_from_grd3d_zones(): """Sample a surface from a 3D grid, using zones""" surf = xtgeo.surface.RegularSurface(RTOP1) grd = xtgeo.grid3d.Grid(RGRD2, fformat="roff") surf.values = 1700 zone = xtgeo.grid3d.GridProperty(RPROP2, fformat="roff", name="Zone", grid=grd) # slice grd3d surf.slice_grid3d(grd, zone, sbuffer=1) surf.to_file(ojn(td, "surf_slice_grd3d_reek_zone.gri")) surf.quickplot(filename=ojn(td, "surf_slice_grd3d_reek_zone.png"))
def show_stats(): """Get statistics for one realisation, poro/perm filtered on facies. But note that values here are unweighted as total volume is not present. """ # read grid grd = xtgeo.grid_from_file(GRIDFILE) # read facies (to be used as filter) facies = xtgeo.gridproperty_from_file(FACIESFILE, name=FACIES, grid=grd) print("Facies codes are: {}".format(facies.codes)) for propname in PROPS: pfile = ojn(EXPATH1, ROOT + "--" + propname + EXT) pname = "geogrid--" + propname prop = xtgeo.gridproperty_from_file(pfile, name=pname, grid=grd) print("Working with {}".format(prop.name)) # now find statistics for each facies, and all facies for key, fname in facies.codes.items(): avg = prop.values[facies.values == key].mean() std = prop.values[facies.values == key].std() print("For property {} in facies {}, avg is {:10.3f} and " "stddev is {:9.3f}".format(propname, fname, avg, std)) avg = prop.values.mean() std = prop.values.std() print("For property {} in ALL facies, avg is {:10.3f} and " "stddev is {:9.3f}".format(propname, avg, std))
def test_cube_slice_w_ignore_dead_traces_nearest(): """Get cube slice nearest aka Auto4D input, with scrambled data with dead traces, various YFLIP cases, ignore dead traces.""" cube1 = Cube(XCUB2) surf1 = RegularSurface() surf1.from_cube(cube1, 1000.1) cells = ((18, 12), (20, 2), (0, 4)) surf1.slice_cube(cube1, deadtraces=False) plotfile = ojn(td, "slice_nea1.png") title = "Cube with dead traces; nearest; use just values as is" surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) for cell in cells: icell, jcell = cell assert surf1.values[icell, jcell] == pytest.approx(cube1.values[icell, jcell, 0], abs=0.01) assert ma.count_masked(surf1.values) == 0 # shall be no masked cells # swap surface surf2 = surf1.copy() surf2.values = 1000.1 surf2.swapaxes() surf2.slice_cube(cube1, deadtraces=False) assert surf2.values.mean() == pytest.approx(surf1.values.mean(), rel=0.001) # swap surface and cube surf2 = surf1.copy() surf2.values = 1000.1 surf2.swapaxes() cube2 = cube1.copy() cube2.swapaxes() surf2.slice_cube(cube2, deadtraces=False) assert surf2.values.mean() == pytest.approx(surf1.values.mean(), rel=0.001) # swap cube only surf2 = surf1.copy() surf2.values = 1000.1 cube2 = cube1.copy() cube2.swapaxes() surf2.slice_cube(cube2, deadtraces=False) assert surf2.values.mean() == pytest.approx(surf1.values.mean(), rel=0.001)
def test_cube_slice_auto4d_data(): """Get cube slice aka Auto4D input, with synthetic/scrambled data""" xs1 = RegularSurface(XTOP1, fformat="gri") xs1.describe() xs1out = ojn(td, "XTOP1.ijxyz") xs1.to_file(xs1out, fformat="ijxyz") xs2 = RegularSurface(xs1out, fformat="ijxyz") assert xs1.values.mean() == pytest.approx(xs2.values.mean(), abs=0.0001) kube1 = Cube(XCUB1) kube1.describe() assert xs2.nactive == 10830 xs2.slice_cube_window(kube1, sampling="trilinear", mask=True, attribute="max") xs2out1 = ojn(td, "XTOP2_sampled_from_cube.ijxyz") xs2out2 = ojn(td, "XTOP2_sampled_from_cube.gri") xs2out3 = ojn(td, "XTOP2_sampled_from_cube.png") xs2.to_file(xs2out1, fformat="ijxyz") xs2.to_file(xs2out2) assert xs2.nactive == 3275 # 3320 # shall be fewer cells xs2.quickplot( filename=xs2out3, colortable="seismic", title="Auto4D Test", minmax=(0, 12000), infotext="Method: max", )
def test_cube_slice_w_dead_traces_nearest(): """Get cube slice nearest aka Auto4D input, with scrambled data with dead traces, various YFLIP cases, undef at dead traces.""" cube1 = Cube(XCUB2) surf1 = RegularSurface() surf1.from_cube(cube1, 1000.1) cells = ((18, 12), ) surf1.slice_cube(cube1, deadtraces=True, algorithm=1) plotfile = ojn(td, "slice_nea1_dead1.png") title = "Cube with dead traces; nearest; UNDEF at dead traces" surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) for cell in cells: icell, jcell = cell assert surf1.values[icell, jcell] == cube1.values[icell, jcell, 0] ndead = (cube1.traceidcodes == 2).sum() assert ma.count_masked(surf1.values) == ndead surf2 = RegularSurface() surf2.from_cube(cube1, 1000.1) surf2.slice_cube(cube1, deadtraces=True, algorithm=2) plotfile = ojn(td, "slice_nea1_dead2.png") title = "Cube with dead traces; nearest; UNDEF at dead traces algo 2" surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) for cell in cells: icell, jcell = cell assert surf2.values[icell, jcell] == cube1.values[icell, jcell, 0] ndead = (cube1.traceidcodes == 2).sum() assert ma.count_masked(surf1.values) == ndead
def test_cube_slice_auto4d_data(): """Get cube slice aka Auto4D input, with synthetic/scrambled data""" xs1 = RegularSurface(xtop1, fformat='gri') xs1.describe() xs1out = ojn(td, 'xtop1.ijxyz') xs1.to_file(xs1out, fformat='ijxyz') xs2 = RegularSurface(xs1out, fformat='ijxyz') assert xs1.values.mean() == pytest.approx(xs2.values.mean(), abs=0.0001) kube1 = Cube(xcub1) kube1.describe() assert xs2.nactive == 10830 xs2.slice_cube_window(kube1, sampling='trilinear', mask=True, attribute='max') xs2out1 = ojn(td, 'xtop2_sampled_from_cube.ijxyz') xs2out2 = ojn(td, 'xtop2_sampled_from_cube.gri') xs2out3 = ojn(td, 'xtop2_sampled_from_cube.png') xs2.to_file(xs2out1, fformat='ijxyz') xs2.to_file(xs2out2) assert xs2.nactive == 3320 # shall be fewer cells xs2.quickplot(filename=xs2out3, colortable='seismic', title='Auto4D Test', minmax=(0, 12000), infotext='Method: max')
def test_cube_slice_w_dead_traces_nearest(): """Get cube slice nearest aka Auto4D input, with scrambled data with dead traces, various YFLIP cases, undef at dead traces.""" cube1 = Cube(xcub2) surf1 = RegularSurface() surf1.from_cube(cube1, 1000.1) cells = ((18, 12), ) surf1.slice_cube(cube1, deadtraces=True) plotfile = ojn(td, 'slice_nea1_dead.png') title = 'Cube with dead traces; nearest; UNDEF at dead traces' surf1.quickplot(filename=plotfile, minmax=(-10000, 10000), title=title) for cell in cells: icell, jcell = cell assert surf1.values[icell, jcell] == cube1.values[icell, jcell, 0] ndead = (cube1.traceidcodes == 2).sum() print(ndead) assert ma.count_masked(surf1.values) == ndead # swap cube only surf2 = surf1.copy() surf2.values = 1000.1 cube2 = cube1.copy() cube2.swapaxes() surf2.slice_cube(cube2, deadtraces=True) plotfile = ojn(td, 'slice_nea1_dead_cubeswap.png') surf2.quickplot(filename=plotfile, minmax=(-10000, 10000)) assert ma.count_masked(surf2.values) == ndead assert surf2.values.mean() == surf1.values.mean()
def test_get_surface_from_grd3d_porosity(): """Sample a surface from a 3D grid""" surf = xtgeo.surface.RegularSurface(rtop1) print(surf.values.min(), surf.values.max()) grd = xtgeo.grid3d.Grid(rgrd1, fformat="egrid") surf.values = 1700 zsurf = surf.copy() surfr = surf.copy() surf2 = surf.copy() phi = xtgeo.grid3d.GridProperty(rprop1, fformat="init", name="PORO", grid=grd) # slice grd3d surf.slice_grid3d(grd, phi) surf.to_file(ojn(td, "surf_slice_grd3d_reek.gri")) surf.quickplot(filename=ojn(td, "surf_slice_grd3d_reek.png")) # refined version: surfr.refine(2) surfr.slice_grid3d(grd, phi) surfr.to_file(ojn(td, "surf_slice_grd3d_reek_refined.gri")) surfr.quickplot(filename=ojn(td, "surf_slice_grd3d_reek_refined.png")) # use zsurf: surf2.slice_grid3d(grd, phi, zsurf=zsurf) surf2.to_file(ojn(td, "surf_slice_grd3d_reek_zslice.gri")) surf2.quickplot(filename=ojn(td, "surf_slice_grd3d_reek_zslice.png")) assert np.allclose(surf.values, surf2.values) tsetup.assert_almostequal(surf.values.mean(), 0.1667, 0.01) tsetup.assert_almostequal(surfr.values.mean(), 0.1667, 0.01)
xtg = XTGeoDialog() logger = xtg.basiclogger(__name__) if not xtg.testsetup(): raise SystemExit td = xtg.tmpdir # ============================================================================= # Do tests # ============================================================================= rpath1 = '../xtgeo-testdata/surfaces/reek' rpath2 = '../xtgeo-testdata/3dgrids/reek' rtop1 = ojn(rpath1, '1/topreek_rota.gri') rgrd1 = ojn(rpath2, 'REEK.EGRID') rprop1 = ojn(rpath2, 'REEK.INIT') rgrd2 = ojn(rpath2, 'reek_sim_grid.roff') rprop2 = ojn(rpath2, 'reek_sim_zone.roff') @tsetup.plotskipifroxar def test_get_surface_from_grd3d_porosity(): """Sample a surface from a 3D grid""" surf = xtgeo.surface.RegularSurface(rtop1) print(surf.values.min(), surf.values.max()) grd = xtgeo.grid3d.Grid(rgrd1, fformat='egrid') surf.values = 1700 zsurf = surf.copy()
logger = xtg.basiclogger(__name__) if not xtg.testsetup(): sys.exit(-9) td = xtg.tmpdir # ============================================================================= # Do tests # ============================================================================= rpath1 = '../xtgeo-testdata/surfaces/reek' rpath3 = '../xtgeo-testdata/surfaces/etc' rpath2 = '../xtgeo-testdata/cubes/reek' rpath4 = '../xtgeo-testdata/cubes/etc' rtop1 = ojn(rpath1, '1/topreek_rota.gri') rbas1 = ojn(rpath1, '1/basereek_rota.gri') rbas2 = ojn(rpath1, '1/basereek_rota_v2.gri') rsgy1 = ojn(rpath2, 'syntseis_20000101_seismic_depth_stack.segy') xtop1 = ojn(rpath3, 'ib_test_horizon2.gri') xcub1 = ojn(rpath4, 'ib_test_cube2.segy') xcub2 = ojn(rpath4, 'cube_w_deadtraces.segy') @pytest.fixture() def load_cube_rsgy1(): """Loading test cube (pytest setup fixture)""" logger.info('Load cube rsgy1') return Cube(rsgy1)
# -*- coding: utf-8 -*- """Compute statistics within one realisation, using ROFF or RMS internal.""" from os.path import join as ojn import xtgeo EXPATH1 = "../../xtgeo-testdata/3dgrids/reek2" ROOT = "geogrid" EXT = ".roff" GRIDFILE = ojn(EXPATH1, ROOT + EXT) PROPS = ["perm", "poro"] FACIES = "facies" FACIESFILE = ojn(EXPATH1, ROOT + "--" + FACIES + EXT) def show_stats(): """Get statistics for one realisation, poro/perm filtered on facies. But note that values here are unweighted as total volume is not present. """ # read grid grd = xtgeo.grid_from_file(GRIDFILE) # read facies (to be used as filter) facies = xtgeo.gridproperty_from_file(FACIESFILE, name=FACIES, grid=grd) print("Facies codes are: {}".format(facies.codes)) for propname in PROPS:
from xtgeo.common import XTGeoDialog import tests.test_common.test_xtg as tsetup xtg = XTGeoDialog() logger = xtg.basiclogger(__name__) if not xtg.testsetup(): raise SystemExit td = xtg.tmpdir RPATH1 = "../xtgeo-testdata/surfaces/reek" RPATH3 = "../xtgeo-testdata/surfaces/etc" RPATH2 = "../xtgeo-testdata/cubes/reek" RPATH4 = "../xtgeo-testdata/cubes/etc" RTOP1 = ojn(RPATH1, "1/topreek_rota.gri") RBAS1 = ojn(RPATH1, "1/basereek_rota.gri") RBAS2 = ojn(RPATH1, "1/basereek_rota_v2.gri") RSGY1 = ojn(RPATH2, "syntseis_20000101_seismic_depth_stack.segy") XTOP1 = ojn(RPATH3, "ib_test_horizon2.gri") XCUB1 = ojn(RPATH4, "ib_test_cube2.segy") XCUB2 = ojn(RPATH4, "cube_w_deadtraces.segy") @pytest.fixture() def load_cube_rsgy1(): """Loading test cube (pytest setup fixture)""" logger.info("Load cube RSGY1") return Cube(RSGY1)
xtg = XTGeoDialog() logger = xtg.basiclogger(__name__) if not xtg.testsetup(): raise SystemExit td = xtg.tmpdir # ============================================================================= # Do tests # ============================================================================= rpath1 = "../xtgeo-testdata/surfaces/reek" rpath2 = "../xtgeo-testdata/3dgrids/reek" rtop1 = ojn(rpath1, "1/topreek_rota.gri") rgrd1 = ojn(rpath2, "REEK.EGRID") rprop1 = ojn(rpath2, "REEK.INIT") rgrd2 = ojn(rpath2, "reek_sim_grid.roff") rprop2 = ojn(rpath2, "reek_sim_zone.roff") @tsetup.plotskipifroxar @tsetup.skipifmac # segm fault; need to be investigated def test_get_surface_from_grd3d_porosity(): """Sample a surface from a 3D grid""" surf = xtgeo.surface.RegularSurface(rtop1) print(surf.values.min(), surf.values.max()) grd = xtgeo.grid3d.Grid(rgrd1, fformat="egrid") surf.values = 1700
""" Compute statistics of N realisations. In this the realisations are "faked" by just adding a constant to each loop. It provides and insight on memory handling and speed. """ import io from os.path import join as ojn import numpy.ma as npma import xtgeo # from memory_profiler import profile EXPATH1 = '../../xtgeo-testdata/surfaces/reek/2/01_topreek_rota.gri' GRIDFILEROOT = ojn(EXPATH1, 'REEK') NRUN = 1000 def sum_running_stats(): """Find avg per realisation and do a cumulative rolling mean. Memory consumption shall be very low. """ for irel in range(NRUN): # load as Eclipse run; this will look for EGRID, INIT, UNRST print('Loading realization no {}'.format(irel))
""" Compute statistics of N realisations. In this the realisations are "faked" by just adding a constant to each loop. It provides and insight on memory handling and speed. """ import io from os.path import join as ojn import numpy.ma as npma import xtgeo # from memory_profiler import profile EXPATH1 = "../../xtgeo-testdata/surfaces/reek/2/01_topreek_rota.gri" GRIDFILEROOT = ojn(EXPATH1, "REEK") NRUN = 1000 def sum_running_stats(): """Find avg per realisation and do a cumulative rolling mean. Memory consumption shall be very low. """ for irel in range(NRUN): # load as Eclipse run; this will look for EGRID, INIT, UNRST print("Loading realization no {}".format(irel))