Пример #1
0
def test_linear_input(h, sw_mid):
    """Linear input creates difficulties with sorw, which is used in
    add_fromtable(). The intention of the test is to avoid crashes when
    add_fromtable().

    estimate_sorw() is unreliable on linear input, and returns 0 or 1 on the
    given test dataset. Correctness of sorw should not be needed for
    add_fromtable().

    This tests fails in pyscal v0.7.7"""
    dframe = pd.DataFrame(
        columns=["SW", "KRW", "KROW", "PC"],
        data=[[sw, sw, 1 - sw, 1 - sw] for sw in [0, sw_mid, 1.0]],
    )
    wateroil = WaterOil(h=h, swl=0)
    wateroil.add_fromtable(dframe)
    assert wateroil.selfcheck()

    # GasOil did not fail in v0.7.7, but test anyway:
    gasoil = GasOil(h=h, swl=0)
    gasoil.add_fromtable(dframe,
                         sgcolname="SW",
                         krgcolname="KRW",
                         krogcolname="KROW",
                         pccolname="PCOW")
    assert gasoil.selfcheck()
Пример #2
0
def test_go_fromtable_simple():
    df1 = pd.DataFrame(columns=["SG", "KRG", "KROG", "PC"],
                       data=[[0, 0, 1, 2], [1, 1, 0, 0]])
    go = GasOil(h=0.1)
    go.add_fromtable(df1,
                     sgcolname="SG",
                     krgcolname="KRG",
                     krogcolname="KROG",
                     pccolname="PC")
    check_go_table(go.table)
Пример #3
0
def test_go_fromtable_simple():
    """Test reading of a simple gasoil table"""
    df1 = pd.DataFrame(columns=["SG", "KRG", "KROG", "PC"],
                       data=[[0, 0, 1, 2], [1, 1, 0, 0]])
    gasoil = GasOil(h=0.1)
    gasoil.add_fromtable(df1,
                         sgcolname="SG",
                         krgcolname="KRG",
                         krogcolname="KROG",
                         pccolname="PC")
    check_table(gasoil.table)
Пример #4
0
def test_fromtable_types():
    """Test loading from a table with incorrect types"""

    # This frame is valid, but the type was wrong. This
    # can happen if data is via CSV files, and some other rows
    # ruin the numerical interpretation of a column.
    df1 = pd.DataFrame(
        columns=["SW", "KRW", "KROW", "PC"],
        data=[["0", "0", "1", "2"], ["1", "1", "0", "0"]],
    )
    wateroil = WaterOil(h=0.1)
    wateroil.add_fromtable(df1,
                           swcolname="SW",
                           krwcolname="KRW",
                           krowcolname="KROW",
                           pccolname="PC")
    assert "krw" in wateroil.table.columns
    assert "krow" in wateroil.table.columns
    assert "pc" in wateroil.table.columns
    check_table(wateroil.table)

    gasoil = GasOil(h=0.1)
    gasoil.add_fromtable(df1,
                         sgcolname="SW",
                         krgcolname="KRW",
                         krogcolname="KROW",
                         pccolname="PC")
    assert "krg" in gasoil.table.columns
    assert "krog" in gasoil.table.columns
    assert "pc" in gasoil.table.columns
    check_table(gasoil.table)

    # But this should not make sense.
    df2 = pd.DataFrame(
        columns=["SW", "KRW", "KROW", "PC"],
        data=[["0", dict(foo="bar"), "1", "2"], ["1", "1", "0", "0"]],
    )
    wateroil = WaterOil(h=0.1)
    with pytest.raises((ValueError, TypeError)):
        wateroil.add_fromtable(df2,
                               swcolname="SW",
                               krwcolname="KRW",
                               krowcolname="KROW",
                               pccolname="PC")
    gasoil = GasOil(h=0.1)
    with pytest.raises((ValueError, TypeError)):
        gasoil.add_fromtable(df2,
                             sgcolname="SW",
                             krgcolname="KRW",
                             krogcolname="KROW",
                             pccolname="PC")
