Skip to content

Commit

Permalink
ParameterResponseParallelCoordinates plugin. (#410)
Browse files Browse the repository at this point in the history
Co-authored-by: VegardOztan <[email protected]>
Co-authored-by: JosteinGj <[email protected]>
Co-authored-by: saraa394 <[email protected]>
Co-authored-by: sofieaasheim <[email protected]>
  • Loading branch information
5 people authored Aug 21, 2020
1 parent c671fb8 commit db6173e
Show file tree
Hide file tree
Showing 2 changed files with 569 additions and 82 deletions.
48 changes: 48 additions & 0 deletions webviz_subsurface/_utils/parameter_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from webviz_config.common_cache import CACHE
import numpy as np


@CACHE.memoize(timeout=CACHE.TIMEOUT)
def filter_and_sum_responses(
dframe, ensemble, response, filteroptions=None, aggregation="sum"
):
"""Cached wrapper for _filter_and_sum_responses"""
return _filter_and_sum_responses(
dframe=dframe,
ensemble=ensemble,
response=response,
filteroptions=filteroptions,
aggregation=aggregation,
)


def _filter_and_sum_responses(
dframe, ensemble, response, filteroptions=None, aggregation="sum",
):
"""Filter response dataframe for the given ensemble
and optional filter columns. Returns dataframe grouped and
aggregated per realization.
"""
df = dframe.copy()
df = df.loc[df["ENSEMBLE"] == ensemble]
if filteroptions:
for opt in filteroptions:
if opt["type"] == "multi" or opt["type"] == "single":
if isinstance(opt["values"], list):
df = df.loc[df[opt["name"]].isin(opt["values"])]
else:
if opt["name"] == "DATE" and isinstance(opt["values"], str):
df = df.loc[df["DATE"].astype(str) == opt["values"]]
else:
df = df.loc[df[opt["name"]] == opt["values"]]

elif opt["type"] == "range":
df = df.loc[
(df[opt["name"]] >= np.min(opt["values"]))
& (df[opt["name"]] <= np.max(opt["values"]))
]
if aggregation == "sum":
return df.groupby("REAL").sum().reset_index()[["REAL", response]]
if aggregation == "mean":
return df.groupby("REAL").mean().reset_index()[["REAL", response]]
raise ValueError(f"Unknown aggregation '{aggregation}'.")
Loading

0 comments on commit db6173e

Please sign in to comment.