-
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.
More flexibility in
GroupTree
(#1138)
* Two new parameters in GroupTree for more flexibility, terminal_node and excl_well_startswith * Implemented new function get_filtered_dataframe in gruptree_model * New input excl_well_endswith * Improved Exception message for injection nodes in BRANPROP trees * Started on unit tests for the gruptree model * Fixed CI workflow issues * Improved tests with fixture creating the gruptree model * Improved handling of injection for BRANPROP nodes * Made terminal_node optional in get_filtered_dataframe * New input parameter tree_type which is GRUPTREE by default, and some other improvements * Relaxed the requirements on summary vectors * New StrEnum DataType for oilrate, gasrate etc * Eased the requirement on node summary vectors, they are now optional * New type EdgeOrNode * Small docstring update * Implemented mock GruptreeModel class with some new tests * Allowed tree_type to be defaulted in gruptree_model, in which case the tree is automatically selected * Changelog entry * Small update to comment * Set back scipy version in setup.py and installed v 1.9.2 in CI workflow * Updated CI workflow Co-authored-by: Øyvind Lind-Johansen <[email protected]>
- Loading branch information
Showing
9 changed files
with
459 additions
and
119 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DATE,CHILD,KEYWORD,PARENT,VFP_TABLE,ALQ,ALQ_SURFACE_DENSITY,TERMINAL_PRESSURE,AS_CHOKE,ADD_GAS_LIFT_GAS,CHOKE_GROUP,SOURCE_SINK_GROUP,NETWORK_VALUE_TYPE | ||
2023-01-01,FIELD,GRUPTREE,,,,,,,,,, | ||
2023-01-01,NODE,GRUPTREE,FIELD,,,,,,,,, | ||
2023-01-01,WELL,WELSPECS,NODE,,,,,,,,, | ||
2023-01-01,FIELD,BRANPROP,,,,,,,,,, | ||
2023-01-01,NODE,BRANPROP,FIELD,9999.0,0.0,NONE,25.0,NO,NO,,,PROD |
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,92 @@ | ||
import datetime | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import pandas as pd | ||
import pytest | ||
from pandas._testing import assert_frame_equal | ||
|
||
from webviz_subsurface._models.gruptree_model import GruptreeModel, TreeType | ||
|
||
CHECK_COLUMNS = ["DATE", "CHILD", "KEYWORD", "PARENT"] | ||
ENSEMBLE = "01_drogon_ahm" | ||
GRUPTREE_FILE = "share/results/tables/gruptree.csv" | ||
|
||
|
||
@pytest.fixture(name="gruptree_model") | ||
def fixture_model(testdata_folder) -> GruptreeModel: | ||
ens_path = Path(testdata_folder) / ENSEMBLE / "realization-*" / "iter-0" | ||
return GruptreeModel( | ||
ens_name="iter-0", | ||
ens_path=ens_path, | ||
gruptree_file=GRUPTREE_FILE, | ||
tree_type="GRUPTREE", | ||
) | ||
|
||
|
||
# Mock class that loads local csv file | ||
class MockGruptreeModel(GruptreeModel): | ||
# pylint: disable=super-init-not-called | ||
def __init__(self, tree_type: Optional[TreeType] = None): | ||
self._tree_type = tree_type | ||
df_files = pd.DataFrame([{"REAL": 0, "FULLPATH": "tests/data/gruptree.csv"}]) | ||
self._dataframe = self.read_ensemble_gruptree(df_files=df_files) | ||
|
||
|
||
@pytest.mark.usefixtures("app") | ||
def test_gruptree_model_init(testdata_folder, gruptree_model: GruptreeModel): | ||
|
||
# Check that there is only one REAL (means that the gruptree is | ||
# the same for all realizations) | ||
assert gruptree_model.dataframe["REAL"].nunique() == 1 | ||
|
||
# Load gruptree table from realization-0 and compare with | ||
# the dataframe from the gruptree_model | ||
r0_path = f"{testdata_folder}/{ENSEMBLE}/realization-0/iter-0/{GRUPTREE_FILE}" | ||
exp_df = pd.read_csv(r0_path) | ||
exp_df["DATE"] = pd.to_datetime(exp_df["DATE"]) | ||
exp_df = exp_df.where(pd.notnull(exp_df), None) | ||
|
||
assert_frame_equal(gruptree_model.dataframe[CHECK_COLUMNS], exp_df[CHECK_COLUMNS]) | ||
|
||
|
||
@pytest.mark.usefixtures("app") | ||
def test_get_filtered_dataframe(gruptree_model: GruptreeModel): | ||
|
||
# Test the get_filtered_dataframe function with terminal node different than FIELD | ||
filtered_df = gruptree_model.get_filtered_dataframe(terminal_node="OP") | ||
filtered_df = filtered_df[ | ||
filtered_df["DATE"] == filtered_df["DATE"].max() | ||
].reset_index() | ||
exp_filtered_df = pd.DataFrame( | ||
columns=["DATE", "CHILD", "KEYWORD", "PARENT"], | ||
data=[ | ||
[datetime.datetime(year=2018, month=11, day=17), "OP", "GRUPTREE", "FIELD"], | ||
[datetime.datetime(year=2018, month=11, day=17), "A1", "WELSPECS", "OP"], | ||
[datetime.datetime(year=2018, month=11, day=17), "A2", "WELSPECS", "OP"], | ||
[datetime.datetime(year=2018, month=11, day=17), "A3", "WELSPECS", "OP"], | ||
[datetime.datetime(year=2018, month=11, day=17), "A4", "WELSPECS", "OP"], | ||
], | ||
) | ||
assert_frame_equal(filtered_df[CHECK_COLUMNS], exp_filtered_df) | ||
|
||
# Test excl_wells_startswith and excl_wells_endswith | ||
assert set( | ||
gruptree_model.get_filtered_dataframe( | ||
excl_well_startswith=["R_"], | ||
excl_well_endswith=["3", "5"], | ||
)["CHILD"].unique() | ||
) == {"FIELD", "OP", "RFT", "WI", "A1", "A2", "A4", "A6"} | ||
|
||
|
||
def test_tree_type_filtering(): | ||
|
||
mock_model = MockGruptreeModel(tree_type=TreeType.GRUPTREE) | ||
assert "BRANPROP" not in mock_model.dataframe["KEYWORD"].unique() | ||
|
||
mock_model = MockGruptreeModel(tree_type=TreeType.BRANPROP) | ||
assert "GRUPTREE" not in mock_model.dataframe["KEYWORD"].unique() | ||
|
||
# If tree_type is defaulted then the BRANPROP tree is selected | ||
mock_model = MockGruptreeModel() | ||
assert "GRUPTREE" not in mock_model.dataframe["KEYWORD"].unique() |
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.