Skip to content

Commit

Permalink
New plot options in ReservoirSimulationTimeSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
asnyv committed Apr 26, 2021
1 parent bc17543 commit 1142f55
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 54 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED] - YYYY-MM-DD
### Changed
- [#612](https://github.com/equinor/webviz-subsurface/pull/612) - New features in ReservoirSimulationTimeSeries: Statistical lines, option to remove history trace, histogram available when plotting individual realizations.

## [0.2.0] - 2021-03-28
### Changed
- [#604](https://github.com/equinor/webviz-subsurface/pull/604) - Consolidates surface loading and statistical calculation of surfaces by introducing a shared
SurfaceSetModel. Refactored SurfaceViewerFMU to use SurfaceSetModel.
- [#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.
- [#599](https://github.com/equinor/webviz-subsurface/pull/599) - Fixed an issue in ParameterAnalysis where the plugin did not initialize without FIELD vectors
- [#599](https://github.com/equinor/webviz-subsurface/pull/599) - Fixed an issue in ParameterAnalysis where the plugin did not initialize without FIELD vectors

### Fixed
- [#602](https://github.com/equinor/webviz-subsurface/pull/602) - Prevent calculation of data for download at initialisation of ReservoirSimulationTimeSeries.
Expand Down
115 changes: 114 additions & 1 deletion webviz_subsurface/_utils/simulation_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ def p10(x: List[float]) -> List[float]:
def p90(x: List[float]) -> List[float]:
return np.nanpercentile(x, q=10)

def p50(x: List[float]) -> List[float]:
return np.nanpercentile(x, q=50)

# Calculate statistics, ignoring NaNs.
stat_df = (
df[["ENSEMBLE", refaxis] + vectors]
.groupby(["ENSEMBLE", refaxis])
.agg([np.nanmean, np.nanmin, np.nanmax, p10, p90])
.agg([np.nanmean, np.nanmin, np.nanmax, p10, p90, p50])
.reset_index(level=["ENSEMBLE", refaxis], col_level=1)
)
# Rename nanmin, nanmax and nanmean to min, max and mean.
Expand All @@ -76,6 +79,7 @@ def p90(x: List[float]) -> List[float]:
"nanmean": "mean",
"p10": "high_p10",
"p90": "low_p90",
"p50": "p50",
}
stat_df.rename(columns=col_stat_label_map, level=1, inplace=True)

Expand Down Expand Up @@ -156,6 +160,115 @@ def add_fanchart_traces(
]


def add_statistics_traces(
ens_stat_df: pd.DataFrame,
vector: str,
stat_options: List[str],
color: str,
legend_group: str,
line_shape: str,
refaxis: str = "DATE",
hovertemplate: str = "(%{x}, %{y})<br>",
) -> List[Dict[str, Any]]:
"""Renders a statistical lines for each vector"""
traces = []
for i, opt in enumerate(stat_options):
if opt == "Mean":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "Mean",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "mean")],
"mode": "lines",
"line": {"color": color, "shape": line_shape, "width": 3},
"legendgroup": legend_group,
"showlegend": True,
}
)
if opt == "P10 (high)":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "P10",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "high_p10")],
"mode": "lines",
"line": {"color": color, "shape": line_shape, "dash": "dashdot"},
"legendgroup": legend_group,
"showlegend": False if "Mean" in stat_options else i == 0,
}
)
if opt == "P90 (low)":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "P90",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "low_p90")],
"mode": "lines",
"line": {"color": color, "shape": line_shape, "dash": "dashdot"},
"legendgroup": legend_group,
"showlegend": False if "Mean" in stat_options else i == 0,
}
)
if opt == "P50 (median)":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "P50",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "p50")],
"mode": "lines",
"line": {
"color": color,
"shape": line_shape,
"dash": "dot",
"width": 3,
},
"legendgroup": legend_group,
"showlegend": False if "Mean" in stat_options else i == 0,
}
)
if opt == "Maximum":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "Maximum",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "max")],
"mode": "lines",
"line": {
"color": color,
"shape": line_shape,
"dash": "longdash",
"width": 1.5,
},
"legendgroup": legend_group,
"showlegend": False if "Mean" in stat_options else i == 0,
}
)
if opt == "Minimum":
traces.append(
{
"name": legend_group,
"hovertemplate": hovertemplate + "Minimum",
"x": ens_stat_df[("", refaxis)],
"y": ens_stat_df[(vector, "min")],
"mode": "lines",
"line": {
"color": color,
"shape": line_shape,
"dash": "longdash",
"width": 1.5,
},
"legendgroup": legend_group,
"showlegend": False if "Mean" in stat_options else i == 0,
}
)
return traces


def render_hovertemplate(vector: str, interval: Optional[str]) -> str:
if vector.startswith(("AVG_", "INTVL_")) and interval is not None:
if interval == "daily":
Expand Down
Loading

0 comments on commit 1142f55

Please sign in to comment.