Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precalculation of statistical surfaces in StructuralUncertainty #1159

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions webviz_subsurface/_models/surface_set_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def calculate_statistical_surface(

def webviz_store_statistical_calculation(
self,
attribute: str,
name: str,
calculation: Optional[str] = "Mean",
realizations: Optional[List[int]] = None,
) -> Tuple[Callable, list]:
Expand All @@ -153,25 +155,24 @@ def webviz_store_statistical_calculation(
if realizations is not None
else self._surface_table
)
df = df.loc[df["attribute"] == attribute]
df = df.loc[df["name"] == name]
stored_functions_args = []
for _attr, attr_df in df.groupby("attribute"):
for _name, name_df in attr_df.groupby("name"):

if name_df["date"].isnull().values.all():
stored_functions_args.append(
{
"fns": sorted(list(name_df["path"].unique())),
"calculation": calculation,
}
)
else:
for _date, date_df in name_df.groupby("date"):
stored_functions_args.append(
{
"fns": sorted(list(date_df["path"].unique())),
"calculation": calculation,
}
)
if df["date"].isnull().values.all():
stored_functions_args.append(
{
"fns": sorted(list(df["path"].unique())),
"calculation": calculation,
}
)
else:
for _date, date_df in df.groupby("date"):
stored_functions_args.append(
{
"fns": sorted(list(date_df["path"].unique())),
"calculation": calculation,
}
)

return (
save_statistical_surface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def update_intersection(
app: Dash,
get_uuid: Callable,
surface_set_models: Dict[str, SurfaceSetModel],
all_realizations: List[int],
well_set_model: WellSetModel,
color_picker: ColorPicker,
zonelog: Optional[str] = None,
Expand Down Expand Up @@ -134,7 +135,9 @@ def _store_intersection_traces(
legendname=f"{surfacename}({ensemble})",
name=surfacename,
attribute=surfaceattribute,
realizations=realizations,
realizations=realizations
if set(realizations) != set(all_realizations)
else None,
showlegend=showlegend,
color=color,
)
Expand All @@ -147,7 +150,9 @@ def _store_intersection_traces(
legendname=f"{surfacename}({ensemble})",
name=surfacename,
attribute=surfaceattribute,
realizations=realizations,
realizations=realizations
if set(realizations) != set(all_realizations)
else None,
showlegend=showlegend,
color=color,
)
Expand All @@ -172,7 +177,6 @@ def _store_intersection_traces(
traces.append(get_plotly_trace_well_trajectory(well))
if well.zonelogname is not None:
traces.extend(get_plotly_zonelog_trace(well, zonelog))

return traces

@app.callback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from typing import Any, Dict, List, Optional

import numpy as np
Expand All @@ -16,13 +15,6 @@
)


class FanChartStatistics(str, Enum):
MINIMUM = "Min"
MAXIMUM = "Max"
P10 = "P10"
P90 = "P90"


# pylint: disable=too-many-arguments
@CACHE.memoize(timeout=CACHE.TIMEOUT)
def get_plotly_trace_statistical_surface(
Expand Down Expand Up @@ -79,7 +71,7 @@ def get_plotly_traces_uncertainty_envelope(
for a surface"""
values_for_fanchart: Dict[str, np.ma.MaskedArray] = {}
fan_chart_traces: List = []
for calculation in FanChartStatistics:
for calculation in ["P10", "P90", "Min", "Max"]:
values = surfaceset.calculate_statistical_surface(
name=name,
attribute=attribute,
Expand All @@ -89,30 +81,28 @@ def get_plotly_traces_uncertainty_envelope(
# Convert to masked array
values = np.ma.masked_array(values, mask=np.isnan(values))

if calculation == FanChartStatistics.MINIMUM:
if calculation == "Min":
values_for_fanchart["x"] = values[:, 0]
values_for_fanchart[FanChartStatistics(calculation)] = values[:, 1]
values_for_fanchart[calculation] = values[:, 1]

# Fanchart plotting requires continuous data series.
# 1. Create a slice for each non-masked section of y(depth) values.
# As the mask is the same for all statistical surfaces,
# the minimum surface is randomly used.
# 2. Make a set of fanchart traces for each slice.

for unmasked_slice in np.ma.clump_unmasked(
values_for_fanchart[FanChartStatistics.MINIMUM]
):
for unmasked_slice in np.ma.clump_unmasked(values_for_fanchart["Min"]):
fan_chart_data = FanchartData(
samples=values_for_fanchart["x"][unmasked_slice],
low_high=LowHighData(
low_data=values_for_fanchart[FanChartStatistics.P10][unmasked_slice],
low_name=FanChartStatistics.P10,
high_data=values_for_fanchart[FanChartStatistics.P90][unmasked_slice],
high_name=FanChartStatistics.P90,
low_data=values_for_fanchart["P10"][unmasked_slice],
low_name="P10",
high_data=values_for_fanchart["P90"][unmasked_slice],
high_name="P90",
),
minimum_maximum=MinMaxData(
minimum=values_for_fanchart[FanChartStatistics.MINIMUM][unmasked_slice],
maximum=values_for_fanchart[FanChartStatistics.MAXIMUM][unmasked_slice],
minimum=values_for_fanchart["Min"][unmasked_slice],
maximum=values_for_fanchart["Max"][unmasked_slice],
),
)
fan_chart_traces.extend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def __init__(
ens: SurfaceSetModel(surf_ens_df)
for ens, surf_ens_df in surface_table.groupby("ENSEMBLE")
}
self._realizations = sorted(list(surface_table["REAL"].unique()))
self._realizations = [
int(real) for real in sorted(list(surface_table["REAL"].unique()))
]

self._zonelog = zonelog
colors = [
Expand Down Expand Up @@ -380,6 +382,7 @@ def set_callbacks(self, app: Dash) -> None:
app=app,
get_uuid=self.uuid,
surface_set_models=self._surface_ensemble_set_model,
all_realizations=self._realizations,
well_set_model=self._well_set_model,
zonelog=self._zonelog,
color_picker=self._color_picker,
Expand Down Expand Up @@ -425,11 +428,29 @@ def add_webvizstore(self) -> List[Tuple[Callable, list]]:
for ens in self.ensembles:

for calculation in calculations:
store_functions.append(
self._surface_ensemble_set_model[
ens
].webviz_store_statistical_calculation(calculation=calculation)
)
for surf_attr in self._surf_attrs:
for surf_name in self._surfacenames:
store_functions.append(
self._surface_ensemble_set_model[
ens
].webviz_store_statistical_calculation(
attribute=surf_attr,
name=surf_name,
calculation=calculation,
realizations=None,
)
)
print(
self._surface_ensemble_set_model[
ens
].webviz_store_statistical_calculation(
attribute=surf_attr,
name=surf_name,
calculation=calculation,
realizations=None,
)
)

store_functions.append(
self._surface_ensemble_set_model[
ens
Expand All @@ -450,4 +471,5 @@ def add_webvizstore(self) -> List[Tuple[Callable, list]]:
store_functions.append(
(find_files, [{"folder": self._wellfolder, "suffix": self._wellsuffix}])
)

return store_functions
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Callable, Dict, List, Union
from typing import Callable, Dict, List

from dash import dcc, html


def clientside_stores(
get_uuid: Callable,
initial_settings: Dict,
realizations: List[Union[str, int]],
realizations: List[int],
) -> html.Div:
"""Contains the clientside stores"""
return html.Div(
Expand Down
14 changes: 9 additions & 5 deletions webviz_subsurface/plugins/_surface_viewer_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,15 @@ def add_webvizstore(self) -> List[Tuple[Callable, list]]:
]
for ens in list(self.ens_df["ENSEMBLE"].unique()):
for calculation in ["Mean", "StdDev", "Min", "Max"]:
store_functions.append(
self._surface_ensemble_set_model[
ens
].webviz_store_statistical_calculation(calculation=calculation)
)
for attr, vals in self.surfaceconfig.items():
for name in vals["names"]:
store_functions.append(
self._surface_ensemble_set_model[
ens
].webviz_store_statistical_calculation(
calculation=calculation, attribute=attr, name=name
)
)
store_functions.append(
self._surface_ensemble_set_model[
ens
Expand Down