Exemple #1
0
def test_foreseeable_future(tmpdir):
    """The foreseeable future in reservoir simulation is "defined" as 500 years.

    Check that we support summary files with this timespan"""
    tmpdir.chdir()
    src_dframe = pd.DataFrame([
        {
            "DATE": "2000-01-01",
            "FPR": 200
        },
        {
            "DATE": "2500-01-01",
            "FPR": 180
        },
    ])
    eclsum = df2eclsum(src_dframe, casename="PLUGABANDON")

    dframe = summary.df(eclsum)
    assert (dframe.index == [
        dt(2000, 1, 1),
        # This discrepancy is due to seconds as a 32-bit float
        # having an accuracy limit (roundoff-error)
        # https://github.com/equinor/ecl/issues/803
        dt(2499, 12, 31, 23, 55, 44),
    ]).all()

    # Try with time interpolation involved:
    dframe = summary.df(eclsum, time_index="yearly")
    assert len(dframe) == 501
    assert dframe.index.max() == datetime.date(year=2500, month=1, day=1)

    # Try with one-year timesteps:
    src_dframe = pd.DataFrame({
        "DATE":
        pd.date_range("2000-01-01", "2069-01-01", freq="YS"),
        "FPR":
        range(70),
    })
    eclsum = df2eclsum(src_dframe, casename="PLUGABANDON")
    dframe = summary.df(eclsum)
    # Still buggy:
    assert dframe.index[-1] == dt(2068, 12, 31, 23, 57, 52)

    # Try with one-year timesteps, starting late:
    src_dframe = pd.DataFrame({
        "DATE": [datetime.date(2400 + year, 1, 1) for year in range(69)],
        "FPR":
        range(69),
    })
    eclsum = df2eclsum(src_dframe, casename="PLUGABANDON")
    dframe = summary.df(eclsum)
    # Works fine when stepping only 68 years:
    assert dframe.index[-1] == dt(2468, 1, 1, 0, 0, 0)
Exemple #2
0
def test_df2eclsum_datetimeindex():
    """Test that providing a dataframe with a datetimeindex also works"""
    dframe = pd.DataFrame(
        [
            {"DATE": "2016-01-01", "FOPT": 1000, "FOPR": 100},
        ]
    )
    dframe["DATE"] = pd.to_datetime(dframe["DATE"])
    dframe.set_index("DATE")

    roundtrip = df(df2eclsum(dframe))
    assert isinstance(roundtrip.index, pd.DatetimeIndex)
    assert roundtrip["FOPR"].values == [100]
    assert roundtrip["FOPT"].values == [1000]
Exemple #3
0
def test_smry_meta_synthetic():
    """What does meta look like when we start from a synthetic summary?

    ecl2df currently does not try to set the units to anything when
    making synthetic summary.
    """
    dframe = pd.DataFrame(
        [
            {"DATE": np.datetime64("2016-01-01"), "FOPT": 1000, "FOPR": 100},
        ]
    ).set_index("DATE")
    synt_meta = smry_meta(df2eclsum(dframe))

    # Dummy unit provided by EclSum:
    assert synt_meta["FOPT"]["unit"] == "UNIT"
Exemple #4
0
def test_df2eclsum(dframe):
    """Test that a dataframe can be converted to an EclSum object, and then read
    back again"""

    # Massage the dframe first so we can assert on equivalence after.
    dframe = _fix_dframe_for_libecl(dframe)

    eclsum = df2eclsum(dframe)
    if dframe.empty:
        assert eclsum is None
        return

    dframe_roundtrip = df(eclsum)
    pd.testing.assert_frame_equal(
        dframe.sort_index(axis=1),
        dframe_roundtrip.sort_index(axis=1),
        check_dtype=False,
    )
Exemple #5
0
def test_df2eclsum_errors():
    """Test various error conditions, checking that the correct error message
    is emitted"""
    dframe = pd.DataFrame(
        [
            {"DATE": "2016-01-01", "FOPT": 1000, "FOPR": 100},
        ]
    )
    with pytest.raises(ValueError, match="casename foobar must be UPPER CASE"):
        df2eclsum(dframe, casename="foobar")
    with pytest.raises(ValueError, match="Do not use dots in casename"):
        df2eclsum(dframe, casename="FOOBAR.UNSMRY")  # .UNSMRY should not be included

    # No date included:
    with pytest.raises(ValueError, match="dataframe must have a datetime index"):
        df2eclsum(pd.DataFrame([{"FOPT": 1000}]))