Example #1
0
def test_factory_wateroilgas():
    """Test creating discrete cases of WaterOilGas from factory"""
    pyscal_factory = PyscalFactory()

    wog = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    sat_table_str_ok(swof)  # sgof code works for swof also currently
    sat_table_str_ok(sgof)
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof
    check_table(wog.gasoil.table)
    check_table(wog.wateroil.table)

    # Some users will mess up lower vs upper case:
    wog = pyscal_factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    sat_table_str_ok(swof)  # sgof code works for swof also currently
    sat_table_str_ok(sgof)
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof

    # Mangling data
    wateroil = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1))
    assert wateroil.gasoil is None
Example #2
0
def test_factory_wateroilgas():
    logging.getLogger().setLevel("INFO")

    factory = PyscalFactory()

    wog = factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof

    # Some users will mess up lower vs upper case:
    wog = factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof

    # Mangling data:
    with pytest.raises(ValueError):
        factory.create_water_oil_gas(dict(nw=2, now=3, ng=1))
def test_make_scalrecommendation():
    """Test that we can make scal recommendation objects
    from three WaterOilGas objects"""

    low = PyscalFactory.create_water_oil_gas(LOW_SAMPLE_LET)
    base = PyscalFactory.create_water_oil_gas(BASE_SAMPLE_LET)
    high = PyscalFactory.create_water_oil_gas(HIGH_SAMPLE_LET)
    rec = SCALrecommendation(low, base, high)
    interpolant = rec.interpolate(-0.5, h=0.2)
    check_table(interpolant.wateroil.table)
    check_table(interpolant.gasoil.table)

    # Check preservation of tags.
    swof = interpolant.SWOF()
    assert "SCAL recommendation interpolation to -0.5" in swof
    assert "SCAL recommendation interpolation to -0.5" in interpolant.SGOF()
    assert "SCAL recommendation interpolation to -0.5" in interpolant.SWFN()
    assert "SCAL recommendation interpolation to -0.5" in interpolant.SOF3()
    assert "SCAL recommendation interpolation to -0.5" in interpolant.SGFN()

    assert swof.count("SATNUM X") == 1
    assert interpolant.SOF3().count("SATNUM X") == 1

    # Check different comment when different interpolation parameter:
    interpolant = rec.interpolate(-0.777, 0.888, h=0.2)
    assert "SCAL recommendation interpolation to -0.777" in interpolant.SWOF()
    assert "SCAL recommendation interpolation to 0.888" in interpolant.SGOF()
Example #4
0
def test_xls_factory():
    """Test/demonstrate how to go from data in an excel row to pyscal objects

    This test function predates the load_relperm_df() function, but can
    still be in here.
    """

    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"])

    for ((satnum, _), params) in scalinput.iterrows():
        assert satnum
        wog = PyscalFactory.create_water_oil_gas(params.to_dict())
        swof = wog.SWOF()
        assert "LET krw" in swof
        assert "LET krow" in swof
        assert "Simplified J" in swof
        sgof = wog.SGOF()
        sat_table_str_ok(sgof)
        assert "LET krg" in sgof
        assert "LET krog" in sgof
def test_fast():
    """Test the fast option"""
    low_fast = PyscalFactory.create_water_oil_gas(LOW_SAMPLE_LET, fast=True)
    base_fast = PyscalFactory.create_water_oil_gas(BASE_SAMPLE_LET, fast=True)
    high_fast = PyscalFactory.create_water_oil_gas(HIGH_SAMPLE_LET, fast=True)

    rec = SCALrecommendation(low_fast, base_fast, high_fast)
    interp = rec.interpolate(-0.5)
    assert rec.fast
    assert interp.fast

    # test that one or more inputs not being set to fast does not trigger fast mode
    low = PyscalFactory.create_water_oil_gas(LOW_SAMPLE_LET)
    base = PyscalFactory.create_water_oil_gas(BASE_SAMPLE_LET)
    high = PyscalFactory.create_water_oil_gas(HIGH_SAMPLE_LET)

    rec = SCALrecommendation(low_fast, base_fast, high)
    interp = rec.interpolate(-0.5)
    assert not rec.fast
    assert not interp.fast

    rec = SCALrecommendation(low, base_fast, high)
    interp = rec.interpolate(-0.5)
    assert not rec.fast
    assert not interp.fast

    rec = SCALrecommendation(low, base, high)
    interp = rec.interpolate(-0.5)
    assert not rec.fast
    assert not interp.fast
