Skip to content

Commit

Permalink
Merge branch 'master' into fromfmuensemble
Browse files Browse the repository at this point in the history
  • Loading branch information
berland authored Nov 25, 2020
2 parents ad6ff25 + 74d32f6 commit 93270db
Show file tree
Hide file tree
Showing 30 changed files with 915 additions and 230 deletions.
19 changes: 8 additions & 11 deletions ecl2df/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Common functions for ecl2df modules
"""

import os
import sys
import json
import signal
import inspect
import logging
import datetime
import itertools
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -54,11 +54,12 @@
"WELOPEN",
"WELSEGS",
"WELSPECS",
"WSEGAICD",
"WSEGSICD",
]:
with open(
os.path.join(os.path.dirname(__file__), "opmkeywords", keyw), "r"
) as file_handle:
OPMKEYWORDS[keyw] = json.load(file_handle)
OPMKEYWORDS[keyw] = json.loads(
(Path(__file__).parent / "opmkeywords" / keyw).read_text()
)


logging.basicConfig()
Expand Down Expand Up @@ -524,12 +525,8 @@ def df2ecl(
string += function(dataframe)

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 f_handle:
f_handle.write(string)
Path(filename).parent.mkdir(parents=True, exist_ok=True)
Path(filename).write_text(string, encoding="utf-8")
return string


Expand Down
37 changes: 35 additions & 2 deletions ecl2df/compdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def deck2dfs(deck, start_date=None, unroll=True):
compsegsrecords = []
welopenrecords = []
welsegsrecords = []
wsegsicdrecords = []
wsegaicdrecords = []
welspecs = {}
date = start_date # DATE column will always be there, but can contain NaN/None
for idx, kword in enumerate(deck):
Expand Down Expand Up @@ -115,6 +117,18 @@ def deck2dfs(deck, start_date=None, unroll=True):
)
rec_data["J"] = welspecs[rec_data["WELL"]]["J"]
compdatrecords.append(rec_data)
elif kword.name == "WSEGSICD":
for rec in kword: # Loop over the lines inside WSEGSICD record
rec_data = parse_opmio_deckrecord(rec, "WSEGSICD")
rec_data["DATE"] = date
rec_data["KEYWORD_IDX"] = idx
wsegsicdrecords.append(rec_data)
elif kword.name == "WSEGAICD":
for rec in kword: # Loop over the lines inside WSEGAICD record
rec_data = parse_opmio_deckrecord(rec, "WSEGAICD")
rec_data["DATE"] = date
rec_data["KEYWORD_IDX"] = idx
wsegaicdrecords.append(rec_data)
elif kword.name == "COMPSEGS":
wellname = parse_opmio_deckrecord(
kword[0], "COMPSEGS", itemlistname="records", recordindex=0
Expand All @@ -139,7 +153,6 @@ def deck2dfs(deck, start_date=None, unroll=True):
"COMPDAT state. Using 'SHUT' instead." % rec_data["STATUS"]
)
welopenrecords.append(rec_data)

elif kword.name == "WELSEGS":
# First record contains meta-information for well
# (opm deck returns default values for unspecified items.)
Expand Down Expand Up @@ -173,14 +186,34 @@ def deck2dfs(deck, start_date=None, unroll=True):

compsegs_df = pd.DataFrame(compsegsrecords)
welsegs_df = pd.DataFrame(welsegsrecords)
wsegsicd_df = pd.DataFrame(wsegsicdrecords)
wsegaicd_df = pd.DataFrame(wsegaicdrecords)

if unroll and not welsegs_df.empty:
welsegs_df = unrolldf(welsegs_df, "SEGMENT1", "SEGMENT2")

if unroll and not wsegsicd_df.empty:
wsegsicd_df = unrolldf(wsegsicd_df, "SEGMENT1", "SEGMENT2")

if unroll and not wsegaicd_df.empty:
wsegaicd_df = unrolldf(wsegaicd_df, "SEGMENT1", "SEGMENT2")

if "KEYWORD_IDX" in compdat_df.columns:
compdat_df.drop(["KEYWORD_IDX"], axis=1, inplace=True)

return dict(COMPDAT=compdat_df, COMPSEGS=compsegs_df, WELSEGS=welsegs_df)
if "KEYWORD_IDX" in wsegsicd_df.columns:
wsegsicd_df.drop(["KEYWORD_IDX"], axis=1, inplace=True)

if "KEYWORD_IDX" in wsegaicd_df.columns:
wsegaicd_df.drop(["KEYWORD_IDX"], axis=1, inplace=True)

return dict(
COMPDAT=compdat_df,
COMPSEGS=compsegs_df,
WELSEGS=welsegs_df,
WSEGSICD=wsegsicd_df,
WSEGAICD=wsegaicd_df,
)


def postprocess():
Expand Down
25 changes: 13 additions & 12 deletions ecl2df/eclfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import errno
import logging
import shlex
from pathlib import Path

import opm.io

Expand Down Expand Up @@ -49,7 +50,7 @@ def __init__(self, eclbase):
eclbase = str(eclbase)

# Hint about possible wrong filenames:
if ".DATA" in eclbase and not os.path.exists(eclbase):
if ".DATA" in eclbase and not Path(eclbase).is_file():
logger.warning("File %s does not exist", eclbase)
# (this is not an error, because it is possible
# to obtain summary without the DATA file being present)
Expand All @@ -73,12 +74,12 @@ def __init__(self, eclbase):

def get_path(self):
"""Return the full path to the directory with the DATA file"""
return os.path.dirname(os.path.abspath(self._eclbase))
return Path(self._eclbase).absolute().parent

def get_ecldeck(self):
"""Return a opm.io deck of the DATA file"""
if not self._deck:
if os.path.exists(self._eclbase + ".DATA"):
if Path(self._eclbase + ".DATA").is_file():
deckfile = self._eclbase + ".DATA"
else:
deckfile = self._eclbase # Will be any filename
Expand Down Expand Up @@ -107,7 +108,7 @@ def get_egrid(self):
"""Find and return EGRID file as an EclGrid object"""
if not self._egrid:
egridfilename = self._eclbase + ".EGRID"
if not os.path.exists(egridfilename):
if not Path(egridfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), egridfilename
)
Expand All @@ -121,7 +122,7 @@ def get_egridfile(self):
This gives access to data vectors defined on the grid."""
if not self._egridfile:
egridfilename = self._eclbase + ".EGRID"
if not os.path.exists(egridfilename):
if not Path(egridfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), egridfilename
)
Expand All @@ -141,7 +142,7 @@ def get_eclsum(self, include_restart=True):
"""
if not self._eclsum:
smryfilename = self._eclbase + ".UNSMRY"
if not os.path.exists(smryfilename):
if not Path(smryfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), smryfilename
)
Expand All @@ -161,7 +162,7 @@ def get_initfile(self):
"""Find and return the INIT file as an EclFile object"""
if not self._initfile:
initfilename = self._eclbase + ".INIT"
if not os.path.exists(initfilename):
if not Path(initfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), initfilename
)
Expand All @@ -173,7 +174,7 @@ def get_rftfile(self):
"""Find and return the RFT file as an EclFile object"""
if not self._rftfile:
rftfilename = self._eclbase + ".RFT"
if not os.path.exists(rftfilename):
if not Path(rftfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), rftfilename
)
Expand All @@ -185,7 +186,7 @@ def get_rstfile(self):
"""Find and return the UNRST file as an EclFile object"""
if not self._rstfile:
rstfilename = self._eclbase + ".UNRST"
if not os.path.exists(rstfilename):
if not Path(rstfilename).is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), rstfilename
)
Expand Down Expand Up @@ -230,11 +231,11 @@ def get_zonemap(self, filename=None):
else:
filename_defaulted = False
assert isinstance(filename, str)
if not os.path.isabs(filename):
fullpath = os.path.join(self.get_path(), filename)
if not Path(filename).is_absolute():
fullpath = Path(self.get_path()) / filename
else:
fullpath = filename
if not os.path.exists(fullpath):
if not Path(fullpath).is_file():
if filename_defaulted:
# No warnings when the default filename is not there.
return {}
Expand Down
11 changes: 3 additions & 8 deletions ecl2df/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
the INIT file, and dynamic data can be merged from the Restart (UNRST)
file.
"""
import os
import logging
import fnmatch
import textwrap
import datetime
import dateutil.parser
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -644,13 +644,8 @@ def df2ecl(
string += "\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)

Path(filename).parent.mkdir(parents=True, exist_ok=True)
Path(filename).write_text(string, encoding="utf-8")
return string


Expand Down
10 changes: 3 additions & 7 deletions ecl2df/nnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import datetime
import pandas as pd
from pathlib import Path

from ecl2df import common, EclFiles, grid, __version__

Expand Down Expand Up @@ -265,13 +266,8 @@ def df2ecl_editnnc(nnc_df, filename=None, nocomments=False):
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)

