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

Parallel coordinates to WLF #1084

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
add remove constant func from jincheng
  • Loading branch information
Eirik Sundby Håland (OG SUB RPE) committed Jul 14, 2022
commit 43b158f58ebd85c20cb1650d0a59cc2c75594786
Original file line number Diff line number Diff line change
@@ -248,6 +248,9 @@ def __init__(
self.add_store(
PluginIds.Stores.ACTIVE_VIEW, WebvizPluginABC.StorageType.SESSION
)
self.add_store(
PluginIds.Stores.REMOVE_CONSTANT, WebvizPluginABC.StorageType.SESSION
)

self.add_shared_settings_group(
Filter(
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ class Stores:
SELECTED_RESPONSE = "slected-response"
SELECTED_DATE = "selected-date"
ACTIVE_VIEW = "active-view"
REMOVE_CONSTANT = "remove-constant"

class SharedSettings:
# pylint: disable=too-few-public-methods
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ class Ids:
PARAMETERS = "parameters"
ACTIVE_VIEW = "active-view"
ENSEMBLE_BOX = "ensemble-box"
REMOVE_CONSTANT = "remove-constant"

def __init__(
self,
@@ -71,6 +72,18 @@ def layout(self) -> List[Component]:
size=min(len(self.parameter_columns), 15),
value=[],
),
wcc.Checklist(
id=self.register_component_unique_id(
Filter.Ids.REMOVE_CONSTANT
),
options=[
{
"label": " Remove constant values",
"value": "remove_constant",
},
],
value=[],
),
],
),
]
@@ -142,3 +155,13 @@ def _set_ensembles(selected_excl_incl: str) -> str:
)
def _set_ensembles(selected_parameters: str) -> str:
return selected_parameters

@callback(
Output(self.get_store_unique_id(PluginIds.Stores.REMOVE_CONSTANT), "data"),
Input(
self.component_unique_id(Filter.Ids.REMOVE_CONSTANT).to_string(),
"value",
),
)
def _update_remove_store(selected_remove: str) -> str:
return selected_remove
Original file line number Diff line number Diff line change
@@ -51,11 +51,13 @@ def set_callbacks(self) -> None:
self.get_store_unique_id(PluginIds.Stores.SELECTED_PARAMETERS),
"data",
),
Input(self.get_store_unique_id(PluginIds.Stores.REMOVE_CONSTANT), "data"),
)
def _update_plot(
ensemble: str,
exclude_include: str,
parameters: List[str],
remove_constant: str,
) -> dict:
ensemble = ensemble if isinstance(ensemble, list) else [ensemble]
parameters = parameters if isinstance(parameters, list) else [parameters]
@@ -87,4 +89,5 @@ def _update_plot(
"ensemble",
params,
"",
remove_constant,
)
Original file line number Diff line number Diff line change
@@ -147,12 +147,14 @@ def set_callbacks(self) -> None:
self.get_store_unique_id(PluginIds.Stores.SELECTED_PARAMETERS),
"data",
),
Input(self.get_store_unique_id(PluginIds.Stores.REMOVE_CONSTANT), "data"),
self.parcoord_inputs,
)
def _update_plot(
ensemble: List[str],
exclude_include: str,
parameters: List[str],
remove_constant: str,
*opt_args,
) -> dict:
ensemble = ensemble if isinstance(ensemble, list) else [ensemble]
@@ -200,4 +202,5 @@ def _update_plot(
"response",
params,
response,
remove_constant,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List

import numpy as np
import pandas as pd
from webviz_config import WebvizConfigTheme

@@ -13,16 +12,36 @@ def render_parcoord(
mode: str,
params: list,
response: str,
remove_constant: str,
):
"""Renders parallel coordinates plot"""

dimensions = []
dimentions_params = []

if remove_constant == ["remove_constant"]:
for param in params:
if len(np.unique(plot_df[param].values)) > 1:
dimentions_params.append(param)

dimensions = [
{"label": param, "values": plot_df[param].values.tolist()}
for param in dimentions_params
]

else:
dimensions = [
{"label": param, "values": plot_df[param].values.tolist()}
for param in params
]

colormap = (
colormap if mode == "ensemble" else theme.plotly_theme["layout"]["colorway"]
)
if response:
response = f"Response: {response}"
params = [response] + params
# Create parcoords dimensions (one per parameter)
dimensions = [{"label": param, "values": plot_df[param]} for param in params]
data = [
{
"line": {
@@ -70,8 +89,3 @@ def render_parcoord(
width = len(dimensions) * 80 + 250
layout = {"width": width, "height": 1200, "margin": {"b": 740, "t": 30}}
return {"data": data, "layout": theme.create_themed_layout(layout)}


def remove_constants(df: pd.DataFrame):
for i in range(len(df.columns)):
print(i)