Example #6
0
def test_factory_wateroilgas_wo():
    """Test making only wateroil through the wateroilgas factory"""
    pyscal_factory = PyscalFactory()
    wog = pyscal_factory.create_water_oil_gas(
        dict(nw=2, now=3, kroend=0.5, sorw=0.04, swcr=0.1))
    swof = wog.SWOF()
    assert "Corey krw" in swof
    assert "krw" in wog.wateroil.table
    sat_table_str_ok(swof)
    check_table(wog.wateroil.table)
    assert wog.gasoil is None

    wog.SGOF()
def test_make_scalrecommendation_go():
    """Test that we can make scal recommendation objects
    from three WaterOilGas objects, but only with GasOil
    objects"""

    go_param_names = [
        "swirr",
        "sorg",
        "krgend",
        "krgmax",
        "swl",
        "sgcr",
        "Lg",
        "Eg",
        "Tg",
        "Log",
        "Eog",
        "Tog",
        "kroend",
    ]

    low_let_go = slicedict(LOW_SAMPLE_LET, go_param_names)
    low = PyscalFactory.create_water_oil_gas(low_let_go)
    base_let_go = slicedict(BASE_SAMPLE_LET, go_param_names)
    base = PyscalFactory.create_water_oil_gas(base_let_go)
    high_let_go = slicedict(HIGH_SAMPLE_LET, go_param_names)
    assert "Lw" not in high_let_go
    high = PyscalFactory.create_water_oil_gas(high_let_go)
    rec = SCALrecommendation(low, base, high)
    assert rec.type == WaterOilGas
    interpolant = rec.interpolate(-0.5)
    check_table(interpolant.gasoil.table)
    assert interpolant.wateroil is None
    sat_table_str_ok(interpolant.SGOF())
    sat_table_str_ok(interpolant.SGFN())

    # This should return empty string
    assert not interpolant.SWOF()
Example #8
0
def test_factory_wog_gascondensate():
    """Test modelling of gas condensate, which in pyscal terms
    is the same as wateroilgas, except that we allow for aliasing
    in sgrw=sorw for the underlying WaterOil object, and also there
    are additional parameters sgro and kromax for GasOil."""
    wcg = PyscalFactory.create_water_oil_gas(
        dict(
            nw=2,
            now=3,
            ng=1,
            nog=2,
            sgrw=0.1,
            swl=0.1,
            sgcr=0.1,
            sgro=0.1,
            kroend=0.5,
            kromax=0.9,
        ))
    assert wcg.gasoil.sgro == 0.1
    assert wcg.wateroil.sorw == 0.1

    swof = wcg.SWOF()
    sgof = wcg.SGOF()

    # sgrw has been aliased to sorw, but the WaterOil object does not know that:
    assert "sgrw" not in swof
    assert "sorw=0.1" in swof
    assert "sgro=0.1" in sgof
    assert "kroend=0.5" in sgof
    assert "kromax=0.9" in sgof

    sat_table_str_ok(swof)
    sat_table_str_ok(sgof)

    # Different sorw and sgrw is a hard error:
    with pytest.raises(ValueError, match="must equal"):
        PyscalFactory.create_water_oil_gas(
            dict(nw=2, now=3, ng=1, nog=2, sorw=0.2, sgrw=0.1, swl=0.1))

    # But it will pass if they both are supplied but are equal:
    wcg_2 = PyscalFactory.create_water_oil_gas(
        dict(nw=2, now=3, ng=1, nog=2, sorw=0.2, sgrw=0.2, swl=0.1))
    assert "sorw=0.2" in wcg_2.SWOF()

    # kroend higher than kromax is an error:
    with pytest.raises(AssertionError):
        PyscalFactory.create_water_oil_gas(
            dict(
                nw=2,
                now=3,
                ng=1,
                nog=2,
                sgcr=0.1,
                sgro=0.1,
                kromax=0.5,
                kroend=0.8,
                swl=0.1,
            ))