Path(filename).parent.mkdir(parents=True, exist_ok=True)
Path(filename).write_text(string, encoding="utf-8")
return string


Expand Down
107 changes: 107 additions & 0 deletions ecl2df/opmkeywords/WSEGAICD
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"name": "WSEGAICD",
"sections": [
"SCHEDULE"
],
"items": [
{
"name": "WELL",
"value_type": "STRING"
},
{
"name": "SEGMENT1",
"value_type": "INT"
},
{
"name": "SEGMENT2",
"value_type": "INT"
},
{
"name": "STRENGTH",
"value_type": "DOUBLE"
},
{
"name": "LENGTH",
"value_type": "DOUBLE",
"default": 12.0
},
{
"name": "RHO_CAL",
"value_type": "DOUBLE",
"default": 1000.25
},
{
"name": "MU_CAL",
"value_type": "DOUBLE",
"default": 1.45
},
{
"name": "CRIT_WATFRAC",
"value_type": "DOUBLE"
},
{
"name": "WIDTH_WATFRAC",
"value_type": "DOUBLE"
},
{
"name": "MAX_RATIO",
"value_type": "DOUBLE",
"default": 5.0
},
{
"name": "SCALING",
"value_type": "INT",
"dimension": -1,
"default": 0
},
{
"name": "MAX_RATE",
"value_type": "DOUBLE"
},
{
"name": "VOLUME_RATE_EXP",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "VISCOSITY_EXP",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "FLAG",
"value_type": "STRING",
"default": "OPEN"
},
{
"name": "OIL_FRAC_EXP_DENS",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "WATER_FRAC_EXP_DENS",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "GAS_FRAC_EXP_DENS",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "OIL_FRAC_EXP_VISC",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "WATER_FRAC_EXP_VISC",
"value_type": "DOUBLE",
"default": 1.0
},
{
"name": "GAS_FRAC_EXP_VISC",
"value_type": "DOUBLE",
"default": 1.0
}
]
}
Loading

0 comments on commit 93270db

Please sign in to comment.