Пример #5
0
def test_go_invalidcurves():
    """Test  fromtable on invalid gasoil data"""
    # Sw data not ordered:
    krg1 = pd.DataFrame(columns=["Sg", "krg"],
                        data=[[0.15, 0], [0.1, 1], [1, 1]])
    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # pchip-interpolator raises this error;
        # x coordinates are not in increasing order
        gasoil.add_fromtable(krg1, krgcolname="krg")

    krg2 = pd.DataFrame(columns=["Sg", "krg"],
                        data=[[0.15, 0], [0.4, 0.6], [0.6, 0.4], [1, 1]])
    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # Should get notified that krg is not monotonous
        gasoil.add_fromtable(krg2, krgcolname="krg")
    krog2 = pd.DataFrame(columns=["Sg", "krog"],
                         data=[[0.15, 1], [0.4, 0.4], [0.6, 0.6], [1, 0]])
    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # Should get notified that krog is not monotonous
        gasoil.add_fromtable(krog2, krogcolname="krog")
    pc2 = pd.DataFrame(columns=["Sg", "pc"],
                       data=[[0.15, 1], [0.4, 0.4], [0.6, 0.6], [1, 0]])
    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # Should get notified that pc is not monotonous
        gasoil.add_fromtable(pc2, pccolname="pc")
Пример #6
0
def test_go_fromtable_simple():
    """Test reading of a simple gasoil table"""
    df1 = pd.DataFrame(columns=["SG", "KRG", "KROG", "PC"],
                       data=[[0, 0, 1, 0], [1, 1, 0, 2]])
    gasoil = GasOil(h=0.1)
    gasoil.add_fromtable(df1,
                         sgcolname="SG",
                         krgcolname="KRG",
                         krogcolname="KROG",
                         pccolname="PC")
    assert sum(gasoil.table["krg"]) > 0
    assert sum(gasoil.table["krog"]) > 0
    assert np.isclose(sum(gasoil.table["pc"]), 11)  # Linearly increasing PCOG
    check_table(gasoil.table)
Пример #7
0
def test_gascondensate():
    """Test how sgro works when data is tabulated. Sgro is to be used
    for gas condensate modelling. sgro is tricky because only 0 and sgcr
    are valid values for sgro when constructing the objects."""

    # When sgro is nonzero, we are doing gas condensate modelling:
    gascond_orig = GasOil(sgro=0.2, sgcr=0.2, h=0.1)
    gascond_orig.add_corey_gas()
    gascond_orig.add_corey_oil(kroend=0.8)

    # Make a new object without assuming anything about sgro and sgcr:
    gascond_tabulated = GasOil(h=0.1)
    gascond_tabulated.add_fromtable(gascond_orig.table)
    check_table(gascond_tabulated.table)

    # sgro is estimated correctly in this case:
    assert np.isclose(gascond_tabulated.sgro, gascond_orig.sgro)

    # The object constructed from the table has an extra row at SG=0.1, because
    # we didn't tell it that sgcr was 0.2, otherwise they are numerically
    # equivalent:
    assert len(gascond_tabulated.table) == len(gascond_orig.table) + 1
    pd.testing.assert_frame_equal(
        gascond_orig.table.iloc[1:][["SG", "KRG",
                                     "KROG"]].reset_index(drop=True),
        gascond_tabulated.table.iloc[2:][["SG", "KRG",
                                          "KROG"]].reset_index(drop=True),
    )

    # Make a tricky gascondensate object which has a linear oil curve. The sgro
    # estimate will become 1.0, we should still be able to use this as a table.
    gascond_linear = GasOil(sgro=0.2, sgcr=0.2, h=0.1)
    gascond_linear.add_corey_gas()
    gascond_linear.add_corey_oil(kroend=0.8, kromax=1, nog=1)
    gascond_linear_tabulated = GasOil(h=0.1)
    gascond_linear_tabulated.add_fromtable(gascond_linear.table)

    check_table(gascond_linear_tabulated.table)

    # sgro could not be guessed here, and is reset to zero:
    assert np.isclose(gascond_linear_tabulated.sgro, 0.0)
