def test_scalrecommendation(): """Testing making SCAL rec from dict of dict.""" pyscal_factory = PyscalFactory() scal_input = { "low": {"nw": 2, "now": 4, "ng": 1, "nog": 2}, "BASE": {"nw": 3, "NOW": 3, "ng": 1, "nog": 2}, "high": {"nw": 4, "now": 2, "ng": 1, "nog": 3}, } scal = pyscal_factory.create_scal_recommendation(scal_input) # (not supported yet to make WaterOil only..) interp = scal.interpolate(-0.5) sat_table_str_ok(interp.SWOF()) sat_table_str_ok(interp.SGOF()) sat_table_str_ok(interp.SLGOF()) sat_table_str_ok(interp.SOF3()) check_table(interp.wateroil.table) check_table(interp.gasoil.table) incomplete1 = scal_input.copy() del incomplete1["BASE"] with pytest.raises(ValueError): pyscal_factory.create_scal_recommendation(incomplete1) go_only = scal_input.copy() del go_only["low"]["now"] del go_only["low"]["nw"] gasoil = pyscal_factory.create_scal_recommendation(go_only) assert gasoil.low.wateroil is None assert gasoil.base.wateroil is not None assert gasoil.high.wateroil is not None # SCALrecommendation of gasoil only works as long as you # don't try to ask for water data: assert "SGFN" in gasoil.interpolate(-0.4).SGFN() assert "SWOF" not in gasoil.interpolate(-0.2).SWOF()
def test_interpolation(param_wo, param_go): """Test interpolation with random interpolation parameters, looking for numerical corner cases""" rec = PyscalFactory.create_scal_recommendation( {"low": LOW_SAMPLE_LET, "base": BASE_SAMPLE_LET, "high": HIGH_SAMPLE_LET}, "foo", h=0.1, ) rec.add_simple_J() # Add default pc curve # Check that added pc curve is non-zero assert sum(rec.low.wateroil.table["pc"]) assert sum(rec.base.wateroil.table["pc"]) assert sum(rec.high.wateroil.table["pc"]) try: interpolant = rec.interpolate(param_wo, param_go, h=0.1) except AssertionError: return check_table(interpolant.wateroil.table) check_table(interpolant.gasoil.table) assert len(interpolant.gasoil.SGOF()) > 100 assert len(interpolant.gasoil.SGFN()) > 100 assert len(interpolant.wateroil.SWFN()) > 100 assert len(interpolant.SOF3()) > 100 assert len(interpolant.wateroil.SWOF()) > 100 assert interpolant.threephaseconsistency() assert sum(interpolant.wateroil.table["pc"])
def test_boundary_cases(): """Test that interpolation is able to return the boundaries at +/- 1""" rec = PyscalFactory.create_scal_recommendation( { "low": LOW_SAMPLE_LET, "base": BASE_SAMPLE_LET, "high": HIGH_SAMPLE_LET }, "foo", h=0.1, ) assert rec.type == WaterOilGas wo_cols = ["SW", "KRW", "KROW"] # no Pc in this test data go_cols = ["SG", "KRG", "KROG"] assert (rec.interpolate(0).wateroil.table[wo_cols].equals( rec.base.wateroil.table[wo_cols])) assert (rec.interpolate(-1).wateroil.table[wo_cols].equals( rec.low.wateroil.table[wo_cols])) assert (rec.interpolate(1).wateroil.table[wo_cols].equals( rec.high.wateroil.table[wo_cols])) assert (rec.interpolate(0).gasoil.table[go_cols].equals( rec.base.gasoil.table[go_cols])) assert (rec.interpolate(-1).gasoil.table[go_cols].equals( rec.low.gasoil.table[go_cols])) assert (rec.interpolate(1).gasoil.table[go_cols].equals( rec.high.gasoil.table[go_cols])) assert (rec.interpolate(0, 1).wateroil.table[wo_cols].equals( rec.base.wateroil.table[wo_cols])) assert (rec.interpolate(-1, 1).wateroil.table[wo_cols].equals( rec.low.wateroil.table[wo_cols])) assert (rec.interpolate(1, 1).wateroil.table[wo_cols].equals( rec.high.wateroil.table[wo_cols])) assert (rec.interpolate(0, 1).gasoil.table[go_cols].equals( rec.high.gasoil.table[go_cols])) assert (rec.interpolate(-1, 1).gasoil.table[go_cols].equals( rec.high.gasoil.table[go_cols])) assert (rec.interpolate(1, 1).gasoil.table[go_cols].equals( rec.high.gasoil.table[go_cols])) assert (rec.interpolate(0, 0).gasoil.table[go_cols].equals( rec.base.gasoil.table[go_cols])) assert (rec.interpolate(-1, 0).gasoil.table[go_cols].equals( rec.base.gasoil.table[go_cols])) assert (rec.interpolate(1, 0).gasoil.table[go_cols].equals( rec.base.gasoil.table[go_cols])) assert (rec.interpolate(0, -1).gasoil.table[go_cols].equals( rec.low.gasoil.table[go_cols])) assert (rec.interpolate(-1, -1).gasoil.table[go_cols].equals( rec.low.gasoil.table[go_cols])) assert (rec.interpolate(1, -1).gasoil.table[go_cols].equals( rec.low.gasoil.table[go_cols]))
def test_xls_scalrecommendation(): """Test making SCAL recommendations from xls data""" testdir = Path(__file__).absolute().parent xlsxfile = testdir / "data/scal-pc-input-example.xlsx" scalinput = pd.read_excel(xlsxfile, engine="openpyxl").set_index(["SATNUM", "CASE"]) for satnum in scalinput.index.levels[0].values: dictofdict = scalinput.loc[satnum, :].to_dict(orient="index") scalrec = PyscalFactory.create_scal_recommendation(dictofdict) scalrec.interpolate(+0.5)
def test_scalrecommendation(): """Testing making SCAL rec from dict of dict""" factory = PyscalFactory() scal_input = { "low": { "nw": 2, "now": 4, "ng": 1, "nog": 2 }, "BASE": { "nw": 3, "NOW": 3, "ng": 1, "nog": 2 }, "high": { "nw": 4, "now": 2, "ng": 1, "nog": 3 }, } scal = factory.create_scal_recommendation(scal_input) # (not supported yet to make WaterOil only..) scal.interpolate(-0.5).SWOF() incomplete1 = scal_input.copy() del incomplete1["BASE"] with pytest.raises(ValueError): factory.create_scal_recommendation(incomplete1) incomplete2 = scal_input.copy() del incomplete2["low"]["now"] with pytest.raises(ValueError): factory.create_scal_recommendation(incomplete2)
def test_scalrecommendation_gaswater(): """Testing making SCAL rec from dict of dict for gaswater input""" pyscal_factory = PyscalFactory() scal_input = { "low": {"nw": 2, "ng": 1}, "BASE": {"nw": 3, "ng": 1}, "high": {"nw": 4, "ng": 1}, } scal = pyscal_factory.create_scal_recommendation(scal_input, h=0.2) interp = scal.interpolate(-0.5, h=0.2) sat_table_str_ok(interp.SWFN()) sat_table_str_ok(interp.SGFN()) check_table(interp.wateroil.table) check_table(interp.gasoil.table)
def interpolatetest(): """Test interpolation (sample test) in a scal recommentation""" rec = PyscalFactory.create_scal_recommendation( {"low": LOW_SAMPLE_LET, "base": BASE_SAMPLE_LET, "high": HIGH_SAMPLE_LET}, "foo", h=0.001, ) rec.add_simple_J() # Add default pc curve # print rec.low.wateroil.table interpolant = rec.interpolate(0.3, parameter2=-0.9, h=0.05) print(interpolant.wateroil.SWOF()) print(interpolant.gasoil.SGOF()) print("Consistency check: ", end=" ") print(interpolant.threephaseconsistency())
def test_xls_scalrecommendation(): """Test making SCAL recommendations from xls data""" if "__file__" in globals(): # Easen up copying test code into interactive sessions testdir = os.path.dirname(os.path.abspath(__file__)) else: testdir = os.path.abspath(".") xlsxfile = testdir + "/data/scal-pc-input-example.xlsx" scalinput = pd.read_excel(xlsxfile).set_index(["SATNUM", "CASE"]) print(scalinput) for satnum in scalinput.index.levels[0].values: dictofdict = scalinput.loc[satnum, :].to_dict(orient="index") print(dictofdict) scalrec = PyscalFactory.create_scal_recommendation(dictofdict) print(scalrec.interpolate(-0.5).SWOF()) scalrec.interpolate(+0.5)
def test_fast_mode(): """Test that the fast-flag is passed on to constructed objects Each object's own test code tests the actual effects of the fast flag""" wateroil = PyscalFactory.create_water_oil({"nw": 2, "now": 2}) assert not wateroil.fast wateroil = PyscalFactory.create_water_oil({"nw": 2, "now": 2}, fast=True) assert wateroil.fast gasoil = PyscalFactory.create_gas_oil({"ng": 2, "nog": 2}) assert not gasoil.fast gasoil = PyscalFactory.create_gas_oil({"ng": 2, "nog": 2}, fast=True) assert gasoil.fast gaswater = PyscalFactory.create_gas_water({"nw": 2, "ng": 2}) assert not gaswater.gasoil.fast assert not gaswater.wateroil.fast gaswater = PyscalFactory.create_gas_water({"nw": 2, "ng": 2}, fast=True) assert gaswater.gasoil.fast assert gaswater.wateroil.fast assert gaswater.fast wateroilgas = PyscalFactory.create_water_oil_gas( {"nw": 2, "now": 2, "ng": 2, "nog": 2}, fast=True ) assert wateroilgas.fast assert wateroilgas.wateroil.fast assert wateroilgas.gasoil.fast scalrec = PyscalFactory.create_scal_recommendation( { "low": {"nw": 2, "now": 2, "ng": 2, "nog": 2}, "base": {"nw": 2, "now": 2, "ng": 2, "nog": 2}, "high": {"nw": 2, "now": 2, "ng": 2, "nog": 2}, }, fast=True, ) assert scalrec.low.fast assert scalrec.base.fast assert scalrec.high.fast interpolant = scalrec.interpolate(-0.5) assert interpolant.fast
def test_boundary_cases(): """Test that interpolation is able to return the boundaries at +/- 1""" rec = PyscalFactory.create_scal_recommendation( { "low": LOW_SAMPLE_LET, "base": BASE_SAMPLE_LET, "high": HIGH_SAMPLE_LET }, "foo", h=0.1, ) # Object reference equivalence is a little bit strict, # because it would be perfectly fine if interpolate() # retured copied objects. But we don't have an equivalence operator # implemented. assert rec.interpolate(0).wateroil == rec.base.wateroil assert rec.interpolate(-1).wateroil == rec.low.wateroil assert rec.interpolate(1).wateroil == rec.high.wateroil assert rec.interpolate(0).gasoil == rec.base.gasoil assert rec.interpolate(-1).gasoil == rec.low.gasoil assert rec.interpolate(1).gasoil == rec.high.gasoil assert rec.interpolate(0, 1).wateroil == rec.base.wateroil assert rec.interpolate(-1, 1).wateroil == rec.low.wateroil assert rec.interpolate(1, 1).wateroil == rec.high.wateroil assert rec.interpolate(0, 1).gasoil == rec.high.gasoil assert rec.interpolate(-1, 1).gasoil == rec.high.gasoil assert rec.interpolate(1, 1).gasoil == rec.high.gasoil assert rec.interpolate(0, 0).gasoil == rec.base.gasoil assert rec.interpolate(-1, 0).gasoil == rec.base.gasoil assert rec.interpolate(1, 0).gasoil == rec.base.gasoil assert rec.interpolate(0, -1).gasoil == rec.low.gasoil assert rec.interpolate(-1, -1).gasoil == rec.low.gasoil assert rec.interpolate(1, -1).gasoil == rec.low.gasoil
def test_SCAL_interpolation(): """Demonstration of interpolation between LET curves, 2x2 subplot""" matplotlib.style.use("ggplot") rec = PyscalFactory.create_scal_recommendation( { "low": LOW_SAMPLE_LET, "base": BASE_SAMPLE_LET, "high": HIGH_SAMPLE_LET }, "FOO", h=0.001, ) _, ((ax1, ax2), (ax3, ax4)) = pyplot.subplots(2, 2) # Choosing logarithmic spaced interpolation parameters # is not the same as interpolating in log(kr)-space # check the effect by setting # for t in -2 + np.logspace(1e-5,1e-1,15): # and # for t in -1 + np.logspace(1e-5,1e-1,15) # in the loops below. Curves get clustered to the bottom # in both linear and log(kr) spaces, but there # still might be some other distribution for the interpolants # that yields something that spans nicely both the linear and the # logarithmic kr space (?) for tparam in np.arange(-1, 0, 0.2): interp = rec.interpolate(tparam, h=0.001) interp.wateroil.plotkrwkrow(ax1, "r") interp.wateroil.plotkrwkrow(ax2, "r") for tparam in np.arange(0, 1, 0.2): interp = rec.interpolate(tparam, h=0.001) interp.wateroil.plotkrwkrow(ax1, "g") interp.wateroil.plotkrwkrow(ax2, "g") rec.low.wateroil.plotkrwkrow(ax1, linewidth=2, linestyle=":") rec.base.wateroil.plotkrwkrow(ax1, linewidth=2) rec.high.wateroil.plotkrwkrow(ax1, linewidth=2, linestyle="--") rec.low.wateroil.plotkrwkrow(ax2, linewidth=2, linestyle=":") rec.base.wateroil.plotkrwkrow(ax2, linewidth=2) rec.high.wateroil.plotkrwkrow(ax2, linewidth=2, linestyle="--") ax2.set_yscale("log") ax2.set_ylim([1e-10, 1]) ax1.set_xlabel("") ax2.set_xlabel("") ax1.set_title("Water-oil, low, base, high and interpolants", fontsize=10) ax2.set_title("Water-oil, low, base, high and interpolants", fontsize=10) for tparam in np.arange(-1, 0, 0.2): interp = rec.interpolate(tparam, h=0.001) interp.gasoil.plotkrgkrog(ax3, "r") interp.gasoil.plotkrgkrog(ax4, "r") for tparam in np.arange(0, 1, 0.2): interp = rec.interpolate(tparam, h=0.001) interp.gasoil.plotkrgkrog(ax3, "g") interp.gasoil.plotkrgkrog(ax4, "g") rec.low.gasoil.plotkrgkrog(ax3, linewidth=2, linestyle=":") rec.base.gasoil.plotkrgkrog(ax3, linewidth=2) rec.high.gasoil.plotkrgkrog(ax3, linewidth=2, linestyle="--") rec.low.gasoil.plotkrgkrog(ax4, linewidth=2, linestyle=":") rec.base.gasoil.plotkrgkrog(ax4, linewidth=2) rec.high.gasoil.plotkrgkrog(ax4, linewidth=2, linestyle="--") ax3.set_title("Gas-oil, low, base, high and interpolants", fontsize=10) ax4.set_title("Gas-oil, low, base, high and interpolants", fontsize=10) ax4.set_yscale("log") ax4.set_ylim([1e-05, 1]) ax3.set_xlabel("") ax4.set_xlabel("") pyplot.subplots_adjust(hspace=0.3) print("-- Check:") print("-- * Red curves are between dotted and solid blue line") print("-- * Green curves are between solid blue and dashed") print("[Close windows to continue tests]") pyplot.show()
def test_scalrecommendation(): """Testing making SCAL rec from dict of dict.""" pyscal_factory = PyscalFactory() scal_input = { "low": { "nw": 2, "now": 4, "ng": 1, "nog": 2 }, "BASE": { "nw": 3, "NOW": 3, "ng": 1, "nog": 2 }, "high": { "nw": 4, "now": 2, "ng": 1, "nog": 3 }, } scal = pyscal_factory.create_scal_recommendation(scal_input) with pytest.raises(ValueError, match="Input must be a dict"): pyscal_factory.create_scal_recommendation("low") # (not supported yet to make WaterOil only..) interp = scal.interpolate(-0.5) sat_table_str_ok(interp.SWOF()) sat_table_str_ok(interp.SGOF()) sat_table_str_ok(interp.SLGOF()) sat_table_str_ok(interp.SOF3()) check_table(interp.wateroil.table) check_table(interp.gasoil.table) # Check that we error if any of the parameters above is missing: for case in ["low", "BASE", "high"]: copy1 = scal_input.copy() del copy1[case] with pytest.raises(ValueError): pyscal_factory.create_scal_recommendation(copy1) go_only = scal_input.copy() del go_only["low"]["now"] del go_only["low"]["nw"] gasoil = pyscal_factory.create_scal_recommendation(go_only) assert gasoil.low.wateroil is None assert gasoil.base.wateroil is not None assert gasoil.high.wateroil is not None # SCALrecommendation of gasoil only works as long as you # don't try to ask for water data: assert "SGFN" in gasoil.interpolate(-0.4).SGFN() assert "SWOF" not in gasoil.interpolate(-0.2).SWOF() basehigh = scal_input.copy() del basehigh["low"] with pytest.raises(ValueError, match='"low" case not supplied'): pyscal_factory.create_scal_recommendation(basehigh) baselow = scal_input.copy() del baselow["high"] with pytest.raises(ValueError, match='"high" case not supplied'): pyscal_factory.create_scal_recommendation(baselow) with pytest.raises( ValueError, match="All values in parameter dict must be dictionaries"): pyscal_factory.create_scal_recommendation({ "low": [1, 2], "base": { "swl": 0.1 }, "high": { "swl": 0.1 } })