示例#1
0
def test_roundtrip_resinsight(filename, readonly_testdata_dir):
    """Test converting all test data sets in testdir into resinsight and back again.

    ResInsight only supports SUMMARY_OBSERVATION.
    """
    dframe = autoparse_file(filename)[1]

    # Reduce to the subset supported by yaml:
    dframe = dframe[dframe["CLASS"] == "SUMMARY_OBSERVATION"].dropna(
        axis="columns", how="all")
    # Drop observations with no date:
    dframe = dframe[~dframe["DATE"].isna()].dropna(axis=1, how="all")

    # Convert to ResInsight dataframe format and back again:
    ri_dframe = df2resinsight_df(dframe)
    ri_roundtrip_dframe = resinsight_df2df(ri_dframe)

    # LABEL is not part of the ResInsight format, and a made-up label
    # is obtained through the roundtrip (when importing back). Skip it
    # when comparing.

    pd.testing.assert_frame_equal(
        ri_roundtrip_dframe.sort_index(axis="columns").drop(
            ["LABEL", "COMMENT", "SUBCOMMENT"],
            axis="columns",
            errors="ignore"),
        dframe.sort_index(axis="columns").drop(
            ["LABEL", "COMMENT", "SUBCOMMENT"],
            axis="columns",
            errors="ignore"),
        check_like=True,
    )
示例#2
0
def test_autoparse_string(string, expected_format, tmp_path):
    """Test that difficult-to-parse-strings are recognized correctly
    (or not recognized at all). The filetype detector code has very mild
    requirements on dataframe validitiy."""
    os.chdir(tmp_path)
    Path("inputfile.txt").write_text(string, encoding="utf8")
    assert autoparse_file("inputfile.txt")[0] == expected_format
示例#3
0
def test_roundtrip_yaml(filename, readonly_testdata_dir):
    """Test converting all test data sets in testdir into yaml and back again.

    Due to yaml supporting a subset of features in the internal dataframe format
    some exceptions must be hardcoded in this test function.

    Also pay attention to the way the yaml parser creates LABEL data.
    """
    dframe = autoparse_file(filename)[1]

    # Reduce to the subset supported by yaml:
    dframe = dframe[(dframe["CLASS"] == "SUMMARY_OBSERVATION")
                    | (dframe["CLASS"] == "BLOCK_OBSERVATION")].dropna(
                        axis="columns", how="all")
    # Convert to YAML (really dict) format and back again:
    obsdict = df2obsdict(dframe)
    yaml_roundtrip_dframe = obsdict2df(obsdict)
    yaml_roundtrip_dframe.set_index("CLASS", inplace=True)
    dframe.set_index("CLASS", inplace=True)
    if "WELL" in yaml_roundtrip_dframe:
        # WELL as used in yaml is not preservable in roundtrips
        del yaml_roundtrip_dframe["WELL"]
    if "WELL" in dframe:
        del dframe["WELL"]
    # print(yaml_roundtrip_dframe)
    # print(dframe)
    pd.testing.assert_frame_equal(
        yaml_roundtrip_dframe.sort_index(axis="columns").sort_values("LABEL"),
        dframe.sort_index(axis="columns").sort_values("LABEL"),
        check_like=True,
    )
示例#4
0
def test_autoparse_string(string, expected_format, tmpdir):
    """Test that difficult-to-parse-strings are recognized correctly
    (or not recognized at all). The filetype detector code has very mild
    requirements on dataframe validitiy."""
    tmpdir.chdir()
    with open("inputfile.txt", "w") as f_handle:
        f_handle.write(string)
    assert autoparse_file("inputfile.txt")[0] == expected_format
示例#5
0
def test_roundtrip_ertobs(filename, readonly_testdata_dir):
    """Test converting all included test data sets into ERT observations
    (as strings) and then parsing it, ensuring that we end up in the
    same place"""
    dframe = autoparse_file(filename)[1]

    # Convert to ERT obs format and back again:
    ertobs_str = df2ertobs(dframe)
    ert_roundtrip_dframe = ertobs2df(ertobs_str)
    ert_roundtrip_dframe.set_index("CLASS", inplace=True)
    dframe.set_index("CLASS", inplace=True)

    # This big loop is only here to aid in debugging when
    # the dataframes do not match, asserting equivalence of
    # subframes
    for _class in dframe.index.unique():
        roundtrip_subframe = (
            ert_roundtrip_dframe.loc[[_class]]
            .dropna(axis=1, how="all")
            .sort_index(axis=1)
        )
        subframe = dframe.loc[[_class]].dropna(axis=1, how="all").sort_index(axis=1)
        roundtrip_subframe.set_index(
            list(
                {"CLASS", "LABEL", "OBS", "SEGMENT"}.intersection(
                    set(roundtrip_subframe.columns)
                )
            ),
            inplace=True,
        )
        roundtrip_subframe.sort_index(inplace=True)
        subframe.set_index(
            list(
                {"CLASS", "LABEL", "OBS", "SEGMENT"}.intersection(set(subframe.columns))
            ),
            inplace=True,
        )
        subframe.sort_index(inplace=True)
        # Comments are not preservable through ertobs roundtrips:
        subframe.drop(
            ["COMMENT", "SUBCOMMENT"], axis="columns", errors="ignore", inplace=True
        )
        if _class == "BLOCK_OBSERVATION":
            if "WELL" in subframe:
                # WELL as used in yaml is not preservable in roundtrips
                del subframe["WELL"]
        # print(roundtrip_subframe)
        # print(subframe)

        pd.testing.assert_frame_equal(
            roundtrip_subframe.sort_index(),
            subframe.sort_index(),
            check_dtype=False,
        )
示例#6
0
def test_autoparse_file(filename, expected_format, readonly_testdata_dir):
    """Test that the included observation file formats in the test suite
    are correctly recognized"""
    assert autoparse_file(filename)[0] == expected_format
示例#7
0
def test_autoparse_file(filename, expected_format):
    """Test that the included observation file formats in the test suite
    are correctly recognized"""
    testdata_dir = os.path.join(os.path.dirname(__file__), "testdata_fmuobs")
    os.chdir(testdata_dir)
    assert autoparse_file(filename)[0] == expected_format