fmu.ensemble.util package
Submodules
fmu.ensemble.util.dates module
Common utility functions used in fmu.ensemble
- fmu.ensemble.util.dates.logger = <Logger fmu.ensemble.util.dates (WARNING)>
Mapping from fmu-ensemble custom offset strings to Pandas DateOffset strings. See https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects
- fmu.ensemble.util.dates.date_range(start_date, end_date, freq)[source]
Wrapper for pandas.date_range to allow for extra fmu-ensemble specific mnemonics ‘yearly’, ‘daily’, ‘weekly’, mapped over to pandas DateOffsets
- Parameters:
start_date (datetime.date) –
end_date (datetime.date) –
freq (str) – monthly, daily, weekly, yearly, or a Pandas date offset frequency.
- Returns:
list of datetimes
- fmu.ensemble.util.dates.unionize_smry_dates(eclsumsdates, freq, normalize, start_date=None, end_date=None)[source]
Unionize lists of dates into one datelist encompassing the date range from all datelists, with cropping, resampling to wanted frequency, and potential normalized dates to the frequency (rollback/rollforward)
- Parameters:
eclsumsdates (list of lists of datetimes) –
freq (str) – Requested frequency
normalize (bool) – Normalize daterange to frequency or not.
start_date (datetime.date or str) – Overridden if freq==’first’
end_date (datetime.date or str) – Overridden if freq==’last’
- Returns:
list of datetime.date
- fmu.ensemble.util.dates.normalize_dates(start_date: date, end_date: date, freq: str) Tuple[date, date] [source]
Normalize start and end date according to frequency by extending the time range.
So for [1997-11-5, 2020-03-02] and monthly freqency this will transform your dates to [1997-11-1, 2020-04-01]
For yearly frequency will be [1997-01-01, 2021-01-01].
- Parameters:
start_date – datetime.date
end_date – datetime.date
freq – string with either ‘monthly’, ‘yearly’, ‘weekly’ or any other frequency offset accepted by Pandas
- Returns:
Tuple of normalized (start_date, end_date)
fmu.ensemble.util.rates module
Common utility functions for rates used in fmu.ensemble
- fmu.ensemble.util.rates.compute_volumetric_rates(realization, column_keys, time_index, time_unit)[source]
Compute volumetric rates from cumulative summary vectors
Column names that are not referring to cumulative summary vectors are silently ignored.
A Dataframe is returned with volumetric rates, that is rate values that can be summed up to the cumulative version. The ‘T’ in the column name is switched with ‘R’. If you ask for FOPT, you will get FOPR in the returned dataframe.
Rates in the returned dataframe are valid forwards in time, opposed to rates coming directly from the Eclipse simulator which are valid backwards in time.
If time_unit is set, the rates will be scaled to represent either daily, monthly or yearly rates. These will sum up to the cumulative as long as you multiply with the correct number of days, months or year between each consecutive date index. Month lengths and leap years are correctly handled.
The returned dataframe is indexed by DATE.
- Parameters:
realization (ScratchRealization or VirtualRealization) – The realization object containing rates to compute from.
column_keys – str or list of strings, cumulative summary vectors
time_index – str or list of datetimes
time_unit – str or None. If None, the rates returned will be the difference in cumulative between each included time step (where the time interval can vary arbitrarily) If set to ‘days’, ‘months’ or ‘years’, the rates will be scaled to represent a daily, monthly or yearly rate that is compatible with the date index and the cumulative data.
- Returns:
A dataframe indexed by DATE with cumulative columns.
- fmu.ensemble.util.rates.cumcolumn_to_ratecolumn(smrycolumn)[source]
Converts a cumulative summary column name to the corresponding rate column name.
Returns None if the input summary column name is not assumed to be cumulative.
Example: “FOPT” will be mapped to “FOPR”
- Parameters:
smrycolumn (str) – Name of summary vector/column
- Returns:
rate column or None
- Return type:
str
Module contents
Common utility functions used in fmu.ensemble
- fmu.ensemble.util.flatten(dictionary, parent_key='', sep='_')[source]
Flatten nested dictionaries by introducing new keys with the accumulated path.
e.g. {“foo”: {“bar”: “com”}} becomes {“foo-bar”: “com”}
- Parameters:
dictionary (dict) – Possibly nested dictionary
parent_key (str) – If provided, append as top level key
sep (str) – Separator used in merged keys.
- Returns:
dict with only one level.
- fmu.ensemble.util.parse_number(value)[source]
Try to parse the string first as an integer, then as float, if both fails, return the original string.
Caveats: Know your Python numbers: https://stackoverflow.com/questions/379906/how-do-i-parse-a-string-to-a-float-or-int-in-python
Beware, this is a minefield.
- Parameters:
value (str) –
- Returns:
int, float or string
- fmu.ensemble.util.shortcut2path(keys, shortpath)[source]
Convert short pathnames to fully qualified pathnames within the datastore.
If the fully qualified localpath is
‘share/results/volumes/simulator_volume_fipnum.csv’
then you can also access this with these alternatives:
simulator_volume_fipnum
simulator_volume_fipnum.csv
share/results/volumes/simulator_volume_fipnum
but only as long as there is no ambiguity. In case of ambiguity, the shortpath will be returned.
- Parameters:
keys (list of str) – List if all keys in the internal datastore
shortpath (str) – The search string, the short pathname that should resolve to a fully qualified localpath
- Returns:
Fully qualified path if found in keys, returns the shortpath input untouched if nothing is found, or of the shortpath is already fully qualified.