Skip to content

Commit

Permalink
Replace ecl with resdata
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Nov 10, 2023
1 parent 69e7dd2 commit 170296d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
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 @@ -1398,7 +1398,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 @@ -1511,7 +1511,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 @@ -1522,8 +1522,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 @@ -1686,13 +1686,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 @@ -1710,13 +1710,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 @@ -1479,9 +1479,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 @@ -1508,9 +1506,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 @@ -1613,7 +1609,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 170296d

Please sign in to comment.