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_avg02(): """Make average map from Reek Eclipse.""" grd = Grid() grd.from_file(GFILE2, fformat="egrid") # get the poro po = GridProperty() po.from_file(IFILE2, fformat="init", name="PORO", grid=grd) # get the dz and the coordinates dz = grd.get_dz(mask=False) xc, yc, _zc = grd.get_xyz(mask=False) # get actnum actnum = grd.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_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_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_import_grdecl_and_bgrdecl(): """Eclipse import of GRDECL and binary GRDECL""" grd1 = Grid(REEKFIL2, fformat="grdecl") grd1.describe() assert grd1.dimensions == (40, 64, 14) assert grd1.nactive == 35812 # get dZ... dzv1 = grd1.get_dz() grd2 = Grid(REEKFIL3, fformat="bgrdecl") grd2.describe() assert grd2.dimensions == (40, 64, 14) assert grd2.nactive == 35812 # get dZ... dzv2 = grd2.get_dz() tsetup.assert_almostequal(dzv1.values.mean(), dzv2.values.mean(), 0.001)
def test_npvalues1d(): """Different ways of getting np arrays""" grd = Grid(DUALFIL3) dz = grd.get_dz() dz1 = dz.get_npvalues1d(activeonly=False) # [ 1. 1. 1. 1. 1. nan ...] dz2 = dz.get_npvalues1d(activeonly=True) # [ 1. 1. 1. 1. 1. 1. ...] assert dz1[0] == 1.0 assert np.isnan(dz1[5]) assert dz1[0] == 1.0 assert not np.isnan(dz2[5]) grd = Grid(DUALFIL1) # all cells active dz = grd.get_dz() dz1 = dz.get_npvalues1d(activeonly=False) dz2 = dz.get_npvalues1d(activeonly=True) assert dz1.all() == dz2.all()
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"))
def test_avg03(): """Make average map from Reek Eclipse, speed up by zone_avg.""" 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() actnum = actnum.get_npvalues3d() # convert from masked numpy to ordinary xcuse = xc.get_npvalues3d() ycuse = yc.get_npvalues3d() dzuse = dz.get_npvalues3d(fill_value=0.0) pouse = po.get_npvalues3d(fill_value=0.0) # dz must be zero for undef cells dzuse[actnum < 0.5] = 0.0 pouse[actnum < 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, zone_avg=True) # add the faults in plot fau = Polygons(ffile1, fformat='zmap') fspec = {'faults': fau} avgmap.quickplot(filename='TMP/tmp_poro3.png', xlabelrotation=30, faults=fspec) avgmap.to_file('TMP/tmp.poro3.gri', fformat='irap_ascii') logger.info(avgmap.values.mean()) assert avgmap.values.mean() == pytest.approx(0.1653, abs=0.01)
def test_hcpvfz1(): """HCPV thickness map.""" # It is important that input are pure numpies, not masked logger.info("Name is %s", __name__) grd = Grid() logger.info("Import roff...") grd.from_file(ROFF1_GRID, fformat="roff") # get the hcpv st = GridProperty() to = GridProperty() st.from_file(ROFF1_PROPS, name="Oil_HCPV") to.from_file(ROFF1_PROPS, name="Oil_bulk") # get the dz and the coordinates, with no mask (ie get value for outside) dz = grd.get_dz(mask=False) xc, yc, _zc = grd.get_xyz(mask=False) xcv = ma.filled(xc.values3d) ycv = ma.filled(yc.values3d) dzv = ma.filled(dz.values3d) hcpfz = ma.filled(st.values3d, fill_value=0.0) tov = ma.filled(to.values3d, fill_value=10) tov[tov < 1.0e-32] = 1.0e-32 hcpfz = hcpfz * dzv / tov # make a map... estimate from xc and yc xmin = xcv.min() xmax = xcv.max() ymin = ycv.min() ymax = ycv.max() xinc = (xmax - xmin) / 50 yinc = (ymax - ymin) / 50 logger.debug( "xmin xmax ymin ymax, xinc, yinc: %s %s %s %s %s %s", xmin, xmax, ymin, ymax, xinc, yinc, ) hcmap = RegularSurface( nx=50, ny=50, xinc=xinc, yinc=yinc, xori=xmin, yori=ymin, values=np.zeros((50, 50)), ) hcmap2 = RegularSurface( nx=50, ny=50, xinc=xinc, yinc=yinc, xori=xmin, yori=ymin, values=np.zeros((50, 50)), ) zp = np.ones((grd.ncol, grd.nrow, grd.nlay)) # now make hcpf map t1 = xtg.timer() hcmap.hc_thickness_from_3dprops( xprop=xcv, yprop=ycv, dzprop=dzv, hcpfzprop=hcpfz, zoneprop=zp, zone_minmax=(1, 1), ) assert hcmap.values.mean() == pytest.approx(1.447, abs=0.1) t2 = xtg.timer(t1) logger.info("Speed basic is %s", t2) t1 = xtg.timer() hcmap2.hc_thickness_from_3dprops( xprop=xcv, yprop=ycv, dzprop=dzv, hcpfzprop=hcpfz, zoneprop=zp, coarsen=2, zone_avg=True, zone_minmax=(1, 1), mask_outside=True, ) t2 = xtg.timer(t1) logger.info("Speed zoneavg coarsen 2 is %s", t2) hcmap.quickplot(filename="TMP/quickplot_hcpv.png") hcmap2.quickplot(filename="TMP/quickplot_hcpv_zavg_coarsen.png") logger.debug(hcmap.values.mean())