-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ParameterResponseParallelCoordinates plugin. (#410)
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
1 parent
c671fb8
commit db6173e
Showing
2 changed files
with
569 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}'.") |
Oops, something went wrong.