From 0bc48147a433f62b27fa9c7259005036e8857c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Lind-Johansen?= <47847084+lindjoha@users.noreply.github.com> Date: Mon, 5 Dec 2022 08:14:22 +0100 Subject: [PATCH] Split settings groups in `RftPlotter` (#1180) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Split selections into plot_type and ensembles * Renames Selections to Ensembles * removed print * Removed len > 0 to check if lists are not empty Co-authored-by: Øyvind Lind-Johansen --- .../_settings/_formation_plot_settings.py | 8 +++--- .../_views/_misfit_per_real_view/_settings.py | 2 +- .../_views/_parameter_response_view/_view.py | 1 - .../_sim_vs_obs_view/_settings/__init__.py | 3 ++- .../_sim_vs_obs_view/_settings/_ensembles.py | 26 +++++++++++++++++++ .../{_selections.py => _plot_type.py} | 17 +++--------- .../_views/_sim_vs_obs_view/_view.py | 16 +++++++----- 7 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_ensembles.py rename webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/{_selections.py => _plot_type.py} (60%) diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_map_view/_settings/_formation_plot_settings.py b/webviz_subsurface/plugins/_rft_plotter/_views/_map_view/_settings/_formation_plot_settings.py index a55a52123..9238dcb88 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_map_view/_settings/_formation_plot_settings.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_map_view/_settings/_formation_plot_settings.py @@ -25,8 +25,8 @@ def __init__(self, datamodel: RftPlotterDataModel) -> None: self._well_names = datamodel.well_names def layout(self) -> List[Component]: - ensemble = self._ensembles[0] if len(self._ensembles) > 0 else None - well = self._well_names[0] if len(self._well_names) > 0 else None + ensemble = self._ensembles[0] if self._ensembles else None + well = self._well_names[0] if self._well_names else None dates_in_well = self._datamodel.date_in_well(well) if well is not None else [] return [ wcc.Dropdown( @@ -49,7 +49,7 @@ def layout(self) -> List[Component]: id=self.register_component_unique_id(self.Ids.DATE), options=[{"label": date, "value": date} for date in dates_in_well], clearable=False, - value=dates_in_well[0] if len(dates_in_well) > 0 else None, + value=dates_in_well[0] if dates_in_well else None, ), wcc.RadioItems( label="Plot simulations as", @@ -154,7 +154,7 @@ def _update_date( well: str, current_date: str ) -> Tuple[List[Dict[str, str]], Optional[str]]: dates = self._datamodel.date_in_well(well) - first_date = dates[0] if len(dates) > 0 else None + first_date = dates[0] if dates else None available_dates = [{"label": date, "value": date} for date in dates] date = current_date if current_date in dates else first_date return available_dates, date diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_misfit_per_real_view/_settings.py b/webviz_subsurface/plugins/_rft_plotter/_views/_misfit_per_real_view/_settings.py index f6c37f460..29683b7af 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_misfit_per_real_view/_settings.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_misfit_per_real_view/_settings.py @@ -20,7 +20,7 @@ def layout(self) -> List[Component]: label="Ensembles", id=self.register_component_unique_id(self.Ids.ENSEMBLES), options=[{"label": ens, "value": ens} for ens in self._ensembles], - value=[self._ensembles[0] if len(self._ensembles) > 0 else None], + value=[self._ensembles[0] if self._ensembles else None], clearable=False, multi=True, ), diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_parameter_response_view/_view.py b/webviz_subsurface/plugins/_rft_plotter/_views/_parameter_response_view/_view.py index ae1b3d8cd..a3dae6059 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_parameter_response_view/_view.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_parameter_response_view/_view.py @@ -103,7 +103,6 @@ def _update_selections_from_clickdata( clickdata = corr_vector_clickdata.get("points", [{}])[0].get("y") ls_clickdata = clickdata.split() - print("click dat ais: ", ls_clickdata) return ls_clickdata[0] @callback( diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/__init__.py b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/__init__.py index 18ad93440..d862a2a6c 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/__init__.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/__init__.py @@ -1,2 +1,3 @@ -from ._selections import PlotType, Selections +from ._ensembles import Ensembles +from ._plot_type import PlotType, PlotTypeSettings from ._size_color_settings import SizeColorSettings diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_ensembles.py b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_ensembles.py new file mode 100644 index 000000000..c8c8201ad --- /dev/null +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_ensembles.py @@ -0,0 +1,26 @@ +from typing import List + +import webviz_core_components as wcc +from dash.development.base_component import Component +from webviz_config.utils import StrEnum +from webviz_config.webviz_plugin_subclasses import SettingsGroupABC + + +class Ensembles(SettingsGroupABC): + class Ids(StrEnum): + ENSEMBLES = "ensembles" + + def __init__(self, ensembles: List[str]) -> None: + super().__init__("Ensembles") + self._ensembles = ensembles + + def layout(self) -> List[Component]: + return [ + wcc.Dropdown( + id=self.register_component_unique_id(self.Ids.ENSEMBLES), + options=[{"label": ens, "value": ens} for ens in self._ensembles], + value=[self._ensembles[0] if self._ensembles else None], + clearable=False, + multi=True, + ), + ] diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_selections.py b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_plot_type.py similarity index 60% rename from webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_selections.py rename to webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_plot_type.py index 4c37e9135..85f7a4cb5 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_selections.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_settings/_plot_type.py @@ -11,19 +11,16 @@ class PlotType(StrEnum): ERROR_BOXPLOT = "error-boxplot" -class Selections(SettingsGroupABC): +class PlotTypeSettings(SettingsGroupABC): class Ids(StrEnum): PLOT_TYPE = "plot-type" - ENSEMBLES = "ensembles" - def __init__(self, ensembles: List[str]) -> None: - super().__init__("Selections") - self._ensembles = ensembles + def __init__(self) -> None: + super().__init__("Plot Type") def layout(self) -> List[Component]: return [ wcc.RadioItems( - label="Plot Type", id=self.register_component_unique_id(self.Ids.PLOT_TYPE), options=[ { @@ -37,12 +34,4 @@ def layout(self) -> List[Component]: ], value=PlotType.CROSSPLOT, ), - wcc.Dropdown( - label="Ensembles", - id=self.register_component_unique_id(self.Ids.ENSEMBLES), - options=[{"label": ens, "value": ens} for ens in self._ensembles], - value=[self._ensembles[0] if len(self._ensembles) > 0 else None], - clearable=False, - multi=True, - ), ] diff --git a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_view.py b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_view.py index 36ae52dfc..5669479fd 100644 --- a/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_view.py +++ b/webviz_subsurface/plugins/_rft_plotter/_views/_sim_vs_obs_view/_view.py @@ -9,13 +9,14 @@ from ..._reusable_view_element import GeneralViewElement from ..._types import ColorAndSizeByType from ..._utils import RftPlotterDataModel, filter_frame -from ._settings import PlotType, Selections, SizeColorSettings +from ._settings import Ensembles, PlotType, PlotTypeSettings, SizeColorSettings from ._utils import update_crossplot, update_errorplot class SimVsObsView(ViewABC): class Ids(StrEnum): - SELECTIONS = "selections" + PLOT_TYPE = "plot-type" + ENSEMBLES = "ensembles" FILTERS = "filters" SIZE_COLOR_SETTINGS = "size-color-settings" VIEW_ELEMENT = "view-element" @@ -26,7 +27,8 @@ def __init__(self, datamodel: RftPlotterDataModel) -> None: self.add_settings_groups( { - self.Ids.SELECTIONS: Selections(self._datamodel.ensembles), + self.Ids.PLOT_TYPE: PlotTypeSettings(), + self.Ids.ENSEMBLES: Ensembles(self._datamodel.ensembles), self.Ids.FILTERS: FilterLayout( wells=self._datamodel.well_names, zones=self._datamodel.zone_names, @@ -47,14 +49,14 @@ def set_callbacks(self) -> None: "children", ), Input( - self.settings_group(self.Ids.SELECTIONS) - .component_unique_id(Selections.Ids.PLOT_TYPE) + self.settings_group(self.Ids.PLOT_TYPE) + .component_unique_id(PlotTypeSettings.Ids.PLOT_TYPE) .to_string(), "value", ), Input( - self.settings_group(self.Ids.SELECTIONS) - .component_unique_id(Selections.Ids.ENSEMBLES) + self.settings_group(self.Ids.ENSEMBLES) + .component_unique_id(Ensembles.Ids.ENSEMBLES) .to_string(), "value", ),