Ejemplo n.º 1
0
def shared_settings(testdata_folder: pathlib.Path) -> Dict:
    return {
        "HM_SETTINGS":
        WebvizSettings(
            theme=default_theme,
            shared_settings={
                "scratch_ensembles": {
                    "iter-0":
                    f"{testdata_folder}/01_drogon_ahm/realization-*/iter-0",
                    "iter-1":
                    f"{testdata_folder}/01_drogon_ahm/realization-*/iter-1",
                    "iter-2":
                    f"{testdata_folder}/01_drogon_ahm/realization-*/iter-2",
                    "iter-3":
                    f"{testdata_folder}/01_drogon_ahm/realization-*/iter-3",
                }
            },
        ),
        "HM_ENSEMBLES": ["iter-0", "iter-1", "iter-2", "iter-3"],
        "SENS_SETTINGS":
        WebvizSettings(
            theme=default_theme,
            shared_settings={
                "scratch_ensembles": {
                    "sens_run":
                    f"{testdata_folder}/01_drogon_design/realization-*/iter-0",
                }
            },
        ),
        "SENS_ENSEMBLES": ["sens_run"],
    }
Ejemplo n.º 2
0
def test_construction_with_invalid_types() -> None:
    with pytest.raises(TypeError):
        theme = WebvizConfigTheme("dummyThemeName")
        _settings_obj = WebvizSettings(cast(dict, None), theme)

    with pytest.raises(TypeError):
        shared_settings = {"somenumber": 10, "somestring": "abc"}
        _settings_obj = WebvizSettings(shared_settings,
                                       cast(WebvizConfigTheme, None))
def test_parameter_corr(
        dash_duo: dash.testing.composite.DashComposite) -> None:

    app = dash.Dash(__name__)
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    app.config.suppress_callback_exceptions = True
    CACHE.init_app(app.server)
    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, webviz_settings,
                                                     ensembles)

        app.layout = parameter_correlation.layout
        dash_duo.start_server(app)

        my_component = dash_duo.find_element(
            f"#{parameter_correlation.ids('ensemble-all')}")

        if not my_component.text.startswith("iter-0"):
            raise AssertionError()
Ejemplo n.º 4
0
def test_initialized_table_plotter(dash_duo: DashComposite) -> None:

    app = dash.Dash(__name__)
    app.css.config.serve_locally = True
    app.scripts.config.serve_locally = True
    app.config.suppress_callback_exceptions = True
    CACHE.init_app(app.server)
    webviz_settings = WebvizSettings({}, default_theme)
    csv_file = Path("./tests/data/example_data.csv")
    plot_options = dict(
        x="Well",
        y="Initial reservoir pressure (bar)",
        size="Average permeability (D)",
        facet_col="Segment",
    )

    page = _table_plotter.TablePlotter(app,
                                       webviz_settings,
                                       csv_file,
                                       lock=True,
                                       plot_options=plot_options)
    app.layout = page.layout
    dash_duo.start_server(app)

    # Wait for the app to render(there is probably a better way...)

    # Checking that plot options are defined
    assert page.plot_options == plot_options
    assert page.lock

    # Checking that the selectors are hidden
    selector_row = dash_duo.find_element("#" + page.uuid("selector-row"))
    assert "display: none;" in selector_row.get_attribute("style")
Ejemplo n.º 5
0
def test_table_plotter(dash_duo: DashComposite) -> None:

    app = dash.Dash(__name__)
    app.config.suppress_callback_exceptions = True
    CACHE.init_app(app.server)
    webviz_settings = WebvizSettings({}, default_theme)
    csv_file = Path("./tests/data/example_data.csv")
    page = _table_plotter.TablePlotter(app, webviz_settings, csv_file)
    app.layout = page.layout
    dash_duo.start_server(app)

    # Wait for the app to render(there is probably a better way...)
    time.sleep(5)

    # Checking that no plot options are defined
    assert page.plot_options == {}
    # Check that filter is not active
    assert not page.use_filter

    # Checking that the correct plot type is initialized
    plot_dd = dash_duo.find_element("#" + page.uuid("plottype"))
    assert plot_dd.text == "scatter"

    # Checking that only the relevant options are shown
    for plot_option in page.plot_args.keys():
        plot_option_dd = dash_duo.find_element("#" +
                                               page.uuid(f"div-{plot_option}"))
        if plot_option not in page.plots["scatter"]:
            assert plot_option_dd.get_attribute("style") == "display: none;"

    # Checking that options are initialized correctly
    for option in ["x", "y"]:
        plot_option_dd = dash_duo.find_element("#" +
                                               page.uuid(f"dropdown-{option}"))
        assert plot_option_dd.text == "Well"
