Skip to content

Commit

Permalink
Fix erroneous PVTG support in ecl2df.pvt (#251)
Browse files Browse the repository at this point in the history
Apparently forgotten initially. Uncovered by codecov.io

Added tests for non-covered code lines.
  • Loading branch information
berland authored Jan 22, 2021
1 parent 5213f4e commit 7b6f005
Show file tree
Hide file tree
Showing 3 changed files with 278 additions and 46 deletions.
49 changes: 39 additions & 10 deletions ecl2df/pvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,35 +418,64 @@ def df2ecl_pvtw(dframe, comment=None):


def df2ecl_pvtg(dframe, comment=None):
"""Print DENSITY keyword with data
DENSITY is one line (one record) of data pr. PVTNUM
"""Print PVTG keyword with data
Args:
dframe (pd.DataFrame): Containing PVTG data
comment (str): Text that will be included as a comment
"""
if dframe.empty:
return "-- No data!"
string = "DENSITY\n"
string = "PVTG\n"
string += common.comment_formatter(comment)
string += "-- {:^21} {:^21} {:^21} \n".format(
"OILDENSITY", "WATERDENSITY", "GASDENSITY"
string += "-- {:^22} {:^22} {:^22} {:^22}\n".format(
"PRESSURE", "OGR", "VOLUMEFACTOR", "VISCOSITY"
)
string += "-- {:^22} {:^22} {:^22} {:^22}\n".format(
"*", "OGR", "VOLUMEFACTOR", "VISCOSITY"
)
if "KEYWORD" not in dframe:
# Use everything..
subset = dframe
else:
subset = dframe[dframe["KEYWORD"] == "DENSITY"]
subset = dframe[dframe["KEYWORD"] == "PVTG"]
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()))
string += "{GASDENSITY:20.7f} /\n".format(**(row.to_dict()))

def _pvtg_pvtnum(dframe):
"""Print PVTG-data for a specific PVTNUM"""
string = ""
dframe = dframe.set_index("PRESSURE").sort_index()
for pg in dframe.index.unique():
string += _pvtg_pvtnum_pg(dframe[dframe.index == pg])
return string + "/\n"

def _pvtg_pvtnum_pg(dframe):
"""Print PVTG-data for a particular gas phase pressure"""
string = ""
assert len(dframe.index.unique()) == 1
pg = dframe.index.values[0]
string += "{:20.7f} ".format(pg)
for rowidx, row in dframe.reset_index().iterrows():
if rowidx > 0:
indent = "\n" + " " * 22
else:
indent = ""
string += (
indent
+ "{OGR:20.7f} {VOLUMEFACTOR:20.7f} {VISCOSITY:20.7f}".format(
**(row.to_dict())
)
)
string += " /\n-- End PRESSURE={}\n".format(pg)
return string

for pvtnum in subset.index.unique():
string += _pvtg_pvtnum(subset[subset.index == pvtnum])
return string + "\n"


Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from os import path

from setuptools import setup, find_packages
Expand Down
Loading

0 comments on commit 7b6f005

Please sign in to comment.