Skip to content

Commit

Permalink
Add filter linking in SimulationTimeseriesOneByOne (#1227)
Browse files Browse the repository at this point in the history
* Add filter linking in SimulationTimeseriesOneByOne

* changelog
  • Loading branch information
tnatt authored Aug 3, 2023
1 parent f841100 commit 051cd97
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED] - YYYY-MM-DD

### Added
- [#1227](https://github.com/equinor/webviz-subsurface/pull/1227) - New functionality in `SimulationTimeSeriesOneByOne`: option to use the sensitivity filter on all visualisations, not only the timeseries.

## [0.2.20] - 2023-06-26

### Added
- [#1217](https://github.com/equinor/webviz-subsurface/pull/1217) - New plugin `SimulationTimeSeriesOneByOne`, meant to replace the old `ReservoirSimulationTimeSeriesOneByOne`. Uses the `.arrow` summary provider and is implemented with WLF (Webviz Layout Framework).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def get_tornado_reference(sensitivities: List[str], existing_reference: str) ->
return "rms_seed"
return sensitivities[0]

@staticmethod
def get_realizations_for_sensitivies(
sens_df: pd.DataFrame, sensitivities: List[str]
) -> List[int]:
return list(sens_df[sens_df["SENSNAME"].isin(sensitivities)]["REAL"].unique())

def create_tornado_figure(
self,
tornado_data: TornadoData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

import webviz_core_components as wcc
from dash import html
from dash.development.base_component import Component
from webviz_config.utils import StrEnum
from webviz_config.webviz_plugin_subclasses import SettingsGroupABC
Expand All @@ -9,17 +10,35 @@
class SensitivityFilter(SettingsGroupABC):
class Ids(StrEnum):
SENSITIVITY_FILTER = "sensitivity-filter"
SENSITIVITY_FILTER_LINK = "sensitivity-filter-link"

def __init__(self, sensitivities: List[str]) -> None:
super().__init__("Sensitivity Filter")
self._sensitivities = sensitivities

def layout(self) -> List[Component]:
return [
html.Div(
style={"margin-bottom": "10px"},
children=[
wcc.Checklist(
id=self.register_component_unique_id(
self.Ids.SENSITIVITY_FILTER_LINK
),
options=[
{
"label": "Apply filter only on timeseries",
"value": "no link",
}
],
value=[],
),
],
),
wcc.SelectWithLabel(
id=self.register_component_unique_id(self.Ids.SENSITIVITY_FILTER),
options=[{"label": i, "value": i} for i in self._sensitivities],
value=self._sensitivities,
size=min(20, len(self._sensitivities)),
)
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _update_options(option_values: list, options_id: List[dict]) -> dict:
def _update_realization_store(sensitivites: list, ensemble: str) -> List[int]:
"""Update graph with line coloring, vertical line and title"""
df = self._data_model.get_sensitivity_dataframe_for_ensemble(ensemble)
return list(df[df["SENSNAME"].isin(sensitivites)]["REAL"].unique())
return self._data_model.get_realizations_for_sensitivies(df, sensitivites)

@callback(
Output(
Expand Down Expand Up @@ -469,6 +469,19 @@ def _update_timeseries_figure(
),
"data",
),
Input(
self.settings_group_unique_id(
self.Ids.SETTINGS, GeneralSettings.Ids.REAL_STORE
),
"data",
),
Input(
self.settings_group_unique_id(
self.Ids.SENSITIVITY_FILTER,
SensitivityFilter.Ids.SENSITIVITY_FILTER_LINK,
),
"value",
),
State(
self.settings_group_unique_id(
self.Ids.SELECTIONS, Selections.Ids.ENSEMBLE
Expand All @@ -478,18 +491,35 @@ def _update_timeseries_figure(
)
@callback_typecheck
def _update_tornadoplot(
date: str, selections: dict, vector: str, ensemble: str
date: str,
selections: dict,
vector: str,
realizations: List[int],
sensfilter_only_timeseries: list,
ensemble: str,
) -> tuple:
if selections is None or selections[
"Reference"
] not in self._data_model.get_unique_sensitivities_for_ensemble(ensemble):
raise PreventUpdate

sens_df = self._data_model.get_sensitivity_dataframe_for_ensemble(ensemble)

# make sure the tornado reference is included if sensitivity filter is used
if not sensfilter_only_timeseries:
reference_realizations = (
self._data_model.get_realizations_for_sensitivies(
sens_df, sensitivities=[selections["Reference"]]
)
)
realizations = list(set(reference_realizations + realizations))

# Get dataframe with vectors and dataframe with parameters and merge
vector_df = self._data_model.get_vectors_df(
ensemble=ensemble,
date=date_from_str(date),
vector_names=[vector],
realizations=realizations if not sensfilter_only_timeseries else None,
)
data = merge_dataframes_on_realization(
dframe1=vector_df,
Expand Down

0 comments on commit 051cd97

Please sign in to comment.