Skip to content

Commit

Permalink
Use new WebvizSettings instead of dictionary piggybacked onto app obj…
Browse files Browse the repository at this point in the history
…ect (#544)

Use new WebvizSettings instead of dictionary piggybacked onto app object
  • Loading branch information
sigurdp authored Jan 22, 2021
1 parent fdc63ed commit 651e89a
Show file tree
Hide file tree
Showing 30 changed files with 140 additions and 82 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED] - YYYY-MM-DD
### Changed
- [#544](https://github.com/equinor/webviz-subsurface/pull/544) - All plugins now use new special `webviz_settings` argument to plugin's `__init__` method for common settings in favor of piggybacking dictionary onto the to the Dash applicaton object.

### Fixed
- [#536](https://github.com/equinor/webviz-subsurface/pull/536) - Fixed issue and bumped dependencies related to Pandas version 1.2.0. Bumped dependency to webviz-config to support mypy typechecks.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"pyscal>=0.7.2",
"scipy>=1.2",
"statsmodels>=0.12.1", # indirect dependency through https://plotly.com/python/linear-fits/
"webviz-config>=0.2.6",
"webviz-config>=0.2.7",
"webviz-subsurface-components>=0.2.0",
"xtgeo>=2.8",
],
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/test_parameter_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
from webviz_config.common_cache import CACHE
from webviz_config.themes import default_theme
from webviz_config import WebvizSettings

# pylint: disable=no-name-in-module
from webviz_config.plugins import (
Expand All @@ -22,16 +23,15 @@ def test_parameter_corr(dash_duo: dash.testing.composite.DashComposite) -> None:
app.scripts.config.serve_locally = True
app.config.suppress_callback_exceptions = True
CACHE.init_app(app.server)
app.webviz_settings = {
"shared_settings": {"scratch_ensembles": {"iter-0": ""}},
"theme": default_theme,
}
webviz_settings = WebvizSettings(
shared_settings={"scratch_ensembles": {"iter-0": ""}}, theme=default_theme
)
ensembles = ["iter-0"]

with mock.patch(GET_PARAMETERS) as mock_parameters:
mock_parameters.return_value = pd.read_csv("tests/data/parameters.csv")

parameter_correlation = ParameterCorrelation(app, ensembles)
parameter_correlation = ParameterCorrelation(app, webviz_settings, ensembles)

app.layout = parameter_correlation.layout
dash_duo.start_server(app)
Expand Down
4 changes: 3 additions & 1 deletion webviz_subsurface/_private_plugins/tornado_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dash_core_components as dcc
import webviz_core_components as wcc
from webviz_config.common_cache import CACHE
from webviz_config import WebvizSettings

from .._abbreviations.number_formatting import si_prefixed

Expand Down Expand Up @@ -52,6 +53,7 @@ class TornadoPlot:
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
realizations: pd.DataFrame,
reference: str = "rms_seed",
allow_click: bool = False,
Expand All @@ -71,7 +73,7 @@ def __init__(
)
self.allow_click = allow_click
self.uid = uuid4()
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
self.plotly_theme = webviz_settings.theme.plotly_theme
self.set_callbacks(app)

def ids(self, element: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings
from webviz_config.common_cache import CACHE
from webviz_config.webviz_store import webvizstore
import webviz_core_components as wcc
Expand Down Expand Up @@ -39,12 +40,12 @@ class AssistedHistoryMatchingAnalysis(WebvizPluginABC):
"""

def __init__(self, app, input_dir: Path):
def __init__(self, app, webviz_settings: WebvizSettings, input_dir: Path):

super().__init__()

self.input_dir = input_dir
self.theme = app.webviz_settings["theme"]
self.theme = webviz_settings.theme

self.set_callbacks(app)

Expand Down
6 changes: 4 additions & 2 deletions webviz_subsurface/plugins/_bhp_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import webviz_core_components as wcc
from webviz_config.common_cache import CACHE
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings

from webviz_subsurface._models import EnsembleSetModel
from .._utils.unique_theming import unique_colors
Expand Down Expand Up @@ -37,6 +38,7 @@ class BhpQc(WebvizPluginABC):
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
ensembles: list,
wells: Optional[List[str]] = None,
):
Expand All @@ -48,14 +50,14 @@ def __init__(

self.emodel = EnsembleSetModel(
ensemble_paths={
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][ens]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}
)
self.smry = self.emodel.load_smry(
time_index="raw", column_keys=self.column_keys
)
self.theme = app.webviz_settings["theme"]
self.theme = webviz_settings.theme
self.set_callbacks(app)

@property
Expand Down
9 changes: 6 additions & 3 deletions webviz_subsurface/plugins/_disk_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import datetime

import pandas as pd
import dash
import dash_html_components as html
import webviz_core_components as wcc
from webviz_config.webviz_store import webvizstore
from webviz_config.common_cache import CACHE
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings


class DiskUsage(WebvizPluginABC):
Expand All @@ -34,7 +34,10 @@ class DiskUsage(WebvizPluginABC):
"""

def __init__(
self, app: dash.Dash, scratch_dir: pathlib.Path, date: Optional["str"] = None
self,
webviz_settings: WebvizSettings,
scratch_dir: pathlib.Path,
date: Optional["str"] = None,
):

super().__init__()
Expand All @@ -45,7 +48,7 @@ def __init__(
self.date = str(self.disk_usage["date"].unique()[0])
self.users = self.disk_usage["userid"]
self.usage_gib = self.disk_usage["usageKB"] / (1024 ** 2)
self.theme = app.webviz_settings["theme"]
self.theme = webviz_settings.theme

@property
def layout(self) -> html.Div:
Expand Down
11 changes: 8 additions & 3 deletions webviz_subsurface/plugins/_history_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import numpy as np
import pandas as pd
from scipy.stats import chi2
import dash
import dash_html_components as html
import webviz_subsurface_components as wsc
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings

from .._datainput.history_match import extract_mismatch

Expand All @@ -33,15 +33,20 @@ class HistoryMatch(WebvizPluginABC):
observations/observations.yml).
"""

def __init__(self, app: dash.Dash, ensembles: List[str], observation_file: Path):
def __init__(
self,
webviz_settings: WebvizSettings,
ensembles: List[str],
observation_file: Path,
):

super().__init__()

self.observation_file = observation_file

self.ensembles = ensembles
self.ens_paths = {
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][ens]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from webviz_config.webviz_assets import WEBVIZ_ASSETS
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings
from webviz_config.webviz_store import webvizstore

import webviz_subsurface
Expand All @@ -45,12 +46,13 @@ class HorizonUncertaintyViewer(WebvizPluginABC):
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
basedir: Path,
planned_wells_dir: Path = None,
):

super().__init__()
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
self.plotly_theme = webviz_settings.theme.plotly_theme
self.uid = uuid4()
WEBVIZ_ASSETS.add(
Path(webviz_subsurface.__file__).parent / "_assets" / "css" / "modal.css"
Expand Down
6 changes: 4 additions & 2 deletions webviz_subsurface/plugins/_inplace_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from webviz_config.common_cache import CACHE
from webviz_config.webviz_store import webvizstore
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings

from .._datainput.inplace_volumes import extract_volumes
from .._abbreviations.volume_terminology import volume_description, volume_unit
Expand Down Expand Up @@ -86,6 +87,7 @@ class InplaceVolumes(WebvizPluginABC):
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
csvfile: Path = None,
ensembles: list = None,
volfiles: dict = None,
Expand All @@ -105,7 +107,7 @@ def __init__(

elif ensembles and volfiles:
self.ens_paths = {
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][ens]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}
self.volfiles = volfiles
Expand All @@ -122,7 +124,7 @@ def __init__(
self.initial_response = response
self.uid = uuid4()
self.selectors_id = {x: str(uuid4()) for x in self.selectors}
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
self.plotly_theme = webviz_settings.theme.plotly_theme
self.initial_group: Union[str, None] = None
if len(self.volumes["ENSEMBLE"].unique()) > 1:
self.initial_plot = "Box plot"
Expand Down
10 changes: 7 additions & 3 deletions webviz_subsurface/plugins/_inplace_volumes_onebyone.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dash_core_components as dcc
import webviz_core_components as wcc
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings
from webviz_config.common_cache import CACHE
from webviz_config.webviz_store import webvizstore

Expand Down Expand Up @@ -114,6 +115,7 @@ class InplaceVolumesOneByOne(WebvizPluginABC):
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
csvfile_vol: Path = None,
csvfile_parameters: Path = None,
ensembles: list = None,
Expand Down Expand Up @@ -141,7 +143,7 @@ def __init__(

elif ensembles and volfiles:
self.ens_paths = {
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][ens]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}
self.volfiles = volfiles
Expand All @@ -165,10 +167,12 @@ def __init__(
self.volumes = pd.merge(volumes, parameters, on=["ENSEMBLE", "REAL"])

# Initialize a tornado plot. Data is added in callback
self.tornadoplot = TornadoPlot(app, parameters, allow_click=True)
self.tornadoplot = TornadoPlot(
app, webviz_settings, parameters, allow_click=True
)
self.uid = uuid4()
self.selectors_id = {x: self.uuid(x) for x in self.selectors}
self.theme = app.webviz_settings["theme"]
self.theme = webviz_settings.theme
self.set_callbacks(app)

def add_webvizstore(self) -> List[Tuple[Callable, list]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import dash_core_components as dcc
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings
from webviz_config.webviz_assets import WEBVIZ_ASSETS

import webviz_subsurface
Expand Down Expand Up @@ -73,6 +74,7 @@ class ParameterAnalysis(WebvizPluginABC):
def __init__(
self,
app,
webviz_settings: WebvizSettings,
ensembles: Optional[list] = None,
csvfile_parameters: pathlib.Path = None,
csvfile_smry: pathlib.Path = None,
Expand All @@ -87,7 +89,7 @@ def __init__(
/ "css"
/ "container.css"
)
self.theme = app.webviz_settings["theme"]
self.theme = webviz_settings.theme
self.time_index = time_index
self.column_keys = column_keys
self.ensembles = ensembles
Expand All @@ -97,9 +99,7 @@ def __init__(
if ensembles is not None:
self.emodel = EnsembleSetModel(
ensemble_paths={
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][
ens
]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}
)
Expand Down
13 changes: 10 additions & 3 deletions webviz_subsurface/plugins/_parameter_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from webviz_config.webviz_store import webvizstore
from webviz_config.common_cache import CACHE
from webviz_config import WebvizPluginABC
from webviz_config import WebvizSettings

from .._datainput.fmu_input import scratch_ensemble

Expand Down Expand Up @@ -42,16 +43,22 @@ class ParameterCorrelation(WebvizPluginABC):
Parameter values are extracted automatically from the `parameters.txt` files in the individual
realizations of your defined `ensembles`, using the `fmu-ensemble` library."""

def __init__(self, app: dash.Dash, ensembles: list, drop_constants: bool = True):
def __init__(
self,
app: dash.Dash,
webviz_settings: WebvizSettings,
ensembles: list,
drop_constants: bool = True,
):

super().__init__()

self.ensembles = {
ens: app.webviz_settings["shared_settings"]["scratch_ensembles"][ens]
ens: webviz_settings.shared_settings["scratch_ensembles"][ens]
for ens in ensembles
}
self.drop_constants = drop_constants
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
self.plotly_theme = webviz_settings.theme.plotly_theme

self.uid = uuid4()
self.set_callbacks(app)
Expand Down
Loading

0 comments on commit 651e89a

Please sign in to comment.