How to use the ecl2df.EclFiles.str2deck function in ecl2df

To help you get started, we’ve selected a few ecl2df examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github equinor / ecl2df / tests / test_compdat.py View on Github external
-- comments.
/
"""
    deck = EclFiles.str2deck(schstr)
    compdfs = compdat.deck2dfs(deck)
    compdat_df = compdfs["COMPDAT"]
    assert compdat_df.loc[0, "SATN"] == 0
    assert not compdat_df.loc[0, "DFACT"]
    assert compdat_df.loc[0, "DIR"] == "Y"

    schstr = """
COMPDAT
 'FOO' 303 1010 031 39  /
/
"""
    compdat_df = compdat.deck2dfs(EclFiles.str2deck(schstr))["COMPDAT"]
    assert len(compdat_df) == 9
    assert not compdat_df["DFACT"].values[0]
    assert not compdat_df["TRAN"].values[0]
    assert compdat_df["I"].values[0] == 303
github equinor / ecl2df / tests / test_compdat.py View on Github external
def test_str_compdat():
    """Test compdat parsing directly on strings"""
    schstr = """
COMPDAT
 'OP1' 33 110 31 31 'OPEN' 1* 6467.31299 0.216 506642.25  0 1* 'Y' 7.18 /
-- comments.
/
"""
    deck = EclFiles.str2deck(schstr)
    compdfs = compdat.deck2dfs(deck)
    compdat_df = compdfs["COMPDAT"]
    assert compdat_df.loc[0, "SATN"] == 0
    assert not compdat_df.loc[0, "DFACT"]
    assert compdat_df.loc[0, "DIR"] == "Y"

    schstr = """
COMPDAT
 'FOO' 303 1010 031 39  /
/
"""
    compdat_df = compdat.deck2dfs(EclFiles.str2deck(schstr))["COMPDAT"]
    assert len(compdat_df) == 9
    assert not compdat_df["DFACT"].values[0]
    assert not compdat_df["TRAN"].values[0]
    assert compdat_df["I"].values[0] == 303
github equinor / ecl2df / tests / test_compdat.py View on Github external
def test_unrollwelsegs():
    """Test unrolling of welsegs."""
    schstr = """
WELSEGS
  -- seg_start to seg_end (two first items in second record) is a range of
  -- 2 segments, should be automatically unrolled to 2 rows.
  'OP1' 1689 1923 1.0E-5 'ABS' 'HFA' 'HO' / comment without -- identifier
   2 3 1 1 1923.9 1689.000 0.1172 0.000015  /
/
"""
    df = compdat.deck2dfs(EclFiles.str2deck(schstr))["WELSEGS"]
    assert len(df) == 2

    df = compdat.deck2dfs(EclFiles.str2deck(schstr), unroll=False)["WELSEGS"]
    assert len(df) == 1
github equinor / ecl2df / tests / test_compdat.py View on Github external
'OP1' 1689 1923 1.0E-5 'ABS' 'HFA' 'HO' / comment without -- identifier
-- foo bar
   2 2 1 1 1923.9 1689.000 0.1172 0.000015  /
/

COMPSEGS
  'OP1' / -- Yet a comment
  -- comment
  41 125 29  5 2577.0 2616.298 / icd on branch 1 in segment 17
/
-- (WSEGVALS is not processed)
WSEGVALV
  'OP1'   166   1   7.4294683E-06  0 / icd on segment 17, cell 41 125 29
/
"""
    deck = EclFiles.str2deck(schstr)
    compdfs = compdat.deck2dfs(deck)
    compdat_df = compdfs["COMPDAT"]
    welsegs = compdfs["WELSEGS"]
    compsegs = compdfs["COMPSEGS"]
    assert "WELL" in compdat_df
    assert len(compdat_df) == 1
    assert compdat_df["WELL"].unique()[0] == "OP1"

    # Check that we have not used the very long opm.io term here:
    assert "CONNECTION_TRANSMISSIBILITY_FACTOR" not in compdat_df
    assert "TRAN" in compdat_df

    assert "Kh" not in compdat_df  # Mixed-case should not be used.
    assert "KH" in compdat_df

    # Make sure the ' are ignored:
github equinor / ecl2df / tests / test_compdat.py View on Github external
TSTEP
  1 /

COMPDAT
 'OP1' 34 111 32 32 'OPEN' /
/

TSTEP
  2 3 /

COMPDAT
  'OP1' 35 111 33 33 'SHUT' /