Example #9
0
def test_factory_wateroilgas():
    """Test creating discrete cases of WaterOilGas from factory"""
    pyscal_factory = PyscalFactory()

    # Factory refuses to create incomplete defaulted objects.
    with pytest.raises(ValueError):
        pyscal_factory.create_water_oil_gas()

    with pytest.raises(TypeError):
        # (this must be a dictionary)
        # pylint: disable=unexpected-keyword-arg
        pyscal_factory.create_water_oil_gas(swirr=0.01)  # noqa

    with pytest.raises(TypeError):
        pyscal_factory.create_water_oil_gas(params="swirr 0.01")

    wog = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    sat_table_str_ok(swof)  # sgof code works for swof also currently
    sat_table_str_ok(sgof)
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof
    check_table(wog.gasoil.table)
    check_table(wog.wateroil.table)

    # Some users will mess up lower vs upper case:
    wog = pyscal_factory.create_water_oil_gas(dict(NW=2, NOW=3, NG=1, nog=2.5))
    swof = wog.SWOF()
    sgof = wog.SGOF()
    sat_table_str_ok(swof)  # sgof code works for swof also currently
    sat_table_str_ok(sgof)
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof

    # Mangling data
    wateroil = pyscal_factory.create_water_oil_gas(dict(nw=2, now=3, ng=1))
    assert wateroil.gasoil is None
Example #10
0
def test_make_scalrecommendation_wo():
    """Test that we can make scal recommendation objects
    from three WaterOilGas objects, but only with WaterOil
    objects"""

    wo_param_names = [
        "swirr",
        "sorw",
        "krwend",
        "krwmax",
        "swl",
        "swcr",
        "Lw",
        "Ew",
        "Tw",
        "Lo",
        "Eo",
        "To",
        "krowend",
    ]

    low_let_wo = slicedict(LOW_SAMPLE_LET, wo_param_names)
    low = PyscalFactory.create_water_oil_gas(low_let_wo)
    base_let_wo = slicedict(BASE_SAMPLE_LET, wo_param_names)
    base = PyscalFactory.create_water_oil_gas(base_let_wo)
    high_let_wo = slicedict(HIGH_SAMPLE_LET, wo_param_names)
    assert "Lg" not in high_let_wo
    high = PyscalFactory.create_water_oil_gas(high_let_wo)
    rec = SCALrecommendation(low, base, high)
    interpolant = rec.interpolate(-0.5)
    check_table(interpolant.wateroil.table)
    assert interpolant.gasoil is None
    assert sat_table_str_ok(interpolant.SWOF())
    assert sat_table_str_ok(interpolant.SWFN())

    # This should return empty string
    assert not interpolant.SGOF()
Example #11
0
def test_factory_wateroilgas_deprecated_krowgend(caplog):
    """Some users will use deprecated  krowend krogend,
    these values should be translated to kroend"""
    wog = PyscalFactory.create_water_oil_gas(
        dict(nw=2, now=3, ng=1, nog=2.5, krowend=0.6, krogend=0.7))
    assert "deprecated" in caplog.text
    swof = wog.SWOF()
    assert "kroend=0.6" in swof
    sgof = wog.SGOF()
    assert "kroend=0.7" in sgof
    assert not wog.threephaseconsistency()
    sat_table_str_ok(swof)  # sgof code works for swof also currently
    sat_table_str_ok(sgof)
    assert "Corey krg" in sgof
    assert "Corey krog" in sgof
    assert "Corey krw" in swof
    assert "Corey krow" in swof
Example #12
0
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
Example #13
0
def test_xls_factory():
    """Test/demonstrate how to go from data in an excel row to pyscal objects

    This test function predates the load_relperm_df() function, but can
    still be in here.
    """
    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, _), params) in scalinput.iterrows():
        assert satnum
        wog = PyscalFactory.create_water_oil_gas(params.to_dict())
        swof = wog.SWOF()
        assert "LET krw" in swof
        assert "LET krow" in swof
        assert "Simplified J" in swof
        sgof = wog.SGOF()
        sat_table_str_ok(sgof)
        assert "LET krg" in sgof
        assert "LET krog" in sgof