Skip to content

Commit

Permalink
Replace ecl with resdata (#234)
Browse files Browse the repository at this point in the history
* Replace ecl with resdata

* Fix doc yaml block

* Lock setuptools_scm version

* Fix doc building

(cherry picked from commit 459ddb0)
  • Loading branch information
DanSava committed Nov 22, 2023
1 parent b767a96 commit 467edd6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/fmu-ensemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ jobs:
- name: Build docs
run: |
sphinx-apidoc -H "API for fmu.ensemble" -o ./docs ./src/fmu
python setup.py build_sphinx
mkdir tmp
sphinx-build -W -b html -d tmp/doctrees docs build/sphinx/html
touch build/sphinx/html/.nojekyll
- name: 🚢 Build and deploy Python package
Expand Down
16 changes: 8 additions & 8 deletions docs/advancedusage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ matching), use the YAML syntax:
# Mandatory elements per entry: key and observations
- key: WBP4:OP_1
# This is a global comment regarding this set of observations
comment: "Shut-in pressures converted from well head conditions"
observations:
# Mandatory elements per entry in ecl_vector observations: value, error, date
- {value: 251, error: 4, date: 2001-01-01}
- {value: 251, error: 10, date: 2002-01-01}
- {value: 251, error: 10, date: 2003-01-01,
comment: First measurement after sensor drift correction}
comment: "Shut-in pressures converted from well head conditions"
observations:
# Mandatory elements per entry in ecl_vector observations: value, error, date
- {value: 251, error: 4, date: 2001-01-01}
- {value: 251, error: 10, date: 2002-01-01}
- {value: 251, error: 10, date: 2003-01-01,
comment: First measurement after sensor drift correction}
Representative realizations
Expand Down Expand Up @@ -324,7 +324,7 @@ VirtualRealization object from an Ensemble object. If we want only the
aggregated table for our particular custom function, we can aggregate the
ensemble only for that particular datatype:

.. code-block:: ipython
.. code-block::
In [1]: mean_realization = ensemble.agg("mean", keylist="zonestats.csv")
In [2]: mean_realization.get_df("zonestats.csv")
Expand Down
14 changes: 2 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
"""The setup script."""
from setuptools import setup, find_packages

try:
from sphinx.setup_command import BuildDoc

cmdclass = {"build_sphinx": BuildDoc}
except ImportError:
# sphinx not installed - do not provide build_sphinx cmd
cmdclass = {}


with open("README.rst") as readme_file:
readme = readme_file.read()

Expand All @@ -20,13 +11,13 @@
history = history_file.read().decode("UTF-8")

REQUIREMENTS = [
"ecl>=2.9",
"resdata>=4.0.0",
"numpy",
"pandas",
"pyyaml>=5.1",
]

SETUP_REQUIREMENTS = ["setuptools>=28", "setuptools_scm"]
SETUP_REQUIREMENTS = ["setuptools>=28", "setuptools_scm < 6.1"]