Ejemplo n.º 6
0
def test_construction_and_basic_access() -> None:
    # pylint: disable=unidiomatic-typecheck
    the_shared_settings = {"somenumber": 10, "somestring": "abc"}
    the_theme = WebvizConfigTheme("dummyThemeName")
    settings_obj = WebvizSettings(the_shared_settings, the_theme)

    copy_of_shared_settings = settings_obj.shared_settings
    assert copy_of_shared_settings is not the_shared_settings
    assert type(copy_of_shared_settings) == type(the_shared_settings)
    assert copy_of_shared_settings == the_shared_settings
    the_shared_settings["somestring"] = "MODIFIED"
    assert copy_of_shared_settings != the_shared_settings

    copy_of_theme = settings_obj.theme
    assert copy_of_theme is not the_theme
    assert type(copy_of_theme) == type(the_theme)
    assert copy_of_theme.__dict__ == the_theme.__dict__
    the_theme.theme_name = "MODIFIED"
    assert copy_of_theme.__dict__ != the_theme.__dict__
def test_default_configuration(dash_duo, app, testdata_folder) -> None:
    webviz_settings = WebvizSettings(
        shared_settings={
            "scratch_ensembles": {
                "iter-0": str(testdata_folder / "01_drogon_ahm/realization-*/iter-0")
            }
        },
        theme=default_theme,
    )
    plugin = StructuralUncertainty(
        app,
        webviz_settings,
        ensembles=["iter-0"],
        surface_attributes=["ds_extract_postprocess"],
        surface_name_filter=[
            "topvolon",
            "toptherys",
            "topvolantis",
            "basevolantis",
        ],
        wellsuffix=".rmswell",
        wellfolder=testdata_folder / "observed_data" / "wells",
    )

    app.layout = plugin.layout
    dash_duo.start_server(app)

    intersection_data_id = plugin.uuid("intersection-data")
    modal_id = plugin.uuid("modal")
    # Check some initialization
    # Check dropdowns
    for element, return_val in zip(
        ["well", "surface_attribute"], ["55_33-1", "ds_extract_postprocess"]
    ):
        uuid = stringify_object_id(
            uuid={"element": element, "id": intersection_data_id}
        )
        assert dash_duo.wait_for_element(f"#\\{uuid} .Select-value").text == return_val

    # Check Selects
    for element, return_val in zip(
        ["surface_names"],
        [["topvolon", "toptherys", "topvolantis", "basevolantis"]],
    ):
        uuid = stringify_object_id(
            uuid={"element": element, "id": intersection_data_id}
        )
        assert (
            dash_duo.wait_for_element(f"#\\{uuid} select").text.splitlines()
            == return_val
        )

    # Check Calculation checkbox
    uuid = stringify_object_id(
        uuid={"element": "calculation", "id": intersection_data_id}
    )
    calculation_element = dash_duo.driver.find_elements_by_css_selector(
        f"#\\{uuid} > label > input"
    )
    assert len(calculation_element) == len(
        ["Min", "Max", "Mean", "Realizations", "Uncertainty envelope"]
    )
    for checkbox, selected in zip(
        calculation_element,
        ["true", "true", "true", None, None],
    ):
        assert checkbox.get_attribute("selected") == selected

    # Check realizations
    real_filter_btn_uuid = stringify_object_id(
        {
            "id": modal_id,
            "modal_id": "realization-filter",
            "element": "button-open",
        }
    )
    real_uuid = stringify_object_id(
        uuid={"element": "realizations", "id": intersection_data_id}
    )

    ### Open realization filter and check realizations
    dash_duo.wait_for_element_by_id(real_filter_btn_uuid).click()
    real_selector = dash_duo.wait_for_element_by_id(real_uuid)
    assert real_selector.text.splitlines() == ["0", "1"]

    assert dash_duo.get_logs() == [], "browser console should contain no error"
