How to use the ecl2df.common.comment_formatter 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 / ecl2df / nnc.py View on Github external
Returns:
        string with the EDITNNC keyword.
    """

    string = ""
    ecl2df_header = (
        "Output file printed by ecl2df.nnc"
        + " "
        + __version__
        + "\n"
        + " at "
        + str(datetime.datetime.now())
    )
    if not nocomments:
        string += common.comment_formatter(ecl2df_header)
    string += "\n"

    if "DIR" in nnc_df:
        nnc_df = nnc_df[nnc_df["DIR"] == "NNC"]

    if "TRANM" not in nnc_df:
        raise ValueError("TRANM not supplied in nnc_df")
    string += "EDITNNC" + os.linesep
    table_str = nnc_df[["I1", "J1", "K1", "I2", "J2", "K2", "TRANM"]].to_string(
        header=True, index=False
    )
    lines = table_str.rstrip().split(os.linesep)
    indent = "   "
    string += "-- " + lines[0] + os.linesep
    string += os.linesep.join([indent + line + " /" for line in lines[1:]])
    string += os.linesep
github equinor / ecl2df / ecl2df / nnc.py View on Github external
if "TRANM" not in nnc_df:
        raise ValueError("TRANM not supplied in nnc_df")
    string += "EDITNNC" + os.linesep
    table_str = nnc_df[["I1", "J1", "K1", "I2", "J2", "K2", "TRANM"]].to_string(
        header=True, index=False
    )
    lines = table_str.rstrip().split(os.linesep)
    indent = "   "
    string += "-- " + lines[0] + os.linesep
    string += os.linesep.join([indent + line + " /" for line in lines[1:]])
    string += os.linesep
    string += "/"
    if not nocomments:
        string += " "
        string += common.comment_formatter(
            "  {} nnc connections, avg multiplier {}".format(
                len(nnc_df), nnc_df["TRANM"].mean()
            )
        )
    string += "\n\n"

    if filename is not None:
        # Make directory if not present:
        filenamedir = os.path.dirname(filename)
        if filenamedir and not os.path.exists(filenamedir):
            os.makedirs(filenamedir)
        with open(filename, "w") as file_handle:
            file_handle.write(string)

    return string
github equinor / ecl2df / ecl2df / pvt.py View on Github external
def df2ecl_pvdg(dframe, comment=None):
    """Print PVDG keyword with data

    This data consists of one table (volumefactor and visosity
    as a function of pressure) pr. PVTNUM.

    Args:
        dframe (pd.DataFrame): Containing PVDG data
        comment (str): Text that will be included as a comment
    """
    if dframe.empty:
        return "-- No data!"
    string = "PVDG\n"
    string += common.comment_formatter(comment)
    string += "--   {:^21} {:^21} {:^21}  \n".format(
        "PRESSURE", "VOLUMEFACTOR", "VISCOSITY"
    )
    if "KEYWORD" not in dframe:
        # Use everything..
        subset = dframe
    else:
        subset = dframe[dframe["KEYWORD"] == "PVDG"]
    if "PVTNUM" not in subset:
        subset["PVTNUM"] = 1

    def _pvdg_pvtnum(dframe):
        """Print PVDG-data for a specific PVTNUM

        Args:
            dframe (pd.DataFrame): Cropped to only contain the relevant data.
github equinor / ecl2df / ecl2df / pvt.py View on Github external
def df2ecl_density(dframe, comment=None):
    """Print DENSITY keyword with data

    Args:
        dframe (pd.DataFrame): Containing DENSITY data
        comment (str): Text that will be included as a comment
    """
    if dframe.empty:
        return "-- No data!"
    string = "DENSITY\n"
    string += common.comment_formatter(comment)
    string += "--   {:^21} {:^21} {:^21}  \n".format(
        "OILDENSITY", "WATERDENSITY", "GASDENSITY"
    )
    if "KEYWORD" not in dframe:
        # Use everything..
        subset = dframe
    else:
        subset = dframe[dframe["KEYWORD"] == "DENSITY"]
    if "PVTNUM" not in subset:
        if len(subset) != 1:
            logger.critical("If PVTNUM is not supplied, only one row should be given")
            return ""
        subset["PVTNUM"] = 1
    subset = subset.set_index("PVTNUM").sort_index()
    for _, row in subset.iterrows():
        string += "  {OILDENSITY:20.7f} {WATERDENSITY:20.7f}".format(**(row.to_dict()))
github equinor / ecl2df / ecl2df / pvt.py View on Github external
def df2ecl_pvtw(dframe, comment=None):
    """Print PVTW keyword with data

    PVTW is one line/record with data for a reference pressure
    for each PVTNUM.

    Args:
        dframe (pd.DataFrame): Containing PVTW data
        comment (str): Text that will be included as a comment
    """
    if dframe.empty:
        return "-- No data!"
    string = "PVTW\n"
    string += common.comment_formatter(comment)
    string += "--   {:^21} {:^21} {:^21} {:^21} {:^21}  \n".format(
        "PRESSURE", "VOLUMEFACTOR", "COMPRESSIBILITY", "VISCOSITY", "VISCOSIBILITY"
    )
    if "KEYWORD" not in dframe:
        # Use everything..
        subset = dframe
    else:
        subset = dframe[dframe["KEYWORD"] == "PVTW"]
    if "PVTNUM" not in subset:
        if len(subset) != 1:
            logger.critical("If PVTNUM is not supplied, only one row should be given")
            return ""
        subset["PVTNUM"] = 1
    subset = subset.set_index("PVTNUM").sort_index()
    for _, row in subset.iterrows():
        string += "  {PRESSURE:20.7f} {VOLUMEFACTOR:20.7f} ".format(**(row.to_dict()))