def test_activate_all_cells(tmp_path): """Make the grid active for all cells.""" grid = Grid(EMEGFILE) logger.info("Number of active cells %s before", grid.nactive) grid.activate_all() logger.info("Number of active cells %s after", grid.nactive) assert grid.nactive == grid.ntotal grid.to_file(tmp_path / "emerald_all_active.roff")
def test_copy_grid(): """Copy a grid.""" grd = Grid(EMEGFILE2) grd2 = grd.copy() grd.to_file(join("TMP", "gcp1.roff")) grd2.to_file(join("TMP", "gcp2.roff")) assert cmp(join("TMP", "gcp1.roff"), join("TMP", "gcp2.roff")) is True
def test_copy_grid(): """Crop a grid.""" grd = Grid(EMEGFILE2) grd2 = grd.copy() grd.to_file(join('TMP', 'gcp1.roff')) grd2.to_file(join('TMP', 'gcp2.roff')) assert cmp(join('TMP', 'gcp1.roff'), join('TMP', 'gcp2.roff')) is True
def test_reverse_row_axis_dual(tmpdir): """Reverse axis for distorted but small grid""" grd = Grid(DUAL) assert grd.ijk_handedness == "left" grd.to_file(join(tmpdir, "dual_left.grdecl"), fformat="grdecl") cellcorners1 = grd.get_xyz_cell_corners((5, 1, 1)) grd.reverse_row_axis() assert grd.ijk_handedness == "right" grd.to_file(join(tmpdir, "dual_right.grdecl"), fformat="grdecl") cellcorners2 = grd.get_xyz_cell_corners((5, 3, 1)) assert cellcorners1[7] == cellcorners2[1]
def test_pathlib(tmp_path): """Import and export via pathlib.""" pfile = pathlib.Path(DUALFIL1) grd = Grid() grd.from_file(pfile) assert grd.dimensions == (5, 3, 1) out = tmp_path / "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_copy_grid(tmpdir): """Copy a grid.""" grd = Grid(EMEGFILE2) grd2 = grd.copy() grd.to_file(join(tmpdir, "gcp1.roff")) grd2.to_file(join(tmpdir, "gcp2.roff")) xx1 = Grid(join(tmpdir, "gcp1.roff")) xx2 = Grid(join(tmpdir, "gcp2.roff")) assert xx1._zcornsv.mean() == xx2._zcornsv.mean() assert xx1._actnumsv.mean() == xx2._actnumsv.mean()
def test_reverse_row_axis_eme(tmpdir): """Reverse axis for emerald grid""" grd1 = Grid(EMEGFILE) assert grd1.ijk_handedness == "left" grd1.to_file(join(tmpdir, "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(tmpdir, "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_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(): """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_report_zlog_mismatch(): """Report zone log mismatch grid and well.""" logger.info("Name is {}".format(__name__)) g1 = Grid() g1.from_file(GRIDFILE) g2 = Grid() g2.from_file(GRIDFILE) g2.reduce_to_one_layer() g2.to_file(os.path.join(TDMP, "test.roff"), fformat="roff") z = GridProperty() z.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] resultd = {} # matchd = {'WI_1': 69, 'WI_3': 70, 'OP_4': 74, 'OP_5': 75, 'OP_1': 75, # 'OP_2': 74, 'OP_3': 70} for w in wells: response = g1.report_zone_mismatch( well=w, zonelogname="Zonelog", zoneprop=z, onelayergrid=g2, zonelogrange=(1, 3), option=0, depthrange=[1300, 9999], ) if response is None: continue else: logger.info(response) match = int(float("{0:.4f}".format(response[0]))) logger.info(match) resultd[w.wellname] = match
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_report_zlog_mismatch(): """Report zone log mismatch grid and well.""" logger.info('Name is {}'.format(__name__)) g1 = Grid() g1.from_file(gridfile) g2 = Grid() g2.from_file(gridfile) g2.reduce_to_one_layer() g2.to_file('/tmp/test.roff', fformat='roff') z = GridProperty() z.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] resultd = {} # matchd = {'WI_1': 69, 'WI_3': 70, 'OP_4': 74, 'OP_5': 75, 'OP_1': 75, # 'OP_2': 74, 'OP_3': 70} for w in wells: response = g1.report_zone_mismatch(well=w, zonelogname='Zonelog', zoneprop=z, onelayergrid=g2, zonelogrange=(1, 3), option=0, depthrange=[1300, 9999]) if response is None: continue else: logger.info(response) match = int(float("{0:.4f}".format(response[0]))) logger.info(match) resultd[w.wellname] = match
def test_hybridgrid1(tmpdir): """Making a hybridgrid for Emerald case""" logger.info("Read grid...") grd = Grid(EMEGFILE) assert grd.subgrids is not None # initially, prior to subgrids logger.info("Read grid... done, NZ is %s", grd.nlay) grd.to_file(join(tmpdir, "test_hybridgrid1_asis.bgrdecl"), fformat="bgrdecl") logger.info("Convert...") nhdiv = 40 newnlay = grd.nlay * 2 + nhdiv grd.convert_to_hybrid(nhdiv=nhdiv, toplevel=1700, bottomlevel=1740) logger.info("Hybrid grid... done, NLAY is now %s", grd.nlay) assert grd.nlay == newnlay, "New NLAY number" assert grd.subgrids is None dzv = grd.get_dz() assert dzv.values3d.mean() == pytest.approx(1.395, abs=0.01) logger.info("Export...") grd.to_file(join(tmpdir, "test_hybridgrid1.roff")) logger.info("Read grid 2...") grd2 = Grid(join(tmpdir, "test_hybridgrid1_asis.bgrdecl")) logger.info("Read grid... done, NLAY is %s", grd2.nlay) logger.info("Convert...") nhdiv = 40 newnz = grd2.nlay * 2 + nhdiv grd2.convert_to_hybrid(nhdiv=nhdiv, toplevel=1700, bottomlevel=1740) logger.info("Hybrid grid... done, NZ is now %s", grd2.nlay) assert grd2.nlay == newnz, "New NLAY number" dzv = grd2.get_dz() assert dzv.values3d.mean() == pytest.approx(1.395, abs=0.01)
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_crop_grid(): """Crop a grid.""" logger.info("Read grid...") grd = Grid(EMEGFILE2) zprop = GridProperty(EMEZFILE2, name="Zone", grid=grd) logger.info("Read grid... done, NLAY is {}".format(grd.nlay)) logger.info("Read grid...NCOL, NROW, NLAY is {} {} {}".format( grd.ncol, grd.nrow, grd.nlay)) grd.crop((30, 60), (20, 40), (1, 46), props=[zprop]) grd.to_file(join("TMP", "grid_cropped.roff")) grd2 = Grid(join("TMP", "grid_cropped.roff")) assert grd2.ncol == 31
def test_hybridgrid1(): """Making a hybridgrid for Emerald case (ROFF and GRDECL""" logger.info("Read grid...") grd = Grid(EMEGFILE) logger.info("Read grid... done, NZ is %s", grd.nlay) grd.to_file(join(TDP, "test_hybridgrid1_asis.grdecl"), fformat="grdecl") logger.info("Convert...") nhdiv = 40 newnlay = grd.nlay * 2 + nhdiv grd.convert_to_hybrid(nhdiv=nhdiv, toplevel=1700, bottomlevel=1740) logger.info("Hybrid grid... done, NLAY is now %s", grd.nlay) assert grd.nlay == newnlay, "New NLAY number" dzv = grd.get_dz() assert dzv.values3d.mean() == pytest.approx(1.395, abs=0.01) logger.info("Export...") grd.to_file("TMP/test_hybridgrid1.roff") logger.info("Read grid 2...") grd2 = Grid("TMP/test_hybridgrid1_asis.grdecl") logger.info("Read grid... done, NLAY is %s", grd2.nlay) logger.info("Convert...") nhdiv = 40 newnz = grd2.nlay * 2 + nhdiv grd2.convert_to_hybrid(nhdiv=nhdiv, toplevel=1700, bottomlevel=1740) logger.info("Hybrid grid... done, NZ is now %s", grd2.nlay) assert grd2.nlay == newnz, "New NLAY number" dzv = grd2.get_dz() assert dzv.values3d.mean() == pytest.approx(1.395, abs=0.01)
def test_eclgrid_import2(): """Eclipse EGRID import, also change ACTNUM.""" grd = Grid() logger.info("Import Eclipse GRID...") grd.from_file(REEKFILE, fformat="egrid") tsetup.assert_equal(grd.ncol, 40, txt="EGrid NX from Eclipse") tsetup.assert_equal(grd.nrow, 64, txt="EGrid NY from Eclipse") tsetup.assert_equal(grd.nactive, 35838, txt="EGrid NTOTAL from Eclipse") tsetup.assert_equal(grd.ntotal, 35840, txt="EGrid NACTIVE from Eclipse") actnum = grd.get_actnum() print(actnum.values[12:13, 22:24, 5:6]) tsetup.assert_equal(actnum.values[12, 22, 5], 0, txt="ACTNUM 0") actnum.values[:, :, :] = 1 actnum.values[:, :, 4:6] = 0 grd.set_actnum(actnum) newactive = grd.ncol * grd.nrow * grd.nlay - 2 * (grd.ncol * grd.nrow) tsetup.assert_equal(grd.nactive, newactive, txt="Changed ACTNUM") grd.to_file(join(TMPDIR, "reek_new_actnum.roff"))
def test_roffbin_export_v2_banal6(): """Test roff binary export v2 for banal no. 6 case""" # export grd1 = Grid() grd1._xtgformat = 2 grd1.from_file(BANAL6) logger.info("EXPORT") grd1.to_file(join(TMPDIR, "b6_export.roffasc"), fformat="roff_asc") grd1.to_file(join(TMPDIR, "b6_export.roffbin"), fformat="roff_bin") grd2 = Grid(join(TMPDIR, "b6_export.roffbin")) cell1 = grd1.get_xyz_cell_corners((2, 2, 2)) cell2 = grd2.get_xyz_cell_corners((2, 2, 2)) assert cell1 == cell2 reek = Grid() reek._xtgformat = 2 reek.from_file(REEKFIL4) reek.to_file("TMP/reek_xtgformat2", fformat="roff_ascii")
def test_to_from_xtggrid_write(tmp_path, 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 xtggrid.to_file(tmp_path / "xtggrid.grdecl", fformat="grdecl") grdecl_grid2 = ggrid.GrdeclGrid.from_file(tmp_path / "xtggrid.grdecl") assert grdecl_grid.zcorn == pytest.approx(grdecl_grid2.zcorn, abs=0.02) assert grdecl_grid.xtgeo_coord() == pytest.approx( grdecl_grid2.xtgeo_coord(), abs=0.02) if grdecl_grid.actnum is None: assert grdecl_grid2.actnum is None or np.all(grdecl_grid2.actnum) else: assert grdecl_grid.actnum.tolist() == grdecl_grid2.actnum.tolist()
def test_eclgrid_import3(tmp_path): """Eclipse GRDECL import and translate.""" grd = Grid(BRILGRDECL, fformat="grdecl") mylist = grd.get_geometrics() xori1 = mylist[0] # translate the coordinates grd.translate_coordinates(translate=(100, 100, 10), flip=(1, 1, 1)) mylist = grd.get_geometrics() xori2 = mylist[0] # check if origin is translated 100m in X tsetup.assert_equal(xori1 + 100, xori2, txt="Translate X distance") grd.to_file(tmp_path / "g1_translate.roff", fformat="roff_binary") grd.to_file(tmp_path / "g1_translate.bgrdecl", fformat="bgrdecl")
def test_simple_io(): """Test various import and export formats, incl egrid and bgrdecl""" gg = Grid(REEKFILE, fformat="egrid") assert gg.ncol == 40 filex = os.path.join(TMPDIR, "grid_test_simple_io.roff") gg.to_file(filex) gg2 = Grid(filex, fformat="roff") assert gg2.ncol == 40 filex = os.path.join(TMPDIR, "grid_test_simple_io.EGRID") filey = os.path.join(TMPDIR, "grid_test_simple_io.bgrdecl") gg.to_file(filex, fformat="egrid") gg.to_file(filey, fformat="bgrdecl") gg2 = Grid(filex, fformat="egrid") gg3 = Grid(filey, fformat="bgrdecl") assert gg2.ncol == 40 dz1 = gg.get_dz() dz2 = gg2.get_dz() dz3 = gg3.get_dz() tsetup.assert_almostequal(dz1.values.mean(), dz2.values.mean(), 0.001) tsetup.assert_almostequal(dz1.values.std(), dz2.values.std(), 0.001) tsetup.assert_almostequal(dz1.values.mean(), dz3.values.mean(), 0.001) tsetup.assert_almostequal(dz1.values.std(), dz3.values.std(), 0.001)
def test_roffbin_bigbox(tmpdir): """Test roff binary for bigbox, to monitor performance""" bigbox = os.path.join(tmpdir, "bigbox.roff") if not os.path.exists(bigbox): logger.info("Create tmp big roff grid file...") grd0 = Grid() grd0.create_box(dimension=(500, 500, 100)) grd0.to_file(bigbox) grd1 = Grid() t0 = xtg.timer() grd1._xtgformat = 1 grd1.from_file(bigbox) t_old = xtg.timer(t0) logger.info("Reading bigbox xtgeformat=1 took %s seconds", t_old) cell1 = grd1.get_xyz_cell_corners((13, 14, 15)) grd2 = Grid() t0 = xtg.timer() t1 = xtg.timer() grd2._xtgformat = 2 grd2.from_file(bigbox) t_new = xtg.timer(t0) logger.info("Reading bigbox xtgformat=2 took %s seconds", t_new) cell2a = grd2.get_xyz_cell_corners((13, 14, 15)) t0 = xtg.timer() grd2._convert_xtgformat2to1() cell2b = grd2.get_xyz_cell_corners((13, 14, 15)) logger.info("Conversion to xtgformat1 took %s seconds", xtg.timer(t0)) t_newtot = xtg.timer(t1) logger.info("Total run time xtgformat=2 + conv took %s seconds", t_newtot) logger.info("Speed gain new vs old: %s", t_old / t_new) logger.info("Speed gain new incl conv vs old: %s", t_old / t_newtot) assert cell1 == cell2a assert cell1 == cell2b
def test_refine_vertically(tmpdir): """Do a grid refinement vertically.""" logger.info("Read grid...") grd = Grid(EMEGFILE) logger.info("Read grid... done, NLAY is {}".format(grd.nlay)) logger.info("Subgrids before: %s", grd.get_subgrids()) avg_dz1 = grd.get_dz().values3d.mean() # idea; either a scalar (all cells), or a dictionary for zone wise grd.refine_vertically(3) avg_dz2 = grd.get_dz().values3d.mean() assert avg_dz1 == pytest.approx(3 * avg_dz2, abs=0.0001) logger.info("Subgrids after: %s", grd.get_subgrids()) grd.inactivate_by_dz(0.001) grd.to_file(join(tmpdir, "test_refined_by_3.roff"))