Skip to content

Commit

Permalink
Deprecate functions that are planned removed in v2.0.0 (#202)
Browse files Browse the repository at this point in the history
* Deprecate cache_eclsum and stacked options. Stacked was never in use. cache_eclsum is not compatible with a parallel approach.

* Deprecate to/from_disk. These are not very important to remove, so the deprecation can be lifted.

* Deprecate grid access functions

* Deprecate get_groupnames and get_wellnames (too specific tasks for fmu-ensemble)
  • Loading branch information
berland authored Feb 23, 2021
1 parent 82cf5fa commit 868bc9d
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 13 deletions.
138 changes: 131 additions & 7 deletions src/fmu/ensemble/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import glob
import logging
import warnings

import dateutil
import pandas as pd
Expand Down Expand Up @@ -696,8 +697,8 @@ def load_smry(
self,
time_index="raw",
column_keys=None,
stacked=True,
cache_eclsum=True,
stacked=None,
cache_eclsum=None,
start_date=None,
end_date=None,
include_restart=True,
Expand Down Expand Up @@ -760,8 +761,28 @@ def load_smry(
pd.DataFame: Summary vectors for the ensemble, or
a dict of dataframes if stacked=False.
"""
if stacked is not None:
warnings.warn(
(
"stacked option to load_smry() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
else:
stacked = True
if not stacked:
raise NotImplementedError

if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to load_smry() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

# Future: Multithread this!
for realidx, realization in self.realizations.items():
# We do not store the returned DataFrames here,
Expand Down Expand Up @@ -963,7 +984,7 @@ def get_smry_dates(
normalize=True,
start_date=None,
end_date=None,
cache_eclsum=True,
cache_eclsum=None,
include_restart=True,
):
"""Return list of datetimes for an ensemble according to frequency
Expand Down Expand Up @@ -996,6 +1017,17 @@ def get_smry_dates(
list of datetimes. Empty list if no data found.
"""

if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to get_smry_dates() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
else:
cache_eclsum = True

# Build list of list of eclsum dates
eclsumsdates = []
for _, realization in self.realizations.items():
Expand All @@ -1014,7 +1046,7 @@ def get_smry_stats(
column_keys=None,
time_index="monthly",
quantiles=None,
cache_eclsum=True,
cache_eclsum=None,
start_date=None,
end_date=None,
):
Expand Down Expand Up @@ -1056,6 +1088,15 @@ def get_smry_stats(
strings in the outer index are changed accordingly. If no
data is found, return empty DataFrame.
"""
if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to get_smry_stats() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

if quantiles is None:
quantiles = [10, 90]

Expand Down Expand Up @@ -1105,6 +1146,13 @@ def get_wellnames(self, well_match=None):
summary file or no matched well names.
"""
warnings.warn(
(
"ensemble.get_wellnames() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if isinstance(well_match, str):
well_match = [well_match]
result = set()
Expand Down Expand Up @@ -1135,7 +1183,13 @@ def get_groupnames(self, group_match=None):
summary file or no matched well names.
"""

warnings.warn(
(
"ensemble.get_groupnames() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if isinstance(group_match, str):
group_match = [group_match]
result = set()
Expand Down Expand Up @@ -1323,7 +1377,7 @@ def get_smry(
self,
time_index=None,
column_keys=None,
cache_eclsum=True,
cache_eclsum=None,
start_date=None,
end_date=None,
include_restart=True,
Expand Down Expand Up @@ -1361,6 +1415,15 @@ def get_smry(
REAL with integers is added to distinguish realizations. If
no realizations, empty DataFrame is returned.
"""
if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to get_smry() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

if isinstance(time_index, str):
# Try interpreting as ISO-date:
try:
Expand Down Expand Up @@ -1406,6 +1469,13 @@ def get_eclgrid(self, props, report=0, agg="mean", active_only=False):
A dictionary. Index by grid attribute, and contains a list
corresponding to a set of values for each grid cells.
"""
warnings.warn(
(
"ensemble.get_eclgrid() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
egrid_reals = [
real for real in self.realizations.values() if real.get_grid() is not None
]
Expand All @@ -1432,6 +1502,13 @@ def global_active(self):
:returns: An EclKw with, for each cell,
the number of realizations where the cell is active.
"""
warnings.warn(
(
"ensemble.global_active() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if not self._global_active:
self._global_active = EclKW(
"eactive", self.global_size, EclDataType.ECL_INT
Expand All @@ -1448,6 +1525,13 @@ def global_size(self):
:returns: global size of the realizations in the Ensemble. see
:func:`fmu_postprocessing.modelling.Realization.global_size()`.
"""
warnings.warn(
(
"ensemble.global_size() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if not self.realizations:
return 0
if self._global_size is None:
Expand All @@ -1467,13 +1551,22 @@ def _get_grid_index(self, active=True):
Returns: The grid of the ensemble, see
:func:`fmu.ensemble.Realization.get_grid()`.
"""
# ensemble._get_grid_index() is deprecated and
# will be removed in fmu-ensemble v2.0.0
if not self.realizations:
return None
return list(self.realizations.values())[0].get_grid_index(active=active)

@property
def init_keys(self):
"""Return all keys available in the Eclipse INIT file """
warnings.warn(
(
"ensemble.init_keys() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if not self.realizations:
return None
all_keys = set.union(
Expand All @@ -1488,6 +1581,13 @@ def init_keys(self):
@property
def unrst_keys(self):
"""Return keys availaible in the Eclipse UNRST file """
warnings.warn(
(
"ensemble.unrst_keys() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if not self.realizations:
return None
all_keys = set.union(
Expand All @@ -1501,6 +1601,13 @@ def unrst_keys(self):

def get_unrst_report_dates(self):
"""Returns UNRST report step and the corresponding date """
warnings.warn(
(
"ensemble.get_unrst_report_dates() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if not self.realizations:
return None
all_report_dates = set.union(
Expand All @@ -1523,6 +1630,13 @@ def get_init(self, prop, agg):
and corresponding values for given property as values.
:raises ValueError: If prop is not found.
"""
warnings.warn(
(
"ensemble.get_init() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if agg == "mean":
mean = self._keyword_mean(prop, self.global_active)
return pd.Series(mean.numpy_copy(), name=prop)
Expand All @@ -1539,7 +1653,13 @@ def get_unrst(self, prop, report, agg):
and corresponding values for given property as values.
:raises ValueError: If prop is not in `TIME_DEPENDENT`.
"""

warnings.warn(
(
"ensemble.get_unrst() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)
if agg == "mean":
mean = self._keyword_mean(prop, self.global_active, report=report)
return pd.Series(mean.numpy_copy(), name=prop)
Expand All @@ -1558,6 +1678,8 @@ def _keyword_mean(self, prop, global_active, report=None):
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)
if report:
for _, realization in self.realizations.items():
Expand All @@ -1580,6 +1702,8 @@ def _keyword_std_dev(self, prop, global_active, mean, report=0):
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)
if report:
for _, realization in self.realizations.items():
Expand Down
40 changes: 37 additions & 3 deletions src/fmu/ensemble/ensembleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import glob
import logging
import warnings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -571,7 +572,7 @@ def load_smry(
self,
time_index="raw",
column_keys=None,
cache_eclsum=True,
cache_eclsum=None,
start_date=None,
end_date=None,
):
Expand Down Expand Up @@ -611,6 +612,15 @@ def load_smry(
A DataFame of summary vectors for the ensembleset.
The column 'ENSEMBLE' will denote each ensemble's name
"""
if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to load_smry() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

# Future: Multithread this:
for _, ensemble in self._ensembles.items():
ensemble.load_smry(
Expand All @@ -630,7 +640,7 @@ def get_smry(
self,
time_index=None,
column_keys=None,
cache_eclsum=False,
cache_eclsum=None,
start_date=None,
end_date=None,
):
Expand Down Expand Up @@ -664,6 +674,16 @@ def get_smry(
ENSEMBLE will distinguish the different ensembles by their
respective names.
"""

if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to get_smry() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

smrylist = []
for _, ensemble in self._ensembles.items():
smry = ensemble.get_smry(
Expand All @@ -676,7 +696,7 @@ def get_smry(
return pd.DataFrame()

def get_smry_dates(
self, freq="monthly", cache_eclsum=True, start_date=None, end_date=None
self, freq="monthly", cache_eclsum=None, start_date=None, end_date=None
):
"""Return list of datetimes from an ensembleset
Expand Down Expand Up @@ -704,6 +724,15 @@ def get_smry_dates(
list of datetime.date.
"""

if cache_eclsum is not None:
warnings.warn(
(
"cache_eclsum option to get_smry_dates() is deprecated and "
"will be removed in fmu-ensemble v2.0.0"
),
FutureWarning,
)

rawdates = set()
for _, ensemble in self._ensembles.items():
rawdates = rawdates.union(
Expand Down Expand Up @@ -744,6 +773,11 @@ def get_wellnames(self, well_match=None):
summary file or no matched well names.
"""
warnings.warn(
"ensembleset.get_wellnames() is deprecated and "
"will be removed in later versions.",
FutureWarning,
)
result = set()
for _, ensemble in self._ensembles.items():
result = result.union(ensemble.get_wellnames(well_match))
Expand Down
Loading

0 comments on commit 868bc9d

Please sign in to comment.