def test_io_ecl2roff_discrete(): """Import Eclipse discrete property; then export to ROFF int.""" logger.info("Name is {}".format(__name__)) po = GridProperty() mygrid = Grid(TESTFILE5) po.from_file(TESTFILE6, fformat="init", name="SATNUM", grid=mygrid) print(po.codes) assert po.ncodes == 1 assert isinstance(po.codes[1], str) po.to_file( os.path.join(TMPDIR, "ecl2roff_disc.roff"), name="SATNUM", fformat="roff" )
def test_io_ecl2roff_discrete(): """Import Eclipse discrete property; then export to ROFF int.""" logger.info('Name is {}'.format(__name__)) po = GridProperty() mygrid = Grid(testfile5) po.from_file(testfile6, fformat="init", name='SATNUM', grid=mygrid) print(po.codes) assert po.ncodes == 1 assert isinstance(po.codes[1], str) po.to_file(os.path.join(td, 'ecl2roff_disc.roff'), name='SATNUM', fformat='roff')
def test_eclinit_import_reek(): """Property import from Eclipse. Reek""" # let me guess the format (shall be egrid) gg = Grid(testfile5, fformat='egrid') assert gg.ncol == 40, "Reek NX" logger.info("Import INIT...") po = GridProperty(testfile6, name='PORO', grid=gg) logger.info(po.values.mean()) assert po.values.mean() == pytest.approx(0.1677, abs=0.0001) pv = GridProperty(testfile6, name='PORV', grid=gg) logger.info(pv.values.mean())
def test_pathlib(): """Import and export via pathlib""" pfile = pathlib.Path(DUALFIL1) grd = Grid() grd.from_file(pfile) assert grd.dimensions == (5, 3, 1) out = pathlib.Path() / TMPDIR / "grdpathtest.roff" grd.to_file(out, fformat="roff") with pytest.raises(OSError): out = pathlib.Path() / "nosuchdir" / "grdpathtest.roff" grd.to_file(out, fformat="roff")
def test_avg02(): """Make average map from Reek Eclipse.""" g = Grid() g.from_file(gfile2, fformat="egrid") # get the poro po = GridProperty() po.from_file(ifile2, fformat='init', name='PORO', grid=g) # get the dz and the coordinates dz = g.get_dz(mask=False) xc, yc, zc = g.get_xyz(mask=False) # get actnum actnum = g.get_actnum() # convert from masked numpy to ordinary xcuse = np.copy(xc.values3d) ycuse = np.copy(yc.values3d) dzuse = np.copy(dz.values3d) pouse = np.copy(po.values3d) # dz must be zero for undef cells dzuse[actnum.values3d < 0.5] = 0.0 pouse[actnum.values3d < 0.5] = 0.0 # make a map... estimate from xc and yc zuse = np.ones((xcuse.shape)) avgmap = RegularSurface(nx=200, ny=250, xinc=50, yinc=50, xori=457000, yori=5927000, values=np.zeros((200, 250))) avgmap.avg_from_3dprop(xprop=xcuse, yprop=ycuse, zoneprop=zuse, zone_minmax=(1, 1), mprop=pouse, dzprop=dzuse, truncate_le=None) # add the faults in plot fau = Polygons(ffile1, fformat='zmap') fspec = {'faults': fau} avgmap.quickplot(filename='TMP/tmp_poro2.png', xlabelrotation=30, faults=fspec) avgmap.to_file('TMP/tmp.poro.gri', fformat='irap_ascii') logger.info(avgmap.values.mean()) assert avgmap.values.mean() == pytest.approx(0.1653, abs=0.01)
def test_hybridgrid2(): """Making a hybridgrid for Emerald case in region""" logger.info('Read grid...') grd = Grid(EMEGFILE) logger.info('Read grid... done, NLAY is {}'.format(grd.nlay)) reg = GridProperty() reg.from_file(EMERFILE, name='REGION') nhdiv = 40 grd.convert_to_hybrid(nhdiv=nhdiv, toplevel=1650, bottomlevel=1690, region=reg, region_number=1) grd.to_file('TMP/test_hybridgrid2.roff')
def test_make_ijk_gf_geogrid(): """Import well from and a large geogrid and make I J K logs""" logger.info("Running test... %s", __name__) mywell = Well(WGULLFILE) mygrid = Grid(GGULLFILE) logger.info("Number of cells in grid is %s", mygrid.ntotal) mywell.make_ijk_from_grid(mygrid) df = mywell.dataframe assert int(df.iloc[16120]["ICELL"]) == 68 assert int(df.iloc[16120]["JCELL"]) == 204 assert int(df.iloc[16120]["KCELL"]) == 15
def test_reverse_row_axis_eme(): """Reverse axis for emerald grid""" grd1 = Grid(EMEGFILE) assert grd1.ijk_handedness == "left" grd1.to_file(join(TDP, "eme_left.roff"), fformat="roff") grd2 = grd1.copy() geom1 = grd1.get_geometrics(return_dict=True) grd2.reverse_row_axis() assert grd2.ijk_handedness == "right" grd2.to_file(join(TDP, "eme_right.roff"), fformat="roff") geom2 = grd2.get_geometrics(return_dict=True) tsetup.assert_almostequal(geom1["avg_rotation"], geom2["avg_rotation"], 0.01)
def test_geometrics_reek(): """Import Reek and test geometrics.""" grd = Grid(REEKFILE, fformat="egrid") geom = grd.get_geometrics(return_dict=True, cellcenter=False) for key, val in geom.items(): logger.info("%s is %s", key, val) # compared with RMS info: tsetup.assert_almostequal(geom["xmin"], 456510.6, 0.1, "Xmin") tsetup.assert_almostequal(geom["ymax"], 5938935.5, 0.1, "Ymax") # cellcenter True: geom = grd.get_geometrics(return_dict=True, cellcenter=True) tsetup.assert_almostequal(geom["xmin"], 456620, 1, "Xmin cell center")
def test_eclinit_simple_importexport(tmpdir): """Property import and export with anoother name""" # let me guess the format (shall be egrid) gg = Grid(TESTFILE13A, fformat="egrid") po = GridProperty(TESTFILE13B, name="PORO", grid=gg) po.to_file( os.path.join(tmpdir, "simple.grdecl"), fformat="grdecl", name="PORO2", fmt="%12.5f", ) p2 = GridProperty(os.path.join(tmpdir, "simple.grdecl"), grid=gg, name="PORO2") assert p2.name == "PORO2"
def test_get_dataframe(): """Get a Pandas dataframe from the gridproperties""" g = Grid(GFILE1, fformat="egrid") x = GridProperties() names = ["SOIL", "SWAT", "PRESSURE"] dates = [19991201] x.from_file(RFILE1, fformat="unrst", names=names, dates=dates, grid=g) df = x.dataframe(activeonly=True, ijk=True, xyz=False) print(df.head()) assert df["SWAT_19991201"].mean() == pytest.approx(0.87802, abs=0.001) assert df["PRESSURE_19991201"].mean() == pytest.approx(334.523, abs=0.005)
def test_import_should_pass(): """Import INIT and UNRST but ask for wrong name or date , using strict=False""" g = Grid() g.from_file(GFILE1, fformat="egrid") rx = GridProperties() names = ["PRESSURE", "DUMMY"] # dummy should exist dates = [19991201, 19991212] # last date does not exist rx.from_file( RFILE1, fformat="unrst", names=names, dates=dates, grid=g, strict=(False, False) ) assert "PRESSURE_19991201" in rx assert "PRESSURE_19991212" not in rx assert "DUMMY_19991201" not in rx
def test_reverse_row_axis_box(tmpdir): """Crop a grid.""" grd = Grid() grd.create_box( origin=(1000, 4000, 300), increment=(100, 100, 2), dimension=(2, 3, 1), rotation=0, ) assert grd.ijk_handedness == "left" grd.to_file(join(tmpdir, "reverse_left.grdecl"), fformat="grdecl") grd.reverse_row_axis() assert grd.ijk_handedness == "right" grd.to_file(join(tmpdir, "reverse_right.grdecl"), fformat="grdecl")
def test_hybridgrid2(tmpdir): """Making a hybridgrid for Emerald case in region""" logger.info("Read grid...") grd = Grid(EMEGFILE) logger.info("Read grid... done, NLAY is {}".format(grd.nlay)) reg = GridProperty() reg.from_file(EMERFILE, name="REGION") nhdiv = 40 grd.convert_to_hybrid( nhdiv=nhdiv, toplevel=1650, bottomlevel=1690, region=reg, region_number=1 ) grd.to_file(join(tmpdir, "test_hybridgrid2.roff"))
def test_to_from_grdeclgrid(grdecl_grid): xtggrid = Grid() xtggrid._actnumsv = grdecl_grid.xtgeo_actnum() xtggrid._coordsv = grdecl_grid.xtgeo_coord() xtggrid._zcornsv = grdecl_grid.xtgeo_zcorn() nx, ny, nz = grdecl_grid.dimensions xtggrid._ncol = nx xtggrid._nrow = ny xtggrid._nlay = nz xtggrid._xtgformat = 2 grdecl_grid2 = ggrid.GrdeclGrid.from_xtgeo_grid(xtggrid) assert grdecl_grid2.xtgeo_actnum().tolist() == xtggrid._actnumsv.tolist() assert grdecl_grid2.xtgeo_coord() == pytest.approx(xtggrid._coordsv, abs=0.02) assert grdecl_grid2.xtgeo_zcorn() == pytest.approx(xtggrid._zcornsv, abs=0.02)
def test_eclunrst_import_soil_reek(): """Property UNRST import from Eclipse, computing SOIL. Reek""" gg = Grid(TESTFILE5, fformat="egrid") logger.info("Import RESTART (UNIFIED) ...") swat = GridProperty(TESTFILE7, name="SWAT", fformat="unrst", date=19991201, grid=gg) tsetup.assert_almostequal(swat.values.mean(), 0.8780, 0.001) sgas = GridProperty(TESTFILE7, name="SGAS", fformat="unrst", date=19991201, grid=gg) tsetup.assert_almostequal(sgas.values.mean(), 0.000, 0.001) soil = GridProperty(TESTFILE7, name="SOIL", fformat="unrst", date=19991201, grid=gg) tsetup.assert_almostequal(soil.values.mean(), 1.0 - 0.8780, 0.001)
def test_import_should_fail(): """Import INIT and UNRST Reek but ask for wrong name or date""" g = Grid() g.from_file(GFILE1, fformat="egrid") x = GridProperties() names = ['PORO', 'NOSUCHNAME'] with pytest.raises(ValueError) as e_info: logger.warning(e_info) x.from_file(IFILE1, fformat="init", names=names, grid=g) rx = GridProperties() names = ['PRESSURE'] dates = [19991201, 19991212] # last date does not exist rx.from_file(RFILE1, fformat='unrst', names=names, dates=dates, grid=g)
def test_inactivate_thin_cells(): """Make hybridgrid for Emerald case in region, and inactive thin cells""" logger.info('Read grid...') grd = Grid(EMEGFILE) logger.info('Read grid... done, NLAY is {}'.format(grd.nlay)) reg = GridProperty() reg.from_file(EMERFILE, name='REGION') nhdiv = 40 grd.convert_to_hybrid(nhdiv=nhdiv, toplevel=1650, bottomlevel=1690, region=reg, region_number=1) grd.inactivate_by_dz(0.001) grd.to_file('TMP/test_hybridgrid2_inact_thin.roff')
def test_import_init(): """Import INIT Reek""" g = Grid() g.from_file(GFILE1, fformat="egrid") x = GridProperties() names = ["PORO", "PORV"] x.from_file(IFILE1, fformat="init", names=names, grid=g) # get the object poro = x.get_prop_by_name("PORO") logger.info("PORO avg {}".format(poro.values.mean())) porv = x.get_prop_by_name("PORV") logger.info("PORV avg {}".format(porv.values.mean())) assert poro.values.mean() == pytest.approx(0.1677402, abs=0.00001)
def test_report_zlog_mismatch_perflog(): """Report zone log mismatch grid and well filter on PERF""" g1 = Grid() g1.from_file(GRIDFILE) zo = GridProperty() zo.from_file(ZONEFILE, name="Zone") w1 = Well(PWELL1) w1.dataframe.to_csv("TMP/testw1.csv") res = g1.report_zone_mismatch( well=w1, zonelogname="Zonelog", zoneprop=zo, zonelogrange=(1, 3), depthrange=[1580, 9999], perflogname="PERF", resultformat=2, ) mywell = res["WELLINTV"] logger.info("\n%s", mywell.dataframe.to_string()) mywell.to_file(join(TMPD, "w1_perf_report.rmswell")) assert res["MATCH2"] == pytest.approx(81, 1.5) assert res["TCOUNT2"] == 57 assert res["MCOUNT2"] == 46 w1 = Well(WELL1) # well is missing perflog; hence result shall be None res = g1.report_zone_mismatch( well=w1, zonelogname="Zonelog", zoneprop=zo, zonelogrange=(1, 3), depthrange=[1580, 9999], perflogname="PERF", resultformat=2, ) # ask for perflogname but no such present assert res is None
def test_report_zlog_mismatch(): """Report zone log mismatch grid and well.""" g1 = Grid() g1.from_file(GRIDFILE) zo = GridProperty() zo.from_file(ZONEFILE, name="Zone") w1 = Well(WELL1) w2 = Well(WELL2) w3 = Well(WELL3) w4 = Well(WELL4) w5 = Well(WELL5) w6 = Well(WELL6) w7 = Well(WELL7) wells = [w1, w2, w3, w4, w5, w6, w7] for wll in wells: response = g1.report_zone_mismatch( well=wll, zonelogname="Zonelog", zoneprop=zo, zonelogrange=(1, 3), depthrange=[1300, 9999], ) match = int(float("{0:.4f}".format(response[0]))) logger.info("Match for %s is %s", wll.wellname, match) assert match == MATCHD1[wll.name] # check also with resultformat=2 res = g1.report_zone_mismatch( well=wll, zonelogname="Zonelog", zoneprop=zo, zonelogrange=(1, 3), depthrange=[1300, 9999], resultformat=2, ) match = int(float("{0:.4f}".format(res["MATCH2"]))) logger.info("Match for %s is %s", wll.wellname, match) assert match == MATCHD2[wll.name]
def test_io_ecl_dates(): """Import Eclipse with some more flexible dates settings""" logger.info("Name is {}".format(__name__)) po = GridProperty() px = GridProperty() mygrid = Grid(TESTFILE5) po.from_file(TESTFILE7, fformat="unrst", name="PRESSURE", grid=mygrid, date="first") assert po.date == 19991201 px.from_file(TESTFILE7, fformat="unrst", name="PRESSURE", grid=mygrid, date="last") assert px.date == 20030101
def test_create_from_gridproperty(): """Create a simple property from grid""" gg = Grid(TESTFILE5, fformat="egrid") poro = GridProperty(gg, name="poro", values=0.33) assert poro.ncol == gg.ncol # create from gridproperty faci = xtgeo.GridProperty(poro, name="FAC", values=1, discrete=True) assert faci.nlay == gg.nlay assert faci.values.mean() == 1 assert faci.values.dtype.kind == "i" some = xtgeo.GridProperty(faci, name="SOME", values=22) assert some.values.mean() == 22.0 assert some.isdiscrete is False some.values = np.where(some.values == 0, 0, 1) assert some.isdiscrete is False
def test_slice_simple(): """Trigger XSection class, and do some simple things basically.""" layslice = Grid3DSlice() mygrid = Grid(USEFILE1) myprop = GridProperty(USEFILE2, grid=mygrid, name="PORO") assert myprop.values.mean() == pytest.approx(0.1677, abs=0.001) layslice.canvas(title="My Grid plot") wnd = (454000, 455000, 6782000, 6783000) layslice.plot_gridslice(mygrid, myprop, window=wnd, colormap=USEFILE3) if XTGSHOW: layslice.show() else: print("Output to screen disabled (will plotto screen); " "use XTG_SHOW env variable") layslice.savefig(os.path.join(TMPDIR, "layerslice.png"))
def test_io_ecl_dates(): """Import Eclipse with some more flexible dates settings""" logger.info('Name is {}'.format(__name__)) po = GridProperty() px = GridProperty() mygrid = Grid(testfile5) po.from_file(testfile7, fformat="unrst", name='PRESSURE', grid=mygrid, date='first') assert po.date == 19991201 px.from_file(testfile7, fformat="unrst", name='PRESSURE', grid=mygrid, date='last') assert px.date == 20030101
def test_grid_layer_slice(): """Test grid slice coordinates.""" grd = Grid() grd.from_file(REEKFILE) sarr1, _ibarr = grd.get_layer_slice(1) sarrn, _ibarr = grd.get_layer_slice(grd.nlay, top=False) cell1 = grd.get_xyz_cell_corners(ijk=(1, 1, 1)) celln = grd.get_xyz_cell_corners(ijk=(1, 1, grd.nlay)) celll = grd.get_xyz_cell_corners(ijk=(grd.ncol, grd.nrow, grd.nlay)) assert sarr1[0, 0, 0] == cell1[0] assert sarr1[0, 0, 1] == cell1[1] assert sarrn[0, 0, 0] == celln[12] assert sarrn[0, 0, 1] == celln[13] assert sarrn[-1, 0, 0] == celll[12] assert sarrn[-1, 0, 1] == celll[13]
def test_eclunrst_import_soil_reek(): """Property UNRST import from Eclipse, computing SOIL. Reek""" gg = Grid(testfile5, fformat='egrid') logger.info("Import RESTART (UNIFIED) ...") swat = GridProperty(testfile7, name='SWAT', fformat='unrst', date=19991201, grid=gg) tsetup.assert_almostequal(swat.values.mean(), 0.8780, 0.001) sgas = GridProperty(testfile7, name='SGAS', fformat='unrst', date=19991201, grid=gg) tsetup.assert_almostequal(sgas.values.mean(), 0.000, 0.001) soil = GridProperty(testfile7, name='SOIL', fformat='unrst', date=19991201, grid=gg) tsetup.assert_almostequal(soil.values.mean(), 1.0 - 0.8780, 0.001)
def test_get_all_corners(): """Get X Y Z for all corners as XTGeo GridProperty objects""" grid = Grid(TESTFILE8A) allc = grid.get_xyz_corners() x0 = allc[0] y0 = allc[1] z0 = allc[2] x1 = allc[3] y1 = allc[4] z1 = allc[5] # top of cell layer 2 in cell 5 5 (if 1 index start as RMS) assert x0.values3d[4, 4, 1] == pytest.approx(457387.718, abs=0.5) assert y0.values3d[4, 4, 1] == pytest.approx(5935461.29790, abs=0.5) assert z0.values3d[4, 4, 1] == pytest.approx(1728.9429, abs=0.1) assert x1.values3d[4, 4, 1] == pytest.approx(457526.55367, abs=0.5) assert y1.values3d[4, 4, 1] == pytest.approx(5935542.02467, abs=0.5) assert z1.values3d[4, 4, 1] == pytest.approx(1728.57898, abs=0.1)
def test_import_soil(): """SOIL need to be computed in code from SWAT and SGAS""" g = Grid() g.from_file(GFILE1, fformat="egrid") x = GridProperties() names = ["SOIL", "SWAT", "PRESSURE"] dates = [19991201] x.from_file(RFILE1, fformat="unrst", names=names, dates=dates, grid=g) logger.info(x.names) # get the object instance soil = x.get_prop_by_name("SOIL_19991201") logger.info(soil.values3d.mean()) logger.debug(x.names) txt = "Average SOIL_19850101" assert soil.values.mean() == pytest.approx(0.121977, abs=0.001), txt
def test_import_restart_gull(): """Import Restart Reek""" g = Grid() g.from_file(GFILE1, fformat="egrid") x = GridProperties() names = ["PRESSURE", "SWAT"] dates = [19991201] x.from_file(RFILE1, fformat="unrst", names=names, dates=dates, grid=g) # get the object pr = x.get_prop_by_name("PRESSURE_19991201") swat = x.get_prop_by_name("SWAT_19991201") logger.info(x.names) logger.info(swat.values3d.mean()) logger.info(pr.values3d.mean())