Esempio n. 1
0
def blockdictlist2df(blocklist: List[dict]) -> pd.DataFrame:
    """Parse a list structure (subpart of yaml syntax) of block observations
    into  dataframe format

    The internal dataframe format uses "LABEL" and "OBS" as unique keys
    for individual observations. These are constructed if not present.

    Args:
        blocklist (list): List of dictionaries with block/rft observations

    Returns:
        pd.DataFrame
    """
    rows = []
    # "well" is a required field in yaml syntax, but is
    # not required in ert observation. But in ERT observation
    # syntax and internal dataframe format, a label is mandatory, but not in
    # YAML. A label is made up from well-name and index of observation for the
    # well.
    for keylist in blocklist:
        if "observations" not in keylist:
            logger.warning("Missing 'observations' in rft observation")
            continue
        for obs_idx, obs in enumerate(keylist["observations"]):
            rowdict = {"CLASS": "BLOCK_OBSERVATION"}
            rowdict.update(uppercase_dictkeys(keylist))
            if "OBSERVATIONS" in rowdict:
                del rowdict["OBSERVATIONS"]
            if "label" not in obs:
                rowdict["LABEL"] = keylist["well"]
            if "obs" not in obs:
                # Make up a label for the particular 3D-point for the
                # observation, using P1, P2, etc. as in the ERT doc example.
                rowdict["OBS"] = "P" + str(obs_idx + 1)
            if "comment" in obs:
                # Comments can be present at two level in yaml format, the
                # lower level (pr. individual obs indices) are stored in
                # SUBCOMMENT
                rowdict["SUBCOMMENT"] = obs["comment"]
                del obs["comment"]
            rowdict.update(uppercase_dictkeys(obs))
            rows.append(rowdict)
    dframe = pd.DataFrame(rows)
    if "DATE" in dframe:
        dframe["DATE"] = pd.to_datetime(dframe["DATE"])
    return dframe
Esempio n. 2
0
def smrydictlist2df(smrylist: List[dict]) -> pd.DataFrame:
    """Parse a list structure (subpart of yaml syntax) of summary observations
    into  dataframe format

    Args:
        blocklist (list): List of dictionaries with summary observations

    Returns:
        pd.DataFrame
    """
    rows = []
    for keylist in smrylist:
        if "observations" not in keylist:
            logger.warning(
                "Missing 'observations' list in summary observation")
            continue
        for obs_idx, obs in enumerate(keylist["observations"]):
            rowdict = {"CLASS": "SUMMARY_OBSERVATION", "KEY": keylist["key"]}
            if "comment" in keylist:
                rowdict["COMMENT"] = keylist["comment"]
            # "comment" may be present at two levels in the dictionary, valid
            # for the whole observation, or for individual dated observations.
            # The latter is put into the column "SUBCOMMENT"
            if "comment" in obs:
                obs["subcomment"] = obs["comment"]
                del obs["comment"]
            rowdict.update(uppercase_dictkeys(obs))
            if "label" in keylist:
                logger.warning(
                    "label should be attached to dated observations, ignored label=%s",
                    keylist["label"],
                )
            if "label" not in obs:
                # We need to make up a unique label, indexed from 1 and upwards:
                rowdict["LABEL"] = keylist["key"] + "-" + str(obs_idx + 1)
            rows.append(rowdict)
    dframe = pd.DataFrame(rows)
    if "DATE" in dframe:
        dframe["DATE"] = pd.to_datetime(dframe["DATE"])
    return dframe