Exemplo n.º 1
0
def test_df2ecl_order():
    """Test that we can control the keyword order in generated
    strings by the list supplied in keywords argument"""
    eclfiles = EclFiles(DATAFILE)
    satdf = satfunc.df(eclfiles.get_ecldeck())

    swof_sgof = satfunc.df2ecl(satdf, keywords=["SWOF", "SGOF"])
    assert swof_sgof.find("SWOF") < swof_sgof.find("SGOF")
    sgof_swof = satfunc.df2ecl(satdf, keywords=["SGOF", "SWOF"])
    assert sgof_swof.find("SGOF") < sgof_swof.find("SWOF")

    only_swof = satfunc.df2ecl(satdf, keywords=["SWOF"])
    assert "SGOF" not in only_swof
    only_sgof = satfunc.df2ecl(satdf, keywords="SGOF")
    assert "SWOF" not in only_sgof
Exemplo n.º 2
0
def test_sgof_satnuminferrer(tmpdir, mocker):
    """Test inferring of SATNUMS in SGOF strings"""
    sgofstr = """
SGOF
  0 0 1 1
  1 1 0 0
/
  0 0 1 1
  0.5 0.5 0.5 0.5
  1 1 0 0
/
  0 0 1 0
  0.1 0.1 0.1 0.1
  1 1 0 0
/
"""
    tmpdir.chdir()
    assert inferdims.guess_dim(sgofstr, "TABDIMS", 0) == 3
    sgofdf = satfunc.df(sgofstr)
    assert "SATNUM" in sgofdf
    assert len(sgofdf["SATNUM"].unique()) == 3
    assert len(sgofdf) == 8
    inc = satfunc.df2ecl(sgofdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(sgofdf, df_from_inc)

    # Write to file and try to parse it with command line:
    sgoffile = "__sgof_tmp.txt"
    Path(sgoffile).write_text(sgofstr)
    mocker.patch(
        "sys.argv",
        ["ecl2csv", "satfunc", "-v", sgoffile, "-o", sgoffile + ".csv"])
    ecl2csv.main()
    parsed_sgof = pd.read_csv(sgoffile + ".csv")
    assert len(parsed_sgof["SATNUM"].unique()) == 3
Exemplo n.º 3
0
def test_satfunc_roundtrip():
    """Test that we can produce a SATNUM dataframe from the Reek case, convert
    it back to an include file, and then reinterpret it to the same"""
    eclfiles = EclFiles(DATAFILE)
    satdf = satfunc.df(eclfiles.get_ecldeck())
    inc = satfunc.df2ecl(satdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(
        satdf.sort_values(["SATNUM", "KEYWORD"]),
        df_from_inc.sort_values(["SATNUM", "KEYWORD"]),
    )
Exemplo n.º 4
0
def test_str2df(string, expected_df):
    """Test that we can parse a string into a DataFrame,
    back to string, and to DataFrame again"""
    satdf = satfunc.df(string)
    pd.testing.assert_frame_equal(satdf, expected_df)

    if expected_df.empty:
        return

    inc = satfunc.df2ecl(satdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(df_from_inc, expected_df)
Exemplo n.º 5
0
def test_str2df():
    """Test parsing of a direct string"""
    swofstr = """
SWOF
 0 0 1 1
 1 1 0 0
 /
"""
    satdf = satfunc.df(swofstr)
    assert len(satdf) == 2
    inc = satfunc.df2ecl_swof(satdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(satdf, df_from_inc)

    swofstr2 = """
-- RUNSPEC -- (this line is optional)

TABDIMS
  2 /

-- PROPS -- (optional)

SWOF
 0 0 1 1
 1 1 0 0
/
 0 0 1 1
 0.5 0.5 0.5 0.5
 1 1 0 0
/
"""
    satdf2 = satfunc.df(swofstr2)
    assert "SATNUM" in satdf
    assert len(satdf2["SATNUM"].unique()) == 2
    assert len(satdf2) == 5

    inc = satfunc.df2ecl(satdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(satdf, df_from_inc)

    # Try empty/bogus data:
    bogusdf = satfunc.deck2df("SWRF\n 0 /\n")
    # (warnings should be issued)
    assert bogusdf.empty

    # Test with bogus E100 keywords:
    tricky = satfunc.deck2df("FOO\n\nSWOF\n 0 0 0 1/ 1 1 1 0\n/\n")
    assert not tricky.empty
    assert len(tricky["SATNUM"].unique()) == 1
Exemplo n.º 6
0
def test_sof2():
    """Test parsing of SOF2"""
    string = """
SOF2
  0 1
  1 0
/
"""
    sof2_df = satfunc.df(string)
    assert len(sof2_df) == 2
    assert "SO" in sof2_df
    assert "KRO" in sof2_df
    inc = satfunc.df2ecl(sof2_df)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(sof2_df, df_from_inc)
Exemplo n.º 7
0
def test_slgof(tmpdir):
    """Test parsing of SLGOF"""
    tmpdir.chdir()
    string = """
SLGOF
  0 1 1 0
  1 0 0 0
/
"""
    slgof_df = satfunc.df(string)
    assert len(slgof_df) == 2
    assert "SL" in slgof_df
    assert "KRG" in slgof_df
    assert "KRO" in slgof_df
    assert "PCOG" in slgof_df
    inc = satfunc.df2ecl(slgof_df, filename="slgof.inc")
    assert os.path.exists("slgof.inc")
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(slgof_df, df_from_inc)
Exemplo n.º 8
0
def test_sgwfn():
    """Test parsing of SGWFN"""
    string = """
 SGWFN
  0 1 1 0
  1 0 0 0
 /
 """
    sgwfn_df = satfunc.df(string)
    assert len(sgwfn_df) == 2
    assert "SG" in sgwfn_df
    assert "KRG" in sgwfn_df
    assert "KRW" in sgwfn_df
    assert "PCGW" in sgwfn_df
    inc = satfunc.df2ecl(sgwfn_df)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(
        sgwfn_df.sort_values(["SATNUM", "KEYWORD"]),
        df_from_inc.sort_values(["SATNUM", "KEYWORD"]),
    )
Exemplo n.º 9
0
def test_sgfn():
    """Test parsing of SGFN"""
    string = """
SGFN
  0 1 0
  1 0 0
/
  0 1 0
  1 0.1 1
/
"""
    sgfn_df = satfunc.df(string)
    assert len(sgfn_df) == 4
    assert len(sgfn_df["SATNUM"].unique()) == 2
    assert "SG" in sgfn_df
    assert "KRG" in sgfn_df
    assert "PCOG" in sgfn_df
    inc = satfunc.df2ecl(sgfn_df)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(sgfn_df, df_from_inc)
Exemplo n.º 10
0
def test_satfunc2df():
    """Test that dataframes are produced"""
    eclfiles = EclFiles(DATAFILE)
    satdf = satfunc.deck2df(eclfiles.get_ecldeck())

    assert not satdf.empty
    assert "KEYWORD" in satdf  # for all data
    assert "SATNUM" in satdf  # for all data

    assert "SWOF" in satdf["KEYWORD"].unique()
    assert "SGOF" in satdf["KEYWORD"].unique()
    assert "SW" in satdf
    assert "KRW" in satdf
    assert "KROW" in satdf
    assert "SG" in satdf
    assert "KROG" in satdf
    assert satdf["SATNUM"].unique() == [1]

    inc = satfunc.df2ecl(satdf)
    df_from_inc = satfunc.df(inc)
    pd.testing.assert_frame_equal(
        satdf.sort_values(["SATNUM", "KEYWORD"]),
        df_from_inc.sort_values(["SATNUM", "KEYWORD"]),
    )