Skip to content

Commit

Permalink
added realplot to tornadopage in VolumetricAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt committed Nov 18, 2021
1 parent 39ad4bc commit 8eec3e1
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED] - YYYY-MM-DD

### Added
- [#845](https://github.com/equinor/webviz-subsurface/pull/845) - Added realization plot colored by sensitivity to tornado tab in `VolumetricAnalysis`.

### Changed
- [#844](https://github.com/equinor/webviz-subsurface/pull/844) - `SeismicMisfit` improvements. Data ranges now follows selected attribute. User defined zooms are now kept during callbacks. New option in slice plot to show individual realizations. Prettyfied all hoverdata. New colorscales. Polygons sorted by name in drop down selector.

Expand Down
28 changes: 4 additions & 24 deletions webviz_subsurface/_components/tornado/_tornado_bar_chart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

import pandas as pd
import plotly.graph_objects as go
Expand All @@ -18,7 +18,7 @@ def __init__(
plotly_theme: Dict[str, Any],
figure_height: Optional[int] = None,
label_options: str = "detailed",
locked_si_prefix: Optional[int] = None,
locked_si_prefix: Optional[Union[int, str]] = None,
number_format: str = "",
unit: str = "",
spaced: bool = True,
Expand All @@ -29,14 +29,14 @@ def __init__(
sensitivity_color_map: dict = None,
) -> None:
self._tornadotable = tornado_data.tornadotable
self._realtable = self.make_points(tornado_data.real_df)
self._realtable = tornado_data.real_df
self._reference_average = tornado_data.reference_average
self._plotly_theme = plotly_theme
self._number_format = number_format
self._unit = unit
self._spaced = spaced
self._locked_si_prefix = locked_si_prefix
self._locked_si_prefix_relative: Optional[int]
self._locked_si_prefix_relative: Optional[Union[str, int]]
self._scale = tornado_data.scale
self._use_true_base = use_true_base
self._show_reference = show_reference
Expand All @@ -59,26 +59,6 @@ def create_color_list(self, sensitivities: list) -> list:
else self._plotly_theme["layout"]["colorway"]
)

def make_points(self, realdf: pd.DataFrame) -> pd.DataFrame:
dfs = []
for sensname in self._tornadotable["sensname"].unique():
for case in ["high", "low"]:
df = realdf.loc[
realdf["REAL"].isin(
self._tornadotable[self._tornadotable["sensname"] == sensname][
f"{case}_reals"
].iloc[0]
)
].copy()
df["sensname"] = sensname
df["case"] = case
dfs.append(df)
return (
pd.concat(dfs)
if dfs
else pd.DataFrame(columns=["REAL", "sensname", "case"])
)

@property
def figure_height(self) -> Optional[int]:
"""Set height of figure as a function of number of senscases(bars)"""
Expand Down
26 changes: 25 additions & 1 deletion webviz_subsurface/_components/tornado/_tornado_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict, List, Union

import numpy as np
import pandas as pd


Expand All @@ -23,7 +24,7 @@ def __init__(
if cutbyref:
self._cut_sensitivities_by_ref()
self._sort_sensitivities_by_max()
self._real_df = dframe[["REAL", "VALUE"]]
self._real_df = self._create_real_df(dframe)

def _validate_input(self, dframe: pd.DataFrame) -> None:
for col in self.REQUIRED_COLUMNS:
Expand All @@ -43,6 +44,29 @@ def _validate_input(self, dframe: pd.DataFrame) -> None:
if dframe.loc[dframe["SENSNAME"].isin([self._reference])].empty:
raise ValueError(f"Reference SENSNAME {self._reference} not in input data")

def _create_real_df(self, dframe: pd.DataFrame) -> pd.DataFrame:
"""Make dataframe with value and case info per realization"""
realdf = dframe[self.REQUIRED_COLUMNS].rename(
columns={"SENSNAME": "sensname", "SENSCASE": "senscase"}
)

sensitivities = self._tornadotable["sensname"].unique()
realdf = realdf.loc[realdf["sensname"].isin(sensitivities)]

for val in self.low_high_realizations_list.values():
for case in ["high", "low"]:
casemask = realdf["REAL"].isin(val[f"real_{case}"])
realdf.loc[casemask, "case"] = case

mc_mask = realdf["SENSTYPE"] == "mc"
realdf["casetype"] = np.where(mc_mask, "mc", realdf["case"])
realdf["sensname_case"] = np.where(
mc_mask,
realdf["sensname"],
realdf[["sensname", "senscase"]].agg("--".join, axis=1),
)
return realdf

@property
def real_df(self) -> pd.DataFrame:
return self._real_df
Expand Down
28 changes: 18 additions & 10 deletions webviz_subsurface/_components/tornado/_tornado_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Dict, List
from typing import Dict, List, Union

from dash.dash_table.Format import Format

from ._tornado_data import TornadoData

Expand All @@ -9,10 +11,13 @@ class TornadoTable:
def __init__(
self,
tornado_data: TornadoData,
use_si_format: bool = True,
precision: int = 4,
) -> None:
self._table = tornado_data.tornadotable.copy()
self.scale = tornado_data.scale

self._use_si_format = use_si_format
self._precision = precision
self._table["low_reals"] = self._table["low_reals"].apply(lambda x: str(len(x)))
self._table["high_reals"] = self._table["high_reals"].apply(
lambda x: str(len(x))
Expand All @@ -31,21 +36,24 @@ def __init__(
inplace=True,
)

def set_column_format(self, col: str) -> Union[dict, Format]:
if "%" in col:
return {"specifier": ".1f"}
if self._use_si_format:
return {
"locale": {"symbol": ["", ""]},
"specifier": f"$.{self._precision}s",
}
return Format(precision=self._precision)

@property
def columns(self) -> List[Dict]:
return [
{
"name": col,
"id": col,
"type": "numeric",
"format": {
"locale": {"symbol": ["", ""]},
"specifier": "$.4s",
}
if not "%" in col
else {
"specifier": ".1f",
},
"format": self.set_column_format(col),
}
for col in [
"Response",
Expand Down
Loading

0 comments on commit 8eec3e1

Please sign in to comment.