Exemple #1
0
def test_gridgeometry2df(mocker):
    """Test that dataframes are produced"""
    eclfiles = EclFiles(REEK)
    grid_geom = grid.gridgeometry2df(eclfiles)

    assert isinstance(grid_geom, pd.DataFrame)
    assert not grid_geom.empty

    assert "I" in grid_geom
    assert "J" in grid_geom
    assert "K" in grid_geom
    assert "X" in grid_geom
    assert "Y" in grid_geom
    assert "Z" in grid_geom
    assert "Z_MIN" in grid_geom
    assert "Z_MAX" in grid_geom
    assert "VOLUME" in grid_geom
    assert "ZONE" in grid_geom
    assert "GLOBAL_INDEX" in grid_geom

    # If at least one inactive cell, this will hold:
    assert grid_geom["GLOBAL_INDEX"].max() > len(grid_geom)

    assert (grid_geom["Z_MAX"] > grid_geom["Z_MIN"]).all()

    with pytest.raises(TypeError, match="missing 1 required positional"):
        grid.gridgeometry2df()

    with pytest.raises(AttributeError):
        # This error situation we don't really try to handle.
        grid.gridgeometry2df(None)

    with pytest.raises(ValueError, match="No EGRID file supplied"):
        mocker.patch("ecl2df.eclfiles.EclFiles.get_egridfile", return_value=None)
        grid.gridgeometry2df(eclfiles)
Exemple #2
0
def test_gridzonemap():
    """Check that zonemap can be merged automatically be default, and also
    that there is some API for supplying the zonemap directly as a dictionary"""
    eclfiles = EclFiles(DATAFILE)
    grid_geom = grid.gridgeometry2df(eclfiles, zonemap=None)

    default_zonemap = grid_geom["ZONE"]

    grid_no_zone = grid.gridgeometry2df(eclfiles, zonemap={})
    assert "ZONE" not in grid_no_zone

    assert (grid.df(eclfiles, zonemap=None)["ZONE"] == default_zonemap).all()

    df_no_zone = grid.df(eclfiles, zonemap={})
    assert "ZONE" not in df_no_zone

    df_custom_zone = grid.gridgeometry2df(eclfiles, zonemap={1: "FIRSTLAYER"})
    assert "ZONE" in df_custom_zone
    assert set(
        df_custom_zone[df_custom_zone["K"] == 1]["ZONE"].unique()) == set(
            ["FIRSTLAYER"])
    assert len(df_custom_zone) == len(grid_no_zone)

    df_bogus_zones = grid.gridgeometry2df(eclfiles,
                                          zonemap={999999: "nonexistinglayer"})
    assert pd.isnull(df_bogus_zones["ZONE"]).all()

    # Test a custom "subzone" map via direct usage of merge_zone on an dataframe
    # where ZONE already exists:

    dframe = grid.df(eclfiles)
    subzonemap = {1: "SUBZONE1", 2: "SUBZONE2"}
    dframe = common.merge_zones(dframe,
                                subzonemap,
                                zoneheader="SUBZONE",
                                kname="K")
    assert (dframe["ZONE"] == default_zonemap).all()
    assert set(dframe[dframe["K"] == 1]["SUBZONE"].unique()) == set(
        ["SUBZONE1"])
    assert set(dframe[dframe["K"] == 2]["SUBZONE"].unique()) == set(
        ["SUBZONE2"])
    assert len(dframe) == len(grid_no_zone)
Exemple #3
0
def test_mergegridframes():
    """Test that we can merge together data for the grid"""
    eclfiles = EclFiles(DATAFILE)
    init_df = grid.init2df(eclfiles)
    grid_geom = grid.gridgeometry2df(eclfiles)

    assert len(init_df) == len(grid_geom)

    merged = grid.merge_gridframes(grid_geom, init_df, pd.DataFrame())
    assert isinstance(merged, pd.DataFrame)
    assert len(merged) == len(grid_geom)

    # Check that PORV is sensible
    assert (abs(sum(merged["PORO"] * merged["VOLUME"] - merged["PORV"])) /
            sum(merged["PORV"]) < 0.00001)
Exemple #4
0
def test_gridgeometry2df():
    """Test that dataframes are produced"""
    eclfiles = EclFiles(DATAFILE)
    grid_geom = grid.gridgeometry2df(eclfiles)

    assert isinstance(grid_geom, pd.DataFrame)
    assert not grid_geom.empty

    assert "I" in grid_geom
    assert "J" in grid_geom
    assert "K" in grid_geom
    assert "X" in grid_geom
    assert "Y" in grid_geom
    assert "Z" in grid_geom
    assert "VOLUME" in grid_geom
    assert "ZONE" in grid_geom
Exemple #5
0
def test_gridgeometry2df():
    """Test that dataframes are produced"""
    eclfiles = EclFiles(DATAFILE)
    grid_geom = grid.gridgeometry2df(eclfiles)

    assert isinstance(grid_geom, pd.DataFrame)
    assert not grid_geom.empty

    assert "I" in grid_geom
    assert "J" in grid_geom
    assert "K" in grid_geom
    assert "X" in grid_geom
    assert "Y" in grid_geom
    assert "Z" in grid_geom
    assert "VOLUME" in grid_geom
    assert "ZONE" in grid_geom
    assert "GLOBAL_INDEX" in grid_geom

    # If at least one inactive cell, this will hold:
    assert grid_geom["GLOBAL_INDEX"].max() > len(grid_geom)
Exemple #6
0
def add_nnc_coords(nncdf, eclfiles):
    """Add columns X, Y and Z for the connection midpoint

    This extracts x, y and z for (I1, J1, K1) and (I2, J2, K2)
    and computes the average in each direction.

    Arguments:
        nncdf (DataFrame): With grid index columns (I1, J1, K1, I2, J2, K2)
        eclfiles (EclFiles): Object used to fetch grid data from EGRID.

    Returns:
        DataFrame: Incoming dataframe augmented with the columns X, Y and Z.
    """
    gridgeometry = grid.gridgeometry2df(eclfiles)
    gnncdf = pd.merge(
        nncdf,
        gridgeometry,
        how="left",
        left_on=["I1", "J1", "K1"],
        right_on=["I", "J", "K"],
    )
    gnncdf = pd.merge(
        gnncdf,
        gridgeometry,
        how="left",
        left_on=["I2", "J2", "K2"],
        right_on=["I", "J", "K"],
        suffixes=("", "_2"),
    )
    # Use pd.DataFrame.mean for averaging, since it can ignore
    # NaN's. In case only one coordinate is NaN, we then get the other one.
    # (NaN coordinates are potentially from zero-volume cells?)
    gnncdf["X"] = gnncdf[["X", "X_2"]].mean(axis=1)
    gnncdf["Y"] = gnncdf[["Y", "Y_2"]].mean(axis=1)
    gnncdf["Z"] = gnncdf[["Z", "Z_2"]].mean(axis=1)

    # Let go of the temporary columns we have in gnncdf
    return gnncdf[list(nncdf.columns) + ["X", "Y", "Z"]]