def test_full_configuration(dash_duo, app, testdata_folder) -> None:
    webviz_settings = WebvizSettings(
        shared_settings={
            "scratch_ensembles": {
                "iter-0": str(testdata_folder / "01_drogon_ahm/realization-*/iter-0"),
            }
        },
        theme=default_theme,
    )
    plugin = StructuralUncertainty(
        app,
        webviz_settings,
        ensembles=["iter-0"],
        surface_attributes=["ds_extract_postprocess"],
        surface_name_filter=["topvolon", "toptherys", "topvolantis", "basevolantis"],
        wellfolder=testdata_folder / "observed_data" / "wells",
        wellsuffix=".rmswell",
        zonelog="Zone",
        initial_settings={
            "intersection_data": {
                "surface_names": ["topvolon", "toptherys", "topvolantis"],
                "surface_attribute": "ds_extract_postprocess",
                "ensembles": [
                    "iter-0",
                ],
                "calculation": ["Mean", "Min", "Max"],
                # - Uncertainty envelope
                "well": "55_33-1",
                "realizations": [0, 1],
                "colors": {
                    "topvolon": {"iter-0": "#2C82C9"},
                    "toptherys": {
                        "iter-0": "#512E34",
                    },
                    "topvolantis": {
                        "iter-0": "#EEE657",
                    },
                },
            },
            "intersection_layout": {
                "yaxis": {
                    "range": [1700, 1550],
                    "title": "True vertical depth [m]",
                },
                "xaxis": {"title": "Lateral distance [m]"},
            },
        },
    )

    app.layout = plugin.layout

    # Injecting a div that will be updated when the plot data stores are
    # changed. Since the plot data are stored in LocalStorage and Selenium
    # has no functionality to wait for LocalStorage to equal some value we
    # instead populate this injected div with some data before we check the content
    # of Localstorage.
    @app.callback(
        Output(plugin.uuid("layout"), "children"),
        Input(plugin.uuid("intersection-graph-layout"), "data"),
        State(plugin.uuid("layout"), "children"),
    )
    def _add_or_update_div(data, children):
        plot_is_updated = html.Div(
            id=plugin.uuid("plot_is_updated"), children=data.get("title")
        )
        if len(children) == 6:
            children[5] = plot_is_updated
        else:
            children.append(plot_is_updated)

        return children

    dash_duo.start_server(app)

    intersection_data_id = plugin.uuid("intersection-data")

    # Check some initialization
    # Check dropdowns
    for element, return_val in zip(
        ["well", "surface_attribute"], ["55_33-1", "ds_extract_postprocess"]
    ):
        uuid = stringify_object_id(
            uuid={"element": element, "id": intersection_data_id}
        )
        assert dash_duo.wait_for_text_to_equal(f"#\\{uuid} .Select-value", return_val)

    # Wait for the callbacks to execute
    dash_duo.wait_for_text_to_equal(
        f'#{plugin.uuid("plot_is_updated")}',
        "Intersection along well: 55_33-1",
        timeout=30,
    )

    # Check that graph data is stored
    graph_data = dash_duo.get_session_storage(plugin.uuid("intersection-graph-data"))
    assert len(graph_data) == 14
    graph_layout = dash_duo.get_session_storage(
        plugin.uuid("intersection-graph-layout")
    )
    assert isinstance(graph_layout, dict)
    assert graph_layout.get("title") == "Intersection along well: 55_33-1"

    ### Change well and check graph
    well_uuid = stringify_object_id(
        uuid={"element": "well", "id": intersection_data_id}
    )

    apply_btn = dash_duo.wait_for_element_by_id(
        plugin.uuid("apply-intersection-data-selections")
    )
    well_dropdown = dash_duo.wait_for_element_by_id(well_uuid)
    dash_duo.select_dcc_dropdown(well_dropdown, value="55_33-2")
    apply_btn.click()

    # dash_duo.wait_for_text_to_equal(
    #     f'#{plugin.uuid("plot_is_updated")}',
    #     "Intersection along well: 55_33-1",
    #     timeout=100,
    # )
    graph_layout = dash_duo.get_session_storage(
        plugin.uuid("intersection-graph-layout")
    )