Skip to content

Commit

Permalink
Port from sunbeam to opm.io
Browse files Browse the repository at this point in the history
Add more code to common for the interface
to opm.io.

Workaround missing UDAvalue support in opm-common for wcon

Add ad-hoc parser just for WCON* keywords (parsing the record as
a string)

Use libecl from pypi
  • Loading branch information
berland committed Feb 21, 2020
1 parent a54f9ff commit 94658cf
Show file tree
Hide file tree
Showing 31 changed files with 737 additions and 386 deletions.
37 changes: 7 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
dist: trusty
dist: bionic

compiler:
- gcc
Expand All @@ -17,9 +17,7 @@ addons:
- boost-latest
- ubuntu-toolchain-r-test
packages:
- gcc-4.9
- g++-4.9
- libboost1.55-all-dev
- libboost-all-dev
- liblapack-dev

sudo: required
Expand All @@ -32,44 +30,23 @@ matrix:
fast_finish: true

before_install:
- export CXX="g++-4.9" CC="gcc-4.9"
- export PYTHONPATH=$INSTALL_ROOT/lib/python$TRAVIS_PYTHON_VERSION/dist-packages:$PYTHONPATH
- export PYTHONPATH=$INSTALL_ROOT/lib/python$TRAVIS_PYTHON_VERSION/site-packages:$INSTALL_ROOT/lib/python$TRAVIS_PYTHON_VERSION/dist-packages:$PYTHONPATH


install:
- pushd ..
- git clone https://github.com/equinor/libecl.git
- git clone --recursive https://github.com/OPM/opm-common.git
- git clone --recursive https://github.com/equinor/sunbeam.git
- pushd libecl
- pip install -r requirements.txt
- popd
- mkdir libecl/build
- pushd libecl/build
- cmake .. -DENABLE_PYTHON=ON
-DBUILD_TESTS=OFF
-DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT ..
- make -j4 install
- popd
- mkdir opm-common/build
- pushd opm-common/build
- git checkout release/sunbeam/2019.02
- cmake .. -DCMAKE_PREFIX_PATH=$INSTALL_ROOT
-DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT
-DBUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=ON
-DOPM_ENABLE_PYTHON=ON
-DOPM_INSTALL_PYTHON=ON
- make -j4 install
- popd
- mkdir sunbeam/build
- pushd sunbeam/build
- cmake .. -DCMAKE_PREFIX_PATH=$INSTALL_ROOT
-DUSE_RPATH=ON
-DCMAKE_INSTALL_PREFIX=$INSTALL_ROOT
-DPYTHON_EXECUTABLE=`which python`
- make -j 4 install
- popd
- popd
- pip install -r requirements.txt
- popd # back to opm-common
- popd # back to ecl2df
- pip install -r requirements_dev.txt
- pip install .

Expand Down
105 changes: 105 additions & 0 deletions ecl2df/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,34 @@
from __future__ import absolute_import
from __future__ import division

import os
import json
import logging
import datetime

import pandas as pd

# Parse named JSON files, this exposes a dict of dictionary describing the contents
# of supported Eclipse keyword data
OPMKEYWORDS = {}
for keyw in [
"COMPDAT",
"COMPSEGS",
"EQUIL",
"FAULTS",
"WELSPECS",
"WELSEGS",
"WCONPROD",
"WCONHIST",
"WCONINJE",
"WCONINJH",
"GRUPTREE",
"GRUPNET",
]:
OPMKEYWORDS[keyw] = json.load(
open(os.path.join(os.path.dirname(__file__), "opmkeywords", keyw))
)


logging.basicConfig()
logger = logging.getLogger(__name__)
Expand All @@ -33,6 +58,86 @@ def parse_ecl_month(eclmonth):
return eclmonth2num[eclmonth]


def parse_opmio_deckrecord(
record, keyword, itemlistname="items", recordindex=None, renamer=None
):
"""
Parse an opm.io.DeckRecord belonging to a certain keyword
Args:
record (opm.libopmcommon_python.DeckRecord): Record be parsed
keyword (string): Which Eclipse keyword this belongs to
itemlistname (string): The key in the json dict that describes the items,
typically 'items' or 'records'
recordindex (int): For keywords where itemlistname is 'records', this is a
list index to the "record"
Beware, there are multiple concepts here for what we call a record.
renamer (dict): If supplied, this dictionary will be used to remap
the keys in returned dict
Returns:
dict
"""
if keyword not in OPMKEYWORDS:
logging.error("Keyword %s not supported by common.py", str(keyword))

# opm.io deckitem access functions, depending on value_type in json data for item:
deckitem_fn = {
"STRING": "get_str",
"INT": "get_int",
"DOUBLE": "get_raw",
"UDA": "get_raw", # Does not work. Is UDA unsupported in opm.io??
}
rec_dict = {}

if recordindex is None: # Beware, 0 is different from None here.
itemlist = OPMKEYWORDS[keyword][itemlistname]
else:
itemlist = OPMKEYWORDS[keyword][itemlistname][recordindex]

for item_idx, jsonitem in enumerate(itemlist):
item_name = jsonitem["name"]
if not record[item_idx].defaulted(0):
rec_dict[item_name] = getattr(
record[item_idx], deckitem_fn[jsonitem["value_type"]]
)(0)
else:
if "default" in jsonitem:
rec_dict[item_name] = jsonitem["default"]
else:
rec_dict[item_name] = None
if renamer:
renamed_dict = {}
for key in rec_dict:
if key in renamer:
renamed_dict[renamer[key]] = rec_dict[key]
else:
renamed_dict[key] = rec_dict[key]
return renamed_dict
return rec_dict


def parse_opmio_date_rec(record):
"""
Parse a opm.io.DeckRecord under a DATES or START keyword in a deck.
Return:
datetime.date
"""
day = record[0].get_int(0)
month = record[1].get_str(0)
year = record[2].get_int(0)
return datetime.date(year=year, month=parse_ecl_month(month), day=day)


def parse_opmio_tstep_rec(record):
"""Parse a record with TSTEP data
Return:
list of floats or ints
"""
return record[0].get_raw_data_list()


def merge_zones(df, zonedict, zoneheader="ZONE", kname="K1"):
"""Merge in a column with zone names, from a dictionary mapping
k-index to zone name
Expand Down
Loading

0 comments on commit 94658cf

Please sign in to comment.