Пример #8
0
def test_interpolations_go_fromtable():
    """Test based on bug exposed in pyscal 0.6.1, where sgcr
    was underestimated in interpolations following add_fromtable().
    """
    base = pd.DataFrame(
        columns=["Sg", "krg", "krog"],
        data=[
            [0.0, 0.0, 1.0],
            [0.1, 0.0, 1.0],
            [0.2, 0.0, 1.0],  # sgcr
            [0.3, 0.1, 0.9],
            [0.8, 0.8, 0.0],  # sorg
            [0.9, 0.9, 0.0],
            [1.0, 1.0, 0.0],
        ],
    )
    opt = pd.DataFrame(
        columns=["Sg", "krg", "krog"],
        data=[
            [0.0, 0.0, 1.0],
            [0.1, 0.0, 1.0],
            [0.3, 0.0, 1.0],
            [0.4, 0.1, 0.2],  # sgcr
            [0.9, 0.9, 0.0],  # sorg
            [0.95, 0.95, 0.0],
            [1.0, 1.0, 0.0],
        ],
    )
    go_base = GasOil(h=0.01)
    go_base.add_fromtable(base)
    assert np.isclose(go_base.estimate_sgcr(), 0.2)
    assert np.isclose(go_base.estimate_sorg(), 0.2)
    go_opt = GasOil(h=0.01)
    go_opt.add_fromtable(opt)
    assert np.isclose(go_opt.estimate_sgcr(), 0.3)
    assert np.isclose(go_opt.estimate_sorg(), 0.1)

    go_ip = interpolate_go(go_base, go_opt, 0.5, h=0.01)
    assert np.isclose(go_ip.estimate_sgcr(), 0.25)
    assert np.isclose(go_ip.estimate_sorg(), 0.15)
Пример #9
0
def test_go_fromtable_problems():
    """Test loading from a table where there should be problems"""
    df1 = pd.DataFrame(columns=["Sg", "KRG", "KROG", "PCOG"],
                       data=[[0.1, 0, 1, 2], [0.9, 1, 0, 0]])
    # Now sgcr and swl is wrong:
    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # Should say sg must start at zero.
        gasoil.add_fromtable(df1, pccolname="PCOG")
    df2 = pd.DataFrame(columns=["Sg", "KRG", "KROG", "PCOG"],
                       data=[[0.0, 0, 1, 2], [0.9, 0.8, 0, 0]])
    with pytest.raises(ValueError):
        # should say too large swl for pcog interpolation
        gasoil = GasOil(h=0.1)
        gasoil.add_fromtable(df2, pccolname="PCOG")
    gasoil = GasOil(h=0.1, swl=0.1)
    gasoil.add_fromtable(df2, pccolname="PCOG")
    assert np.isclose(gasoil.table["pc"].max(), 2.0)
    assert np.isclose(gasoil.table["pc"].min(), 0.0)
    assert np.isclose(gasoil.table["sg"].max(), 0.9)

    gasoil = GasOil(h=0.1)
    with pytest.raises(ValueError):
        # sg must start at zero
        gasoil.add_fromtable(df1, krgcolname="KRG", krogcolname="KROG")
    # This works fine, but we get warnings on swl not seemingly correct
    gasoil.add_fromtable(df2, krgcolname="KRG", krogcolname="KROG")
    # krg will be extrapolated to sg=1
    float_df_checker(gasoil.table, "sg", 1.0, "krg", 0.8)
    float_df_checker(gasoil.table, "sg", 1.0, "krog", 0.0)
    gasoil = GasOil(h=0.1, swl=0.1)
    gasoil.add_fromtable(df2, krgcolname="KRG", krogcolname="KROG")