with open("test_requirements.txt") as f:
test_requirements = f.read().splitlines()
Expand All @@ -42,7 +33,6 @@
setup(
name="fmu-ensemble",
use_scm_version={"write_to": "src/fmu/ensemble/version.py"},
cmdclass=cmdclass,
description="Python API to ensembles produced by ERT",
long_description=readme + "\n\n" + history,
author="Håvard Berland",
Expand Down
22 changes: 11 additions & 11 deletions src/fmu/ensemble/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import pandas as pd
import numpy as np
import yaml
from ecl import EclDataType
from ecl.eclfile import EclKW
from resdata import ResDataType
from resdata.resfile import ResdataKW

from .etc import Interaction # noqa
from .realization import ScratchRealization
Expand Down Expand Up @@ -723,7 +723,7 @@ def load_smry(
you have retrieved it through get_smry()
Wraps around Realization.load_smry() which wraps around
ecl.summary.EclSum.pandas_frame()
resdata.summary.Summary.pandas_frame()
Beware that the default time_index for ensembles is 'monthly',
differing from realizations which use raw dates by default.
Expand Down Expand Up @@ -1386,7 +1386,7 @@ def get_smry(
Aggregates summary data from all realizations.
Wraps around Realization.get_smry() which wraps around
ecl.summary.EclSum.pandas_frame()
resdata.summary.Summary.pandas_frame()
Args:
time_index: list of DateTime if interpolation is wanted
Expand Down Expand Up @@ -1499,7 +1499,7 @@ def get_eclgrid(self, props, report=0, agg="mean", active_only=False):
@property
def global_active(self):
"""
:returns: An EclKw with, for each cell,
:returns: An ResdataKW with, for each cell,
the number of realizations where the cell is active.
"""
warnings.warn(
Expand All @@ -1510,8 +1510,8 @@ def global_active(self):
FutureWarning,
)
if not self._global_active:
self._global_active = EclKW(
"eactive", self.global_size, EclDataType.ECL_INT
self._global_active = ResdataKW(
"eactive", self.global_size, ResDataType.RD_INT
)
for realization in self.realizations.values():
if realization.get_grid() is not None:
Expand Down Expand Up @@ -1674,13 +1674,13 @@ def _keyword_mean(self, prop, global_active, report=None):
"""
:returns: Mean values of keywords.
:param prop: Name of resulting Keyword.
:param global_active: A EclKW with, for each cell, The number of
:param global_active: A ResdataKW with, for each cell, The number of
realizations where the cell is active.
:param report: Report step for unrst keywords
"""
# ensemble._keyword_mean() is deprecated and
# will be removed in fmu-ensemble v2.0.0
mean = EclKW(prop, len(global_active), EclDataType.ECL_FLOAT)
mean = ResdataKW(prop, len(global_active), ResDataType.RD_FLOAT)
if report:
for _, realization in self.realizations.items():
if realization.get_unrst() is not None:
Expand All @@ -1698,13 +1698,13 @@ def _keyword_std_dev(self, prop, global_active, mean, report=0):
:returns: Standard deviation of keywords.
:param name: Name of resulting Keyword.
:param keywords: List of pairs of keywords and list of active cell
:param global_active: A EclKW with, for each cell, The number of
:param global_active: A ResdataKW with, for each cell, The number of
realizations where the cell is active.
:param mean: Mean of keywords.
"""
# ensemble._keyword_std_dev() is deprecated and
# will be removed in fmu-ensemble v2.0.0
std_dev = EclKW(prop, len(global_active), EclDataType.ECL_FLOAT)
std_dev = ResdataKW(prop, len(global_active), ResDataType.RD_FLOAT)
if report:
for _, realization in self.realizations.items():
real_prop = realization.get_global_unrst_keyword(prop, report)
Expand Down
14 changes: 7 additions & 7 deletions src/fmu/ensemble/ensembleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def load_smry(
Fetch summary data from all ensembles
Wraps around Ensemble.load_smry() which wraps
Realization.load_smry(), which wraps ecl.summary.EclSum.pandas_frame()
Realization.load_smry(), which wraps resdata.summary.Summary.pandas_frame()
The time index is determined at realization level. If you
ask for 'monthly', you will from each realization get its
Expand All @@ -596,8 +596,8 @@ def load_smry(
If a string is supplied, that string is attempted used
via get_smry_dates() in order to obtain a time index.
column_keys: list of column key wildcards
cache_eclsum: Boolean for whether we should cache the EclSum
objects. Set to False if you cannot keep all EclSum files in
cache_eclsum: Boolean for whether we should cache the Summary
objects. Set to False if you cannot keep all Summary files in
memory simultaneously
start_date: str or date with first date to include.
Dates prior to this date will be dropped, supplied
Expand Down Expand Up @@ -648,15 +648,15 @@ def get_smry(
Wraps around Ensemble.get_smry(), which wraps around
Realization.get_smry() which wraps around
ecl.summary.EclSum.pandas_frame()
resdata.summary.Summary.pandas_frame()
Args:
time_index: list of DateTime if interpolation is wanted
default is None, which returns the raw Eclipse report times
If a string is supplied, that string is attempted used
via get_smry_dates() in order to obtain a time index.
column_keys: list of column key wildcards
cache_eclsum: boolean for whether to cache the EclSum
cache_eclsum: boolean for whether to cache the Summary
objects. Defaults to False. Set to True if
there is enough memory to keep all realizations summary
files in memory at once. This will speed up subsequent
Expand Down Expand Up @@ -709,8 +709,8 @@ def get_smry_dates(
yield the sorted union of all valid timesteps for
all realizations. Other valid options are
'daily', 'monthly' and 'yearly'.
cache_eclsum: Boolean for whether we should cache the EclSum
objects. Set to False if you cannot keep all EclSum files in
cache_eclsum: Boolean for whether we should cache the Summary
objects. Set to False if you cannot keep all Summary files in
memory simultaneously
start_date: str or date with first date to include.
Dates prior to this date will be dropped, supplied
Expand Down
22 changes: 9 additions & 13 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import numpy as np
import pandas as pd

import ecl.summary
from ecl.eclfile import EclFile
from ecl.grid import EclGrid
from ecl import EclFileFlagEnum
from resdata.summary import Summary
from resdata.resfile import ResdataFile
from resdata.rd_util import FileMode
from resdata.grid import Grid

from .virtualrealization import VirtualRealization
from .realizationcombination import RealizationCombination
Expand Down Expand Up @@ -947,7 +947,7 @@ def get_eclsum(self, cache=True, include_restart=True):
if not os.path.exists(unsmry_filename):
return None
try:
eclsum = ecl.summary.EclSum(
eclsum = Summary(
unsmry_filename, lazy_load=False, include_restart=include_restart
)
except IOError:
Expand Down Expand Up @@ -986,7 +986,7 @@ def load_smry(
on the chosen time_index. If a custom time_index (list
of datetime) was supplied, <time_index> will be called 'custom'.
Wraps ecl.summary.EclSum.pandas_frame()
Wraps resdata.summary.Summary.pandas_frame()
See also get_smry()
Expand Down Expand Up @@ -1480,9 +1480,7 @@ def get_init(self):
return None

if not self._eclinit:
self._eclinit = EclFile(
init_filename, flags=EclFileFlagEnum.ECL_FILE_CLOSE_STREAM
)
self._eclinit = ResdataFile(init_filename, flags=FileMode.CLOSE_STREAM)
return self._eclinit

def get_unrst(self):
Expand All @@ -1509,9 +1507,7 @@ def get_unrst(self):
if not os.path.exists(unrst_filename):
return None
if not self._eclunrst:
self._eclunrst = EclFile(
unrst_filename, flags=EclFileFlagEnum.ECL_FILE_CLOSE_STREAM
)
self._eclunrst = ResdataFile(unrst_filename, flags=FileMode.CLOSE_STREAM)
return self._eclunrst

def get_grid_index(self, active_only):
Expand Down Expand Up @@ -1614,7 +1610,7 @@ def get_grid(self):
if not os.path.exists(grid_filename):
return None
if not self._eclgrid:
self._eclgrid = EclGrid(grid_filename)
self._eclgrid = Grid(grid_filename)
return self._eclgrid

@property
Expand Down
4 changes: 2 additions & 2 deletions tests/test_realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dateutil.relativedelta import relativedelta

import pytest
import ecl.summary
from resdata.summary import Summary

import numpy as np

Expand Down Expand Up @@ -475,7 +475,7 @@ def test_singlereal_ecl(tmp="TMP"):
real = ensemble.ScratchRealization(realdir)

# Eclipse summary files:
assert isinstance(real.get_eclsum(), ecl.summary.EclSum)
assert isinstance(real.get_eclsum(), Summary)
if not os.path.exists(tmp):
os.mkdir(tmp)
real.load_smry().to_csv(os.path.join(tmp, "real0smry.csv"), index=False)
Expand Down

0 comments on commit 467edd6

Please sign in to comment.