/
"""
    deck = EclFiles.str2deck(schstr)
    compdf = compdat.deck2dfs(deck)["COMPDAT"]
    dates = [str(x) for x in compdf["DATE"].unique()]
    assert len(dates) == 3
    assert "2001-05-01" in dates
    assert "2001-05-02" in dates
    assert "2001-05-07" in dates
github equinor / ecl2df / ecl2df / inferdims.py View on Github external
deck (str or opm.io deck): A data deck. If ntxxx_name is to be
            estimated this *must* be a string and not a fully parsed deck.
        npxxx_value (int): Supply this if ntxxx_name is known, but not present in the
            deck, this will override any guessing. If the deck already
            contains XXXDIMS, this will be ignored.

    Returns:
        opm.io Deck object
    """
    assert xxxdims in ["TABDIMS", "EQLDIMS"]
    assert ntxxx_name in ["NTPVT", "NTEQUL", "NTSFUN"]

    if xxxdims in deck and ntxxx_value is None:
        # Then we have nothing to do, but ensure we parse a potential string to a deck
        if isinstance(deck, six.string_types):
            deck = EclFiles.str2deck(deck)
        return deck

    if xxxdims in deck and ntxxx_value is not None:
        logger.warning(
            "Ignoring %s argument, it is already in the deck", str(ntxxx_name)
        )
        return deck

    if not isinstance(deck, six.string_types):
        # The deck must be converted to a string deck in order
        # to estimate dimensions.
        deck = str(deck)

    # Estimate if ntxxx_value is not provided:
    if ntxxx_value is None:
        ntxxx_estimate = guess_dim(deck, xxxdims, DIMS_POS[ntxxx_name])
github equinor / ecl2df / ecl2df / inferdims.py View on Github external
("PARSE_UNKNOWN_KEYWORD", opm.io.action.ignore),
        ("SUMMARY_UNKNOWN_GROUP", opm.io.action.ignore),
        ("UNSUPPORTED_*", opm.io.action.ignore),
        ("PARSE_MISSING_SECTIONS", opm.io.action.ignore),
        ("PARSE_RANDOM_TEXT", opm.io.action.ignore),
        ("PARSE_MISSING_INCLUDE", opm.io.action.ignore),
    ]

    max_guess = 640  # This ought to be enough for everybody
    dimcountguess = 0
    for dimcountguess in range(1, max_guess + 1):
        deck_candidate = inject_dimcount(
            deckstring, dimkeyword, dimitem, dimcountguess, nowarn=True
        )
        try:
            EclFiles.str2deck(
                deck_candidate,
                parsecontext=opm.io.ParseContext(
                    opmioparser_recovery_fail_extra_records
                ),
            )
            # If we succeed, then the dimcountguess was correct
            break
        except ValueError:
            # Typically we get the error PARSE_EXTRA_RECORDS because we did not guess
            # high enough dimnumcount
            continue
            # If we get here, try another dimnumcount
    if dimcountguess == max_guess:
        logger.warning(
            "Unable to guess dim count for %s, or larger than %d", dimkeyword, max_guess
        )
github equinor / ecl2df / ecl2df / inferdims.py View on Github external
# Estimate if ntxxx_value is not provided:
    if ntxxx_value is None:
        ntxxx_estimate = guess_dim(deck, xxxdims, DIMS_POS[ntxxx_name])
        logger.warning("Estimated %s=%s", ntxxx_name, str(ntxxx_estimate))
    else:
        ntxxx_estimate = ntxxx_value

    augmented_strdeck = inject_dimcount(
        str(deck), xxxdims, DIMS_POS[ntxxx_name], ntxxx_estimate, nowarn=True
    )
    # Overwrite the deck object
    deck = EclFiles.str2deck(augmented_strdeck)

    if isinstance(deck, six.string_types):
        # If a string is supplied as a deck, we always return a parsed Deck object
        deck = EclFiles.str2deck(deck)

    return deck
github equinor / ecl2df / ecl2df / inferdims.py View on Github external
# The deck must be converted to a string deck in order
        # to estimate dimensions.
        deck = str(deck)

    # Estimate if ntxxx_value is not provided:
    if ntxxx_value is None:
        ntxxx_estimate = guess_dim(deck, xxxdims, DIMS_POS[ntxxx_name])
        logger.warning("Estimated %s=%s", ntxxx_name, str(ntxxx_estimate))
    else:
        ntxxx_estimate = ntxxx_value

    augmented_strdeck = inject_dimcount(
        str(deck), xxxdims, DIMS_POS[ntxxx_name], ntxxx_estimate, nowarn=True
    )
    # Overwrite the deck object
    deck = EclFiles.str2deck(augmented_strdeck)

    if isinstance(deck, six.string_types):
        # If a string is supplied as a deck, we always return a parsed Deck object
        deck = EclFiles.str2deck(deck)

    return deck