-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
249 additions
and
40 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
tests/unit_tests/data_input/test_calc_from_cumulatives.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import pytest | ||
import pandas as pd | ||
import webviz_subsurface._datainput.from_timeseries_cumulatives as from_cum | ||
|
||
DATA_DF = pd.read_csv( | ||
"./webviz-subsurface-testdata/reek_history_match/share/results/tables/" | ||
+ "unsmry--monthly.csv" | ||
) | ||
DATA_DF.DATE = DATA_DF.DATE.astype(str) | ||
|
||
|
||
def test_calc_from_cumulatives(): | ||
# Includes monthly data, 10 reals x 4 ensembles, 3 years and 1 month (2000-01-01 to 2003-02-01) | ||
|
||
## Test single column key, FOPT as average rate avg_fopr, monthly | ||
calc_df = from_cum.calc_from_cumulatives( | ||
data=DATA_DF, | ||
column_keys="FOPT", | ||
time_index="monthly", | ||
time_index_input="monthly", | ||
as_rate=True, | ||
) | ||
|
||
# Test real 0, iter-2 | ||
real_data = DATA_DF[(DATA_DF["REAL"] == 0) & (DATA_DF["ENSEMBLE"] == "iter-2")] | ||
real_calc = calc_df[(calc_df["REAL"] == 0) & (calc_df["ENSEMBLE"] == "iter-2")] | ||
|
||
assert real_calc[real_calc.DATE == "2000-01-01"]["AVG_FOPR"].values == ( | ||
( | ||
real_data[real_data.DATE == "2000-02-01"]["FOPT"].values | ||
- real_data[real_data.DATE == "2000-01-01"]["FOPT"].values | ||
) | ||
/ 31 | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2002-05-01"]["AVG_FOPR"].values == ( | ||
( | ||
real_data[real_data.DATE == "2002-06-01"]["FOPT"].values | ||
- real_data[real_data.DATE == "2002-05-01"]["FOPT"].values | ||
) | ||
/ 31 | ||
) | ||
|
||
## Test multiple column keys, WOPT:OP_1 as average rate avg_fopr, monthly | ||
calc_df = from_cum.calc_from_cumulatives( | ||
data=DATA_DF, | ||
column_keys=["WOPT:OP_1", "GOPT:OP"], | ||
time_index="yearly", | ||
time_index_input="monthly", | ||
as_rate=True, | ||
) | ||
# Test real 4, iter-0 | ||
real_data = DATA_DF[(DATA_DF["REAL"] == 4) & (DATA_DF["ENSEMBLE"] == "iter-0")] | ||
real_calc = calc_df[(calc_df["REAL"] == 4) & (calc_df["ENSEMBLE"] == "iter-0")] | ||
|
||
assert real_calc[real_calc.DATE == "2000-01-01"]["AVG_WOPR:OP_1"].values == ( | ||
( | ||
real_data[real_data.DATE == "2001-01-01"]["WOPT:OP_1"].values | ||
- real_data[real_data.DATE == "2000-01-01"]["WOPT:OP_1"].values | ||
) | ||
/ 366 | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2002-01-01"]["AVG_GOPR:OP"].values == ( | ||
( | ||
real_data[real_data.DATE == "2003-01-01"]["GOPT:OP"].values | ||
- real_data[real_data.DATE == "2002-01-01"]["GOPT:OP"].values | ||
) | ||
/ 365 | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2002-01-01"]["AVG_WOPR:OP_1"].values == ( | ||
( | ||
real_data[real_data.DATE == "2003-01-01"]["WOPT:OP_1"].values | ||
- real_data[real_data.DATE == "2002-01-01"]["WOPT:OP_1"].values | ||
) | ||
/ 365 | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2001-01-01"]["AVG_GOPR:OP"].values == ( | ||
( | ||
real_data[real_data.DATE == "2002-01-01"]["GOPT:OP"].values | ||
- real_data[real_data.DATE == "2001-01-01"]["GOPT:OP"].values | ||
) | ||
/ 365 | ||
) | ||
|
||
## Test multiple column keys, WOPR_OP as average rate avg_fopr, monthly | ||
calc_df = from_cum.calc_from_cumulatives( | ||
data=DATA_DF, | ||
column_keys=["WGPT:OP_2", "GWPT:OP"], | ||
time_index="monthly", | ||
time_index_input="monthly", | ||
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 == "2000-01-01"]["WGPT:OP_2"].values | ||
- real_data[real_data.DATE == "2000-02-01"]["WGPT:OP_2"].values | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2002-05-01"]["INTVL_GWPT:OP"].values == ( | ||
real_data[real_data.DATE == "2002-06-01"]["GWPT:OP"].values | ||
- real_data[real_data.DATE == "2002-05-01"]["GWPT:OP"].values | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2000-12-01"]["INTVL_WGPT:OP_2"].values == ( | ||
real_data[real_data.DATE == "2001-01-01"]["WGPT:OP_2"].values | ||
- real_data[real_data.DATE == "2000-12-01"]["WGPT:OP_2"].values | ||
) | ||
|
||
assert real_calc[real_calc.DATE == "2002-02-01"]["INTVL_GWPT:OP"].values == ( | ||
real_data[real_data.DATE == "2002-03-01"]["GWPT:OP"].values | ||
- real_data[real_data.DATE == "2002-02-01"]["GWPT:OP"].values | ||
) | ||
|
||
|
||
def test_calc_from_cumulatives_errors(): | ||
with pytest.raises(ValueError): | ||
# The test input data is monthly, so time_index_input should be monthly | ||
calc_df = from_cum.calc_from_cumulatives( | ||
data=DATA_DF, | ||
column_keys=["WGPT:OP_2", "GWPT:OP"], | ||
time_index="monthly", | ||
time_index_input="yearly", | ||
as_rate=False, | ||
) | ||
with pytest.raises(ValueError): | ||
# The test input data is monthly, so time_index == "daily" should not be allowed. | ||
calc_df = from_cum.calc_from_cumulatives( | ||
data=DATA_DF, | ||
column_keys=["WGPT:OP_2", "GWPT:OP"], | ||
time_index="daily", | ||
time_index_input="monthly", | ||
as_rate=True, | ||
) |
46 changes: 46 additions & 0 deletions
46
tests/unit_tests/utils_tests/test_simulation_timeseries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import webviz_subsurface._utils.simulation_timeseries as simulation_timeseries | ||
|
||
|
||
def test_date_to_interval_conversion(): | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2000-01-01", vector="AVG_FOPR", interval="monthly", as_date=False | ||
) | ||
== "2000-01" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2003-05-12", vector="AVG_WOPR:OP_1", interval="monthly", as_date=False | ||
) | ||
== "2003-05" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2002-05-12", vector="AVG_WOPR:OP_1", interval="yearly", as_date=False | ||
) | ||
== "2002" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2002-05-12", vector="AVG_WOPR:OP_1", interval="yearly", as_date=True | ||
) | ||
== "2002-01-01" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2002-05-12", vector="AVG_WOPR:OP_1", interval="daily", as_date=False | ||
) | ||
== "2002-05-12" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date="2002-05-12", vector="AVG_WOPR:OP_1", interval="daily", as_date=True | ||
) | ||
== "2002-05-12" | ||
) | ||
assert ( | ||
simulation_timeseries.date_to_interval_conversion( | ||
date=None, vector="AVG_WOPR:OP_1", interval="daily", as_date=True | ||
) | ||
is None | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.