Exemplo n.º 1
0
def make_range_slider(domid, values, col_name):
    try:
        values.apply(pd.to_numeric, errors="raise")
    except ValueError as exc:
        raise ValueError(f"Cannot calculate filter range for {col_name}. "
                         "Ensure that it is a numerical column.") from exc
    return wcc.RangeSlider(
        label=col_name,
        id=domid,
        min=values.min(),
        max=values.max(),
        step=calculate_slider_step(
            min_value=values.min(),
            max_value=values.max(),
            steps=len(list(values.unique())) - 1,
        ),
        value=[values.min(), values.max()],
        marks={
            str(values.min()): {
                "label": f"{values.min():.2f}"
            },
            str(values.max()): {
                "label": f"{values.max():.2f}"
            },
        },
    )
Exemplo n.º 2
0
def make_range_slider(values: pd.Series, name: str, uuid: str) -> html.Div:
    return wcc.RangeSlider(
        label=name,
        id={
            "id": uuid,
            "type": "range-slider",
            "name": name
        },
        min=values.min(),
        max=values.max(),
        step=calculate_slider_step(
            min_value=values.min(),
            max_value=values.max(),
            steps=len(list(values.unique())) - 1,
        ),
        value=[values.min(), values.max()],
        marks={
            str(values.min()): {
                "label": f"{values.min():.2f}"
            },
            str(values.max()): {
                "label": f"{values.max():.2f}"
            },
        },
        tooltip={"always_visible": False},
    )
Exemplo n.º 3
0
    def _update_realization_selected_info(
        input_selectors: list,
        selections: dict,
        selected_page: str,
        selected_tab: str,
        input_ids: list,
        wrapper_ids: list,
    ) -> list:
        if selected_tab == "fipqc":
            raise PreventUpdate

        reals = volumemodel.realizations
        prev_selection = (selections[selected_page]["filters"].get("REAL", [])
                          if selections is not None
                          and selected_page in selections else None)
        selected_component = [
            value for id_value, value in zip(input_ids, input_selectors)
            if id_value["tab"] == selected_tab
        ][0]
        selected_reals = prev_selection if prev_selection is not None else reals

        component = (wcc.RangeSlider(
            id={
                "id": get_uuid("filters"),
                "tab": selected_tab,
                "component_type": selected_component,
            },
            value=[min(selected_reals),
                   max(selected_reals)],
            min=min(reals),
            max=max(reals),
            marks={
                str(i): {
                    "label": str(i)
                }
                for i in [min(reals), max(reals)]
            },
        ) if selected_component == "range" else wcc.SelectWithLabel(
            id={
                "id": get_uuid("filters"),
                "tab": selected_tab,
                "component_type": selected_component,
            },
            options=[{
                "label": i,
                "value": i
            } for i in reals],
            value=selected_reals,
            size=min(20, len(reals)),
        ))
        return update_relevant_components(
            id_list=wrapper_ids,
            update_info=[{
                "new_value": component,
                "conditions": {
                    "tab": selected_tab
                }
            }],
        )
Exemplo n.º 4
0
def realization_filters(
    uuid: str, tab: str, volumemodel: InplaceVolumesModel
) -> html.Div:
    reals = volumemodel.realizations
    return html.Div(
        style={"margin-top": "15px"},
        children=[
            html.Div(
                style={"display": "inline-flex"},
                children=[
                    html.Span(
                        "Realizations: ",
                        style={"font-weight": "bold"},
                    ),
                    html.Span(
                        id={"id": uuid, "tab": tab, "element": "real_text"},
                        style={"margin-left": "10px"},
                        children=f"{min(reals)}-{max(reals)}",
                    ),
                ],
            ),
            wcc.RadioItems(
                id={"id": uuid, "tab": tab, "element": "real-selector-option"},
                options=[
                    {"label": "Range", "value": "range"},
                    {"label": "Select", "value": "select"},
                ],
                value="range",
                vertical=False,
            ),
            wcc.RangeSlider(
                wrapper_id={"id": uuid, "tab": tab, "element": "real-slider-wrapper"},
                id={
                    "id": uuid,
                    "tab": tab,
                    "component_type": "range",
                },
                value=[min(reals), max(reals)],
                min=min(reals),
                max=max(reals),
                marks={str(i): {"label": str(i)} for i in [min(reals), max(reals)]},
            ),
            html.Div(
                style={"display": "none"},
                children=wcc.Select(
                    id={"id": uuid, "tab": tab, "selector": "REAL", "type": "REAL"},
                    options=[{"label": i, "value": i} for i in reals],
                    value=reals,
                ),
            ),
        ],
    )
Exemplo n.º 5
0
def color_range_selection_layout(
    tab: str,
    get_uuid: Callable,
    value: List[float],
    value_range: List[float],
    step: float,
    view_idx: int,
) -> html.Div:
    return html.Div(children=[
        f"{LayoutLabels.COLORMAP_RANGE}",
        wcc.RangeSlider(
            id={
                "view": view_idx,
                "id": get_uuid(LayoutElements.COLORSELECTIONS),
                "selector": ColorSelector.COLOR_RANGE,
                "tab": tab,
            },
            tooltip={"placement": "bottomLeft"},
            min=value_range[0],
            max=value_range[1],
            step=step,
            marks={
                str(value): {
                    "label": f"{value:.2f}"
                }
                for value in value_range
            },
            value=value,
        ),
        wcc.Checklist(
            id={
                "view": view_idx,
                "id": get_uuid(LayoutElements.COLORSELECTIONS),
                "selector": "colormap_keep_range",
                "tab": tab,
            },
            options=[{
                "label": LayoutLabels.COLORMAP_KEEP_RANGE,
                "value": LayoutLabels.COLORMAP_KEEP_RANGE,
            }],
            value=[],
        ),
        html.Button(
            children=LayoutLabels.RANGE_RESET,
            style=LayoutStyle.RESET_BUTTON,
            id={
                "view": view_idx,
                "id": get_uuid(LayoutElements.RANGE_RESET),
                "tab": tab,
            },
        ),
    ])
Exemplo n.º 6
0
 def settings_layout(self) -> wcc.FlexBox:
     """Layout for color and other settings"""
     return wcc.Frame(
         style={"width": "40%"},
         children=[
             html.Div(
                 style={"width": "100%"},
                 children=wcc.Dropdown(
                     label="Seismic cube",
                     id=self.uuid("cube"),
                     options=[{
                         "label": Path(cube).stem,
                         "value": cube
                     } for cube in self.segyfiles],
                     value=self.segyfiles[0],
                     clearable=False,
                 ),
             ),
             html.Div(children=[
                 wcc.Label(children="Set colorscale", ),
                 wcc.ColorScales(
                     id=self.uuid("color-scale"),
                     colorscale=self.initial_colors,
                     nSwatches=12,
                 ),
             ], ),
             html.Div(children=[
                 wcc.RangeSlider(
                     label="Color range",
                     id=self.uuid("color-values"),
                     min=self.init_state["min_value"],
                     max=self.init_state["max_value"],
                     value=[
                         self.init_state["min_value"],
                         self.init_state["max_value"],
                     ],
                     tooltip={"placement": "bottom"},
                     step=calculate_slider_step(
                         min_value=self.init_state["min_value"],
                         max_value=self.init_state["max_value"],
                         steps=100,
                     ),
                 ),
             ], ),
             html.Button(id=self.uuid("color-reset"),
                         children="Reset Range"),
             html.Button(id=self.uuid("zoom"), children="Reset zoom"),
         ],
     )
def filter_correlated_parameter(get_uuid: Callable, labels: List[str]) -> html.Div:
    return html.Div(
        [
            html.Div(
                style={"marginBottom": "10px"},
                children=wcc.Dropdown(
                    label="Filter on property",
                    id=get_uuid("property-response-correlated-filter"),
                    options=[{"label": label, "value": label} for label in labels],
                    placeholder="Select a label to filter on...",
                ),
            ),
            wcc.RangeSlider(
                id=get_uuid("property-response-correlated-slider"),
                disabled=True,
                marks=None,
            ),
        ]
    )
Exemplo n.º 8
0
def range_filters(uuid: str, datamodel: SwatinitQcDataModel) -> html.Div:
    dframe = datamodel.dframe
    filters = []
    for col in datamodel.filters_continuous:
        min_val, max_val = dframe[col].min(), dframe[col].max()
        filters.append(
            wcc.RangeSlider(
                label="Depth range" if col == "Z" else col,
                id={
                    "id": uuid,
                    "col": col
                },
                min=min_val,
                max=max_val,
                value=[min_val, max_val],
                marks={
                    str(val): {
                        "label": f"{val:.2f}"
                    }
                    for val in [min_val, max_val]
                },
                tooltip={"always_visible": False},
            ))
    return html.Div(filters)
Exemplo n.º 9
0
def map_plot_selectors(get_uuid: Callable,
                       datamodel: RftPlotterDataModel) -> List[html.Div]:
    ensembles = datamodel.ensembles
    zone_names = datamodel.zone_names
    return wcc.Selectors(
        label="Map plot settings",
        children=[
            wcc.Dropdown(
                label="Ensemble",
                id=get_uuid(LayoutElements.MAP_ENSEMBLE),
                options=[{
                    "label": ens,
                    "value": ens
                } for ens in ensembles],
                value=ensembles[0],
                clearable=False,
            ),
            wcc.Dropdown(
                label="Size points by",
                id=get_uuid(LayoutElements.MAP_SIZE_BY),
                options=[
                    {
                        "label": "Standard Deviation",
                        "value": "STDDEV",
                    },
                    {
                        "label": "Misfit",
                        "value": "ABSDIFF",
                    },
                ],
                value="ABSDIFF",
                clearable=False,
            ),
            wcc.Dropdown(
                label="Color points by",
                id=get_uuid(LayoutElements.MAP_COLOR_BY),
                options=[
                    {
                        "label": "Misfit",
                        "value": "ABSDIFF",
                    },
                    {
                        "label": "Standard Deviation",
                        "value": "STDDEV",
                    },
                    {
                        "label": "Year",
                        "value": "YEAR",
                    },
                ],
                value="STDDEV",
                clearable=False,
            ),
            wcc.RangeSlider(
                label="Filter date range",
                id=get_uuid(LayoutElements.MAP_DATE_RANGE),
                min=datamodel.ertdatadf["DATE_IDX"].min(),
                max=datamodel.ertdatadf["DATE_IDX"].max(),
                value=[
                    datamodel.ertdatadf["DATE_IDX"].min(),
                    datamodel.ertdatadf["DATE_IDX"].max(),
                ],
                marks=datamodel.date_marks,
            ),
            wcc.Selectors(
                label="Zone filter",
                open_details=False,
                children=[
                    wcc.SelectWithLabel(
                        size=min(10, len(zone_names)),
                        id=get_uuid(LayoutElements.MAP_ZONES),
                        options=[{
                            "label": name,
                            "value": name
                        } for name in zone_names],
                        value=zone_names,
                        multi=True,
                    ),
                ],
            ),
        ],
    )
 def layout(self):
     return wcc.FlexBox(
         id=self.ids("layout"),
         children=[
             wcc.Frame(
                 style={"flex": 1},
                 children=[
                     wcc.Selectors(
                         label="Map settings",
                         children=[
                             wcc.Dropdown(
                                 id=self.ids("surface"),
                                 label="Select surface",
                                 options=[{
                                     "label": name,
                                     "value": path
                                 } for name, path in zip(
                                     self.surfacenames, self.surfacefiles)],
                                 value=self.surfacefiles[0],
                                 clearable=False,
                             ),
                             wcc.RadioItems(
                                 id=self.ids("surface-type"),
                                 options=[
                                     {
                                         "label": "Display surface z-value",
                                         "value": "surface",
                                     },
                                     {
                                         "label":
                                         "Display seismic attribute as z-value",
                                         "value": "attribute",
                                     },
                                 ],
                                 value="surface",
                             ),
                         ],
                     ),
                     wcc.Selectors(
                         label="Intersection settings",
                         children=[
                             wcc.Dropdown(
                                 label="Select seismic cube",
                                 id=self.ids("cube"),
                                 options=[{
                                     "label": Path(cube).stem,
                                     "value": cube
                                 } for cube in self.segyfiles],
                                 value=self.segyfiles[0],
                                 clearable=False,
                             ),
                             wcc.Label(children="Set colorscale", ),
                             wcc.ColorScales(
                                 id=self.ids("color-scale"),
                                 colorscale=self.initial_colors,
                                 nSwatches=12,
                             ),
                             wcc.RangeSlider(
                                 label="Set color range",
                                 id=self.ids("color-values"),
                                 tooltip={
                                     "placement": "bottom",
                                     "always_visible": True,
                                 },
                                 marks=None,
                             ),
                             html.Button(
                                 id=self.ids("color-range-btn"),
                                 children="Reset Range",
                             ),
                         ],
                     ),
                 ],
             ),
             wcc.Frame(
                 highlight=False,
                 style={
                     "height": "800px",
                     "flex": 3,
                 },
                 children=[
                     LeafletMap(
                         id=self.ids("map-view"),
                         autoScaleMap=True,
                         minZoom=-19,
                         updateMode="update",
                         layers=[],
                         drawTools={
                             "drawMarker": False,
                             "drawPolygon": False,
                             "drawPolyline": True,
                             "position": "topright",
                         },
                         mouseCoords={"position": "bottomright"},
                         colorBar={"position": "bottomleft"},
                         switch={
                             "value": False,
                             "disabled": False,
                             "label": "Hillshading",
                         },
                     ),
                 ],
             ),
             html.Div(
                 style={
                     "flex": 3,
                     "height": "800px"
                 },
                 children=[
                     wcc.Graph(config={"displayModeBar": False},
                               id=self.ids("fence-view")),
                 ],
             ),
         ],
     )
    def _update_realization_selected_info(
        input_selectors: list,
        selections: dict,
        selected_page: str,
        selected_tab: str,
        input_ids: list,
        wrapper_ids: list,
    ) -> list:
        reals = volumemodel.realizations
        prev_selection = (selections[selected_page]["filters"].get("REAL", [])
                          if selections is not None
                          and selected_page in selections else None)

        page_value = [
            value for id_value, value in zip(input_ids, input_selectors)
            if id_value["tab"] == selected_tab
        ]

        if page_value[0] == "range":
            min_value = (min(prev_selection)
                         if prev_selection is not None else min(reals))
            max_value = (max(prev_selection)
                         if prev_selection is not None else max(reals))
            return update_relevant_components(
                id_list=wrapper_ids,
                update_info=[{
                    "new_value":
                    wcc.RangeSlider(
                        id={
                            "id": get_uuid("filters"),
                            "tab": selected_tab,
                            "component_type": page_value[0],
                        },
                        value=[min_value, max_value],
                        min=min(reals),
                        max=max(reals),
                        marks={
                            str(i): {
                                "label": str(i)
                            }
                            for i in [min(reals), max(reals)]
                        },
                    ),
                    "conditions": {
                        "tab": selected_tab
                    },
                }],
            )

        # if input_selector == "select"
        return update_relevant_components(
            id_list=wrapper_ids,
            update_info=[{
                "new_value":
                wcc.SelectWithLabel(
                    id={
                        "id": get_uuid("filters"),
                        "tab": selected_tab,
                        "component_type": page_value[0],
                    },
                    options=[{
                        "label": i,
                        "value": i
                    } for i in reals],
                    value=prev_selection
                    if prev_selection is not None else reals,
                    size=min(20, len(reals)),
                ),
                "conditions": {
                    "tab": selected_tab
                },
            }],
        )
Exemplo n.º 12
0
    def map_plot_selectors(self) -> List[html.Div]:

        return wcc.Selectors(
            label="Map plot settings",
            children=[
                wcc.Dropdown(
                    label="Ensemble",
                    id=self.uuid("map_ensemble"),
                    options=[{
                        "label": ens,
                        "value": ens
                    } for ens in list(self.ertdatadf["ENSEMBLE"].unique())],
                    value=list(self.ertdatadf["ENSEMBLE"].unique())[0],
                    clearable=False,
                ),
                wcc.Dropdown(
                    label="Size points by",
                    id=self.uuid("map_size"),
                    options=[
                        {
                            "label": "Standard Deviation",
                            "value": "STDDEV",
                        },
                        {
                            "label": "Misfit",
                            "value": "ABSDIFF",
                        },
                    ],
                    value="ABSDIFF",
                    clearable=False,
                ),
                wcc.Dropdown(
                    label="Color points by",
                    id=self.uuid("map_color"),
                    options=[
                        {
                            "label": "Misfit",
                            "value": "ABSDIFF",
                        },
                        {
                            "label": "Standard Deviation",
                            "value": "STDDEV",
                        },
                        {
                            "label": "Year",
                            "value": "YEAR",
                        },
                    ],
                    value="STDDEV",
                    clearable=False,
                ),
                wcc.RangeSlider(
                    label="Filter date range",
                    id=self.uuid("map_date"),
                    min=self.ertdatadf["DATE_IDX"].min(),
                    max=self.ertdatadf["DATE_IDX"].max(),
                    value=[
                        self.ertdatadf["DATE_IDX"].min(),
                        self.ertdatadf["DATE_IDX"].max(),
                    ],
                    marks=self.date_marks,
                ),
            ],
        )