Ejemplo n.º 1
0
def df2ecl(
    satfunc_df: pd.DataFrame,
    keywords: Optional[List[str]] = None,
    comments: Optional[Dict[str, str]] = None,
    filename: Optional[str] = None,
) -> str:
    """Generate Eclipse include strings from dataframes with
    saturation functions (SWOF, SGOF, ...)

    Args:
        satfunc_df: Dataframe with data on ecl2df format.
        keywords: List of keywords to include. Must be
            supported and present in the incoming dataframe. Keywords
            are printed in the order defined by this list.
        comments: Dictionary indexed by keyword with comments to be
            included pr. keyword. If a key named "master" is present
            it will be used as a master comment for the outputted file.
        filename: If supplied, the generated text will also be dumped
            to file.

    Returns:
        Generated Eclipse include string

    """
    string = ""
    string += common.df2ecl(
        satfunc_df,
        keywords=keywords,
        comments=comments,
        supported=SUPPORTED_KEYWORDS,
        consecutive="SATNUM",
        filename=filename,
    )
    return string
Ejemplo n.º 2
0
def df2ecl(
    pvt_df: pd.DataFrame,
    keywords: Optional[Union[str, List[str]]] = None,
    comments: Optional[Dict[str, str]] = None,
    filename: Optional[str] = None,
) -> str:
    """Generate Eclipse include strings from PVT dataframes

    Args:
        pvt_df: Dataframe with PVT data on ecl2df format.
        keywords: List of keywords to include. Must be
            supported and present in the incoming dataframe.
        comments: Dictionary indexed by keyword with comments to be
            included pr. keyword. If a key named "master" is present
            it will be used as a master comment for the outputted file.
        filename: If supplied, the generated text will also be dumped
            to file.
    """
    return common.df2ecl(
        pvt_df,
        keywords,
        comments,
        supported=SUPPORTED_KEYWORDS,
        consecutive="PVTNUM",
        filename=filename,
    )
Ejemplo n.º 3
0
def df2ecl(equil_df, keywords=None, comments=None, withphases=False, filename=None):
    """Generate Eclipse include strings from dataframes with
    solution (EQUIL, RSVD++) data.

    Args:
        equil_df (pd.DataFrame): Dataframe with data on ecl2df format.
        keywords (list of str): List of keywords to include. Must be
            supported and present in the incoming dataframe.
        comments (dict): Dictionary indexed by keyword with comments to be
            included pr. keyword. If a key named "master" is present
            it will be used as a master comment for the outputted file.
        withphases (boolean): If True, the phase configuration keywords
            will be outputted. This is mostly for testing, and should
            not be necessary in production.
        filename (str): If supplied, the generated text will also be dumped
            to file.

    """
    string = ""
    if withphases:
        string += (
            phases_from_columns(equil_df.columns).upper().replace("-", "\n") + "\n\n"
        )
    string += common.df2ecl(
        equil_df,
        keywords=keywords,
        comments=comments,
        supported=SUPPORTED_KEYWORDS,
        consecutive="EQLNUM",
        filename=filename,
    )
    return string
Ejemplo n.º 4
0
def test_df2ecl():
    """Test general properties of df2ecl.

    This function is mainly tested in each submodule."""
    dframe = pd.DataFrame(
        [
            {
                "Z": 2469.0,
                "PRESSURE": 382.4,
                "OWC": 100.0,
                "PCOWC": 0.0,
                "GOC": 0.0,
                "EQLNUM": 1,
                "KEYWORD": "EQUIL",
            }
        ]
    )
    with pytest.raises(AssertionError):
        # supported keywords are not supplied
        common.df2ecl(dframe)
    with pytest.raises(AssertionError):
        common.df2ecl(dframe, supported=None)

    with pytest.raises(ValueError, match="KEYWORD must be in the dataframe"):
        common.df2ecl(
            dframe.drop("KEYWORD", axis=1), keywords=["EQUIL"], supported=["EQUIL"]
        )

    string = common.df2ecl(dframe, supported=["EQUIL"])
    # The next calls differ only in timestamp:
    assert len(string) == len(
        common.df2ecl(dframe, keywords="EQUIL", supported=["EQUIL"])
    )
    assert len(string) == len(
        common.df2ecl(dframe, keywords=["EQUIL"], supported=["EQUIL"])
    )
    assert "EQUIL\n" in string
    assert "2469" in string
    assert "-- Output file printed by tests.test_common" in string

    assert "" == common.df2ecl(dframe, supported=["PORO"])

    assert "EQUIL\n-- foobar" in common.df2ecl(
        dframe, comments={"EQUIL": "foobar"}, supported=["EQUIL"]
    )
    assert "\n\n-- masterfoobar\nEQUIL" in common.df2ecl(
        dframe, comments={"master": "masterfoobar"}, supported=["EQUIL"]
    )

    tworows = pd.concat([dframe, dframe])
    tworows["EQLNUM"] = [3, 1]
    tworows["PRESSURE"] = [3456, 1234]
    with pytest.raises(ValueError):
        common.df2ecl(tworows, supported=["EQUIL"], consecutive="EQLNUM")
    # This would be a bug if client code did this, because the wrong
    # consecutive column is set:
    assert "3456" in common.df2ecl(tworows, supported=["EQUIL"], consecutive="PVTNUM")
    tworows["EQLNUM"] = [1, 3]
    with pytest.raises(ValueError):
        common.df2ecl(tworows, supported=["EQUIL"], consecutive="EQLNUM")
    tworows["EQLNUM"] = [2, 1]
    # Passes because the frame is sorted on EQLNUM:
    string = common.df2ecl(tworows, supported=["EQUIL"], consecutive="EQLNUM")
    assert "EQUIL" in string
    assert string.find("3456") > string.find("1234")