def test_rock(): """Test parsing of the ROCK keyword from a string""" deck = """ROCK 100 1.1 /""" rock_df = pvt.rock_fromdeck(EclFiles.str2deck(deck)) assert len(rock_df) == 1 assert "PRESSURE" in rock_df assert "COMPRESSIBILITY" in rock_df dframe_via_string = pvt.rock_fromdeck(pvt.df2ecl_rock(rock_df)) pd.testing.assert_frame_equal(dframe_via_string, rock_df)
def test_pvt_reek(): """Test that the Reek PVT input can be parsed individually""" eclfiles = EclFiles(DATAFILE) pvto_df = pvt.pvto_fromdeck(eclfiles.get_ecldeck()) assert "PVTNUM" in pvto_df assert "PRESSURE" in pvto_df assert "VOLUMEFACTOR" in pvto_df assert "VISCOSITY" in pvto_df assert max(pvto_df["PVTNUM"]) == 1 assert max(pvto_df["PRESSURE"]) == 700.1 # Check count of undersaturated lines pr. RS: # (nb: double brackets in .loc to ensure dataframe is returned) assert len(pvto_df.set_index("RS").loc[[0]]) == 2 assert len(pvto_df.set_index("RS").loc[[15.906]]) == 1 assert len(pvto_df.set_index("RS").loc[[105.5]]) == 15 assert len(pvto_df["RS"].unique()) == 20 assert pvto_df["VOLUMEFACTOR"].max() == 2.851 assert pvto_df["VISCOSITY"].max() == 1.0001 dframe_via_string = pvt.pvto_fromdeck(pvt.df2ecl_pvto(pvto_df)) pd.testing.assert_frame_equal(dframe_via_string, pvto_df) density_df = pvt.density_fromdeck(eclfiles.get_ecldeck()) assert "PVTNUM" in density_df assert "OILDENSITY" in density_df assert "WATERDENSITY" in density_df assert "GASDENSITY" in density_df assert len(density_df) == 1 assert density_df["WATERDENSITY"].values[0] == 999.04 dframe_via_string = pvt.density_fromdeck(pvt.df2ecl_density(density_df)) pd.testing.assert_frame_equal(dframe_via_string, density_df) rock_df = pvt.rock_fromdeck(eclfiles.get_ecldeck()) assert "PVTNUM" in rock_df assert len(rock_df) == 1 assert "PRESSURE" in rock_df assert "COMPRESSIBILITY" in rock_df assert rock_df["PRESSURE"].values[0] == 327.3 pvtw_df = pvt.pvtw_fromdeck(eclfiles.get_ecldeck()) assert "PVTNUM" in pvtw_df assert pvtw_df["PVTNUM"].values[0] == 1 assert len(pvtw_df) == 1 assert "PRESSURE" in pvtw_df assert "VOLUMEFACTOR" in pvtw_df assert "COMPRESSIBILITY" in pvtw_df assert "VISCOSITY" in pvtw_df assert "VISCOSIBILITY" in pvtw_df assert pvtw_df["VISCOSITY"].values[0] == 0.25 pvdg_df = pvt.pvdg_fromdeck(eclfiles.get_ecldeck()) assert "PVTNUM" in pvdg_df assert "PRESSURE" in pvdg_df assert "VOLUMEFACTOR" in pvdg_df assert "VISCOSITY" in pvdg_df assert len(pvdg_df["PVTNUM"].unique()) == 1 assert pvdg_df["PVTNUM"].max() == 1 assert len(pvdg_df) == 15
def test_df2ecl_rock(tmpdir): """Test generation of ROCK include files from dataframes""" tmpdir.chdir() rock_df = pd.DataFrame( columns=["PVTNUM", "KEYWORD", "PRESSURE", "COMPRESSIBILITY"], data=[[1, "ROCK", 100, 0.001]], ) rock_inc = pvt.df2ecl(rock_df) assert "ROCK" in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(ROCK="foo")) assert "foo" in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(DENSITY="foo")) assert "foo" not in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(ROCK="foo\nbar"), filename="foo.inc") assert Path("foo.inc").is_file() assert "foo" in rock_inc assert "bar" in rock_inc # Multiline comments are tricky, is the output valid? rock_df_from_inc = pvt.rock_fromdeck(rock_inc).assign(KEYWORD="ROCK") # Need to sort columns for comparison, as column order does not matter # in dataframes, but it does in the function assert_frame_equal rock_df_from_inc = rock_df_from_inc.reindex( sorted(rock_df_from_inc.columns), axis=1 ) rock_df = rock_df_from_inc.reindex(sorted(rock_df.columns), axis=1) pd.testing.assert_frame_equal(rock_df_from_inc, rock_df) rock_inc = pvt.df2ecl(rock_df, keywords=["DENSITY"]) assert not rock_inc rock_inc = pvt.df2ecl(rock_df, keywords="DENSITY") assert not rock_inc rock_inc = pvt.df2ecl(rock_df, keywords=["ROCK", "DENSITY"]) assert "ROCK" in rock_inc assert "DENSITY" not in rock_inc rock_inc = pvt.df2ecl(rock_df, keywords="ROCK") assert "ROCK" in rock_inc # This dataframe is ignored, if we miss PVTNUM: ambig_rock_df = pd.DataFrame( columns=["KEYWORD", "PRESSURE", "COMPRESSIBILITY"], data=[["ROCK", 100, 0.001], ["ROCK", 200, 0.002]], ) assert "ROCK" not in pvt.df2ecl_rock(ambig_rock_df) # But if only one row, it is ok: assert "ROCK" in pvt.df2ecl_rock(ambig_rock_df.head(1)) # If we don't want the ROCK keyword, we won't get it: nonrock_inc = pvt.df2ecl(rock_df, keywords=["PVTO"]) assert "ROCK" not in nonrock_inc
def test_df2ecl(tmpdir): """Test generation of PVT include files from dataframes The validity of produced dataframes is tested in other test functions herein, here we mainly test for the API and error handling""" tmpdir.chdir() with pytest.raises(ValueError): pvt.df2ecl(pd.DataFrame()) rock_df = pd.DataFrame( columns=["PVTNUM", "KEYWORD", "PRESSURE", "COMPRESSIBILITY"], data=[[1, "ROCK", 100, 0.001]], ) rock_inc = pvt.df2ecl(rock_df) assert "ROCK" in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(ROCK="foo")) assert "foo" in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(DENSITY="foo")) assert "foo" not in rock_inc rock_inc = pvt.df2ecl(rock_df, comments=dict(ROCK="foo\nbar"), filename="foo.inc") assert os.path.exists("foo.inc") assert "foo" in rock_inc assert "bar" in rock_inc # Multiline comments are tricky, is the output valid? rock_df_from_inc = pvt.rock_fromdeck(rock_inc).assign(KEYWORD="ROCK") # Need to sort columns for comparison, as column order does not matter # in dataframes, but it does in the function assert_frame_equal rock_df_from_inc = rock_df_from_inc.reindex(sorted( rock_df_from_inc.columns), axis=1) rock_df = rock_df_from_inc.reindex(sorted(rock_df.columns), axis=1) print(rock_df_from_inc) print(rock_df) pd.testing.assert_frame_equal(rock_df_from_inc, rock_df) rock_inc = pvt.df2ecl(rock_df, keywords=["DENSITY"]) assert not rock_inc rock_inc = pvt.df2ecl(rock_df, keywords="DENSITY") assert not rock_inc rock_inc = pvt.df2ecl(rock_df, keywords=["ROCK", "DENSITY"]) assert "ROCK" in rock_inc assert "DENSITY" not in rock_inc rock_inc = pvt.df2ecl(rock_df, keywords="ROCK") assert "ROCK" in rock_inc