diff --git a/src/fmu/ensemble/ensemble.py b/src/fmu/ensemble/ensemble.py index b2604d43..fc778604 100644 --- a/src/fmu/ensemble/ensemble.py +++ b/src/fmu/ensemble/ensemble.py @@ -4,6 +4,7 @@ import os import glob import logging +import warnings import dateutil import pandas as pd @@ -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, @@ -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, @@ -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 @@ -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(): @@ -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, ): @@ -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] @@ -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() @@ -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() @@ -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, @@ -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: @@ -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 ] @@ -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 @@ -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: @@ -1467,6 +1551,8 @@ 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) @@ -1474,6 +1560,13 @@ def _get_grid_index(self, active=True): @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( @@ -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( @@ -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( @@ -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) @@ -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) @@ -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(): @@ -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(): diff --git a/src/fmu/ensemble/ensembleset.py b/src/fmu/ensemble/ensembleset.py index 83a0af33..e825b0d4 100644 --- a/src/fmu/ensemble/ensembleset.py +++ b/src/fmu/ensemble/ensembleset.py @@ -4,6 +4,7 @@ import os import glob import logging +import warnings import numpy as np import pandas as pd @@ -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, ): @@ -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( @@ -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, ): @@ -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( @@ -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 @@ -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( @@ -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)) diff --git a/src/fmu/ensemble/realization.py b/src/fmu/ensemble/realization.py index 5762f6bd..561494da 100644 --- a/src/fmu/ensemble/realization.py +++ b/src/fmu/ensemble/realization.py @@ -15,6 +15,7 @@ from datetime import datetime, date, time import dateutil import logging +import warnings import yaml import numpy as np @@ -949,7 +950,7 @@ def load_smry( self, time_index="raw", column_keys=None, - cache_eclsum=True, + cache_eclsum=None, start_date=None, end_date=None, include_restart=True, @@ -1000,6 +1001,17 @@ def load_smry( DataFrame: with summary keys as columns and dates as indices. Empty dataframe if no summary is available. """ + 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, + ) + else: + cache_eclsum = True + if not self.get_eclsum(cache=cache_eclsum): # Return empty, but do not store the empty dataframe in self.data return pd.DataFrame() @@ -1047,7 +1059,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, @@ -1079,6 +1091,18 @@ def get_smry( Returns empty dataframe if there is no summary file, or if the column_keys are not existing. """ + + 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, + ) + else: + cache_eclsum = True + if not isinstance(column_keys, list): column_keys = [column_keys] if isinstance(time_index, str) and time_index == "raw": @@ -1192,6 +1216,15 @@ def get_smryvalues(self, props_wildcard=None): a dataframe with values. Raw times from UNSMRY. Empty dataframe if no summary file data available """ + warnings.warn( + ( + "realization.get_smryvalues() is deprecated and " + "will be removed in fmu-ensemble v2.0.0. Process " + "columns from get_smry() instead." + ), + FutureWarning, + ) + if not self._eclsum: # check if it is cached self.get_eclsum() @@ -1410,6 +1443,13 @@ def get_init(self): """ :returns: init file of the realization. """ + warnings.warn( + ( + "realization.get_init() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) init_file_row = self.files[self.files.FILETYPE == "INIT"] init_filename = None if len(init_file_row) == 1: @@ -1433,6 +1473,13 @@ def get_unrst(self): """ :returns: restart file of the realization. """ + warnings.warn( + ( + "realization.get_unrst() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) unrst_file_row = self.files[self.files.FILETYPE == "UNRST"] unrst_filename = None if len(unrst_file_row) == 1: @@ -1455,6 +1502,13 @@ def get_grid_index(self, active_only): """ Return the grid index in a pandas dataframe. """ + warnings.warn( + ( + "realization.get_grid_index() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_grid(): return self.get_grid().export_index(active_only=active_only) logger.warning("No GRID file in realization %s", self) @@ -1462,6 +1516,13 @@ def get_grid_index(self, active_only): def get_grid_corners(self, grid_index): """Return a dataframe with the the x, y, z for the 8 grid corners of corner point cells""" + warnings.warn( + ( + "realization.get_grid_corners() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_grid(): corners = self.get_grid().export_corners(grid_index) columns = [ @@ -1498,6 +1559,13 @@ def get_grid_corners(self, grid_index): def get_grid_centre(self, grid_index): """Return the grid centre of corner-point-cells, x, y and z in distinct columns""" + warnings.warn( + ( + "realization.get_grid_centre() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_grid(): grid_cell_centre = self.get_grid().export_position(grid_index) return pd.DataFrame( @@ -1510,6 +1578,13 @@ def get_grid(self): """ :returns: grid file of the realization. """ + warnings.warn( + ( + "realization.get_grid() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) grid_file_row = self.files[self.files.FILETYPE == "EGRID"] grid_filename = None if len(grid_file_row) == 1: @@ -1531,6 +1606,13 @@ def global_size(self): """ :returns: Number of cells in the realization. """ + warnings.warn( + ( + "realization.get_grid() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_grid() is not None: return self.get_grid().get_global_size() @@ -1541,6 +1623,13 @@ def actnum(self): Active cells are given value 1, while inactive cells have value 1. """ + warnings.warn( + ( + "realization.get_grid() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if not self._actnum and self.get_init() is not None: self._actnum = self.get_init()["PORV"][0].create_actnum() return self._actnum @@ -1550,6 +1639,13 @@ def report_dates(self): """ :returns: List of DateTime.DateTime for which values are reported. """ + warnings.warn( + ( + "realization.get_grid() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_unrst() is not None: return self.get_unrst().report_dates @@ -1559,6 +1655,13 @@ def get_global_init_keyword(self, prop): :returns: The EclKw of given name. Length is global_size. non-active cells are given value 0. """ + warnings.warn( + ( + "realization.get_global_init_keyword() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_init() is not None: return self.get_init()[prop][0].scatter_copy(self.actnum) @@ -1568,5 +1671,12 @@ def get_global_unrst_keyword(self, prop, report): :returns: The EclKw of given name. Length is global_size. non-active cells are given value 0. """ + warnings.warn( + ( + "realization.get_global_unrst_keyword() is deprecated and " + "will be removed in later versions." + ), + FutureWarning, + ) if self.get_unrst() is not None: return self.get_unrst()[prop][report].scatter_copy(self.actnum) diff --git a/src/fmu/ensemble/virtualensemble.py b/src/fmu/ensemble/virtualensemble.py index 994c93d2..35ba07a7 100644 --- a/src/fmu/ensemble/virtualensemble.py +++ b/src/fmu/ensemble/virtualensemble.py @@ -6,6 +6,7 @@ import shutil import fnmatch import datetime +import warnings import logging import yaml @@ -468,6 +469,13 @@ def to_disk( symlinks (boolean): If includefiles is True, setting this to True means that only symlinking will take place, not full copy. """ + warnings.warn( + ( + "to_disk() is considered deprecated and " + "might be removed in fmu-ensemble v2.0.0" + ), + FutureWarning, + ) if not HAVE_PYARROW: logger.warning( ( @@ -641,6 +649,13 @@ def from_disk(self, filesystempath, fmt="parquet", lazy_load=False): lazy_load (bool): If True, loading of dataframes from disk will be postponed until get_df() is actually called. """ + warnings.warn( + ( + "from_disk() is considered deprecated and " + "might be removed in fmu-ensemble v2.0.0" + ), + FutureWarning, + ) start_time = datetime.datetime.now() if fmt not in ["csv", "parquet"]: raise ValueError("Unknown format for from_disk: %s" % fmt) diff --git a/src/fmu/ensemble/virtualrealization.py b/src/fmu/ensemble/virtualrealization.py index 096381ac..113d346b 100644 --- a/src/fmu/ensemble/virtualrealization.py +++ b/src/fmu/ensemble/virtualrealization.py @@ -2,6 +2,7 @@ import os import fnmatch import shutil +import warnings import logging import pandas as pd @@ -78,6 +79,11 @@ def to_disk(self, filesystempath, delete=False): delete: boolean, if True, existing directory at the filesystempath will be deleted before export. """ + warnings.warn( + "to_disk() is considered deprecated and might be " + "removed in fmu-ensemble v2.0.0", + FutureWarning, + ) if os.path.exists(filesystempath): if delete: shutil.rmtree(filesystempath) @@ -141,6 +147,11 @@ def load_disk(self, filesystempath): filesystempath: path to a directory that to_disk() has written to (or a really careful user) """ + warnings.warn( + "load_disk() is considered deprecated and might be " + "removed in fmu-ensemble v2.0.0", + FutureWarning, + ) logger.info("Loading virtual realization from %s", filesystempath) for root, _, filenames in os.walk(filesystempath): for filename in filenames: diff --git a/tests/test_ensemble.py b/tests/test_ensemble.py index 12230a3f..3eb1930a 100644 --- a/tests/test_ensemble.py +++ b/tests/test_ensemble.py @@ -853,7 +853,8 @@ def test_eclsumcaching(): # If we redo this operation, the same objects should all # be None afterwards: - ens.load_smry(cache_eclsum=None) + ens.load_smry(cache_eclsum=False) + # cache_eclsum==None is from v1.1.5 no longer equivalent to False assert not any([x._eclsum for (idx, x) in ens.realizations.items()]) ens.get_smry()