From ada4c9f17aa0b562eb6f93f6630baa50df083b96 Mon Sep 17 00:00:00 2001 From: Asgeir Nyvoll <47146384+asnyv@users.noreply.github.com> Date: Thu, 25 Mar 2021 11:29:51 +0100 Subject: [PATCH] Yearly inferred pandas frequency = AS-JAN (#592) --- CHANGELOG.md | 1 + .../data_input/test_calc_from_cumulatives.py | 25 +++++++++++++++++++ .../_datainput/from_timeseries_cumulatives.py | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9047bff9..d59f55d8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#586](https://github.com/equinor/webviz-subsurface/pull/586) - Added phase ratio vs pressure and density vs pressure plots. Added unit and density functions to PVT library. Refactored code and added checklist for plots to be viewed in PVT plot plugin. Improved the layout. ### Fixed +- [#592](https://github.com/equinor/webviz-subsurface/pull/592) - Fixed bug for inferred frequency of yearly summary data. - [#594](https://github.com/equinor/webviz-subsurface/pull/594) - Fixed bug in SurfaceViewerFMU where surfaces with only undefined values was not handled properly. - [#584](https://github.com/equinor/webviz-subsurface/pull/584) - Fixed bug for in RelativePermeability plugin where it was not possible to plot against oil saturation axis when using relperm data of "family 2". - [#595](https://github.com/equinor/webviz-subsurface/pull/595) - Raise a descriptive error in SurfaceViewerFMU plugin if no surfaces are available. diff --git a/tests/unit_tests/data_input/test_calc_from_cumulatives.py b/tests/unit_tests/data_input/test_calc_from_cumulatives.py index 0597c2fab..b0842ce72 100644 --- a/tests/unit_tests/data_input/test_calc_from_cumulatives.py +++ b/tests/unit_tests/data_input/test_calc_from_cumulatives.py @@ -130,6 +130,31 @@ def test_calc_from_cumulatives(testdata_folder: Path) -> None: - real_data[real_data.DATE == "2002-02-01"]["GWPT:OP"].values ) + # Resample the data to yearly datapoints: + data_df = data_df[ + data_df["DATE"].isin(["2000-01-01", "2001-01-01", "2002-01-01", "2003-01-01"]) + ] + calc_df = from_cum.calc_from_cumulatives( + data=data_df, + column_keys=["WGPT:OP_2", "GWPT:OP"], + time_index="yearly", + time_index_input="yearly", + as_rate=False, + ) + # Test real 9, iter-0 + real_data = data_df[(data_df["REAL"] == 9) & (data_df["ENSEMBLE"] == "iter-0")] + real_calc = calc_df[(calc_df["REAL"] == 9) & (calc_df["ENSEMBLE"] == "iter-0")] + + assert real_calc[real_calc.DATE == "2000-01-01"]["INTVL_WGPT:OP_2"].values == ( + real_data[real_data.DATE == "2001-01-01"]["WGPT:OP_2"].values + - real_data[real_data.DATE == "2000-01-01"]["WGPT:OP_2"].values + ) + + assert real_calc[real_calc.DATE == "2002-01-01"]["INTVL_GWPT:OP"].values == ( + real_data[real_data.DATE == "2003-01-01"]["GWPT:OP"].values + - real_data[real_data.DATE == "2002-01-01"]["GWPT:OP"].values + ) + @pytest.mark.parametrize( "column_keys,time_index,time_index_input,as_rate", diff --git a/webviz_subsurface/_datainput/from_timeseries_cumulatives.py b/webviz_subsurface/_datainput/from_timeseries_cumulatives.py index 96521dc7d..cc8dc2f14 100644 --- a/webviz_subsurface/_datainput/from_timeseries_cumulatives.py +++ b/webviz_subsurface/_datainput/from_timeseries_cumulatives.py @@ -103,7 +103,7 @@ def calc_from_cumulatives( def _verify_time_index( df: pd.DataFrame, time_index: str, time_index_input: str ) -> None: - freqs = {"D": "daily", "MS": "monthly", "YS": "yearly"} + freqs = {"D": "daily", "MS": "monthly", "AS-JAN": "yearly"} valid_time_indices = { "daily": ["daily", "monthly", "yearly"], "monthly": ["monthly", "yearly"],