Beispiel #1
0
    def set_callbacks(self, app):
        @app.callback(self.plugin_data_output, [self.plugin_data_requested])
        def user_download_data(data_requested):
            if data_requested:
                return WebvizPluginABC.plugin_data_compress(
                    [
                        {
                            "filename": Path(self.csv_file).name,
                            "content": get_data(self.csv_file).to_csv(),
                        }
                    ]
                )
            return ""

        inputs = [Input(self.key_dropdown_id, "value")]
        data = get_data(self.csv_file)
        if "date" in data.columns:
            inputs.append(Input(self.date_dropdown_id, "value"))

        @app.callback(
            Output(self.graph_id, "figure"), inputs,
        )
        def update_graph(key_list, *args):
            if key_list is None:
                return {}

            data = get_data(self.csv_file)

            traces = []
            if "date" in data.columns:
                for key in key_list:
                    for date in args[0]:
                        selected_data = data[data["date"] == date].drop(
                            columns=["date"]
                        )
                        traces.append(
                            go.Bar(
                                y=selected_data[key],
                                x=selected_data["realization"],
                                name=f"{key}:{date}",
                                showlegend=True,
                            ),
                        )
            else:
                for key in key_list:
                    traces.append(
                        go.Bar(
                            y=data[key],
                            x=data["realization"],
                            name=key,
                            showlegend=True,
                        ),
                    )

            return {
                "data": traces,
                "layout": dict(
                    xaxis={"title": "Realization"}, yaxis={"title": "Value"},
                ),
            }
Beispiel #2
0
        def update_graph(
            xaxis_name,
            yaxis_name,
            realization_nr,
            xaxis_type,
            yaxis_type,
            interpolation_type,
            xaxis_opt,
            yaxis_opt,
        ):
            if None in [xaxis_name, yaxis_name]:
                return {}

            if isinstance(realization_nr, int):
                realization_nr = [realization_nr]

            df = get_data(self.data_path)
            traces = []
            for realization in realization_nr:
                x_data = df.filter(like=xaxis_name).loc[realization]
                y_data = df.filter(like=yaxis_name).loc[realization]
                mode = "markers" if not interpolation_type else "markers+lines"
                traces.append(
                    get_graph_line(
                        x_data,
                        y_data,
                        xaxis_opt,
                        yaxis_opt,
                        mode=mode,
                        line_shape=interpolation_type,
                        name="Realization: {}".format(realization_nr),
                    ))
            return crossplot_update_graph(traces, xaxis_name, yaxis_name,
                                          xaxis_type, yaxis_type)
Beispiel #3
0
        def update_graph(control_list):
            # # The key_list arguments is the list of functions to plot.
            if control_list is None:
                return {}

            # # Get the data, setting its index.
            data = get_data(self.csv_file).set_index("control")

            traces = []
            for control in control_list:
                control_data = data.xs(control)
                traces.append(
                    go.Scatter(
                        y=control_data["value"],
                        x=control_data["batch"],
                        mode="lines",
                        name=control,
                        showlegend=True,
                    ), )
            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={"title": "Batch"},
                    yaxis={"title": "Control Value"},
                ),
            }
Beispiel #4
0
    def layout(self):
        data = get_data(self.csv_file)

        fig = px.scatter(
            data,
            y="value",
            x="control",
            color="batch",
            template="plotly_white",
            labels={
                "control": "Control",
                "value": "Control Value"
            },
        )
        return html.Div([
            dcc.Graph(
                id=self.graph_id,
                config={
                    "displaylogo": False,
                    "toImageButtonOptions": {
                        "filename": "best_controls"
                    },
                },
                figure=fig,
            )
        ])
Beispiel #5
0
 def user_download_data(
     data_requested,
     radio_value,
     realizations_check,
     realizations_input,
 ):
     if data_requested:
         content = get_data(self.csv_file)
         if realizations_check:
             realizations = parse_range(realizations_input)
             if realizations:
                 content = content[content["realization"].isin(
                     realizations)]
         if radio_value == "Statistics":
             filename = "objective_statistics.csv"
             content = calculate_statistics(content)
         else:
             filename = "objective_values.csv"
         return WebvizPluginABC.plugin_data_compress([{
             "filename":
             filename,
             "content":
             content.to_csv(),
         }])
     return ""
        def update_graph(function_list, _):
            if function_list is None:
                return {}

            data = get_data(self.csv_file)
            accepted_data = data[data.accepted == 1]
            not_accepted_data = data[data.accepted == 0]

            colors = cycle(DEFAULT_PLOTLY_COLORS)
            traces = []
            for name, color in zip(function_list, colors):
                if name != "objective":
                    traces.append(
                        go.Scatter(
                            y=data[name],
                            x=data.batch,
                            mode="lines+markers",
                            marker={
                                "color": color,
                                "size": 10
                            },
                            name=name,
                        ), )
                else:
                    traces.extend([
                        go.Scatter(
                            y=accepted_data[name],
                            x=accepted_data.batch,
                            mode="lines+markers",
                            marker={
                                "color": "blue",
                                "size": 10
                            },
                            name="accepted",
                        ),
                        go.Scatter(
                            y=not_accepted_data[name],
                            x=not_accepted_data.batch,
                            mode="markers",
                            marker={
                                "color": "red",
                                "size": 9
                            },
                            name="rejected",
                        ),
                    ])

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={
                        "title": "Batch",
                        "tickformat": ",d"
                    },
                    yaxis={"title": "Objective function value"},
                ),
            }
Beispiel #7
0
 def user_download_data(data_requested):
     if data_requested:
         return {
             "filename": Path(self.data_path).name,
             "content": base64encode(get_data(self.data_path).to_csv()),
             "mime_type": "text/csv",
         }
     return None
Beispiel #8
0
        def user_download_data(data_requested, radio_value):
            if data_requested:
                if radio_value == "Statistics":
                    data = get_data(self.statistics_file).set_index(
                        ["summary_key", "batch", "date"])
                    file_path = self.statistics_file
                else:
                    data = get_data(self.values_file).set_index(
                        ["batch", "date"])
                    file_path = self.values_file

                return WebvizPluginABC.plugin_data_compress([{
                    "filename":
                    Path(file_path).name,
                    "content":
                    data.to_csv(),
                }])
            return ""
Beispiel #9
0
 def user_download_data(data_requested):
     if data_requested:
         return WebvizPluginABC.plugin_data_compress([{
             "filename":
             Path(self.csv_file).name,
             "content":
             get_data(self.csv_file).to_csv(),
         }])
     return ""
Beispiel #10
0
    def layout(self):
        data = get_data(self.statistics_file)

        functions = data["function"].unique()
        function_dropdown_options = [{"label": i, "value": i} for i in functions]
        func_elements = [
            html.Label("Functions to plot:"),
            dcc.Dropdown(
                id=self.function_dropdown_id,
                options=function_dropdown_options,
                multi=True,
                value=[functions[0]],
            ),
        ]

        radio_options = ["Statistics", "Data"]
        radio_elements = [
            dcc.RadioItems(
                id=self.radio_id,
                options=[{"label": i, "value": i} for i in radio_options],
                value=radio_options[1],
                labelStyle={"display": "inline-block"},
                style={"margin-top": 20},
            )
        ]

        return html.Div(
            [
                html.Div(
                    [
                        html.Div(
                            func_elements + radio_elements,
                            style={
                                "width": "29%",
                                "display": "inline-block",
                                "vertical-align": "top",
                            },
                        ),
                        html.Div(
                            [
                                dcc.Graph(
                                    id=self.graph_id,
                                    config={
                                        "modeBarButtonsToRemove": ["toImage"],
                                        "displaylogo": False,
                                    },
                                )
                            ],
                            style={"width": "69%", "display": "inline-block"},
                        ),
                    ]
                ),
            ]
        )
Beispiel #11
0
 def user_download_data(data_requested, radio_value):
     if data_requested:
         file_path = (
             self.statistics_file
             if radio_value == "Statistics"
             else self.values_file
         )
         return WebvizPluginABC.plugin_data_compress(
             [
                 {
                     "filename": Path(file_path).name,
                     "content": get_data(file_path).to_csv(),
                 }
             ]
         )
     return ""
 def layout(self):
     data = get_data(self.csv_file)
     exclude = ["batch", "accepted"]
     functions = [name for name in data.columns if name not in exclude]
     function_dropdown_options = [{
         "label": i,
         "value": i
     } for i in functions]
     func_elements = [
         html.Label("Functions to plot:"),
         dcc.Dropdown(
             id=self.function_dropdown_id,
             options=function_dropdown_options,
             multi=True,
             value=[functions[0]],
         ),
     ]
     return html.Div([
         html.Div(
             func_elements,
             style={
                 "width": "29%",
                 "display": "inline-block",
                 "vertical-align": "top",
             },
         ),
         html.Div(
             [
                 dcc.Graph(
                     id=self.graph_id,
                     config={
                         "displaylogo": False,
                         "toImageButtonOptions": {
                             "filename": "single_objectives"
                         },
                     },
                 )
             ],
             id=self.div_id,
             style={
                 "width": "69%",
                 "display": "inline-block"
             },
         ),
     ])
Beispiel #13
0
        def update_graph(key_list, *args):
            if key_list is None:
                return {}

            data = get_data(self.csv_file)

            traces = []
            if "date" in data.columns:
                for key in key_list:
                    for date in args[0]:
                        selected_data = data[data["date"] == date].drop(
                            columns=["date"])
                        traces.append(
                            go.Bar(
                                y=selected_data[key],
                                x=selected_data["realization"],
                                name=f"{key}:{date}",
                                showlegend=True,
                            ), )
            else:
                for key in key_list:
                    traces.append(
                        go.Bar(
                            y=data[key],
                            x=data["realization"],
                            name=key,
                            showlegend=True,
                        ), )

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={
                        "title": "Realization",
                        "tickformat": ",d"
                    },
                    yaxis={
                        "title": "(best realization) - (initial realization)"
                    },
                ),
            }
Beispiel #14
0
    def layout(self):
        data = get_data(self.csv_file)

        controls = data["control"].unique()
        control_dropdown_options = [{"label": i, "value": i} for i in controls]
        control_elements = [
            html.Label("Controls to plot:"),
            dcc.Dropdown(
                id=self.controls_dropdown_id,
                options=control_dropdown_options,
                multi=True,
                value=[controls[0]],
            ),
        ]

        return html.Div([
            html.Div([
                html.Div(
                    control_elements,
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "modeBarButtonsToRemove": ["toImage"],
                                "displaylogo": False,
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])
Beispiel #15
0
 def update_graph(
     xaxis_column_name,
     yaxis_column_name,
     xaxis_type,
     yaxis_type,
     axis_options_x_id,
     axis_options_y_id,
 ):
     if None in [xaxis_column_name, yaxis_column_name]:
         return {}
     df = get_data(self.data_path)
     x_data = df[xaxis_column_name]
     y_data = df[yaxis_column_name]
     data = [
         get_graph_line(x_data, y_data, axis_options_x_id,
                        axis_options_y_id)
     ]
     return crossplot_update_graph(data, xaxis_column_name,
                                   yaxis_column_name, xaxis_type,
                                   yaxis_type)
Beispiel #16
0
        def update_graph(well_keys, batch_list, statistics, target_rate):
            if well_keys is None or batch_list is None:
                return {}
            if well_keys is not None and len(well_keys) == 0:
                return {}
            if batch_list is not None and len(batch_list) == 0:
                return {}

            df = get_data(self.csv_file)

            if statistics == "Statistics":
                df = calculate_statistics(df, well_keys).set_index(
                    ["summary_key", "batch", "date"])
            else:
                df = df.set_index(["batch", "date"])

            callback = summary_callback.get_callback_func(statistics)

            traces = callback(df, well_keys, batch_list, "batch", "date")
            if target_rate == "On":
                target_keys = _get_target_keys(df, well_keys)
                traces.extend(
                    callback(df,
                             target_keys,
                             batch_list,
                             "batch",
                             "date",
                             mode="lines"))

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={"title": "Date"},
                    yaxis={"title": "Well rates"},
                    hovermode="closest",
                ),
            }
Beispiel #17
0
        def update_graph(_):
            data = get_data(self.csv_file)
            accepted_data = data[data.accepted == True]  # pylint: disable=C0121
            not_accepted_data = data[data.accepted == False]  # pylint: disable=C0121
            traces = [
                go.Scatter(
                    y=accepted_data.value,
                    x=accepted_data.batch,
                    mode="lines+markers",
                    marker={
                        "color": "blue",
                        "size": 10
                    },
                    name="accepted",
                ),
                go.Scatter(
                    y=not_accepted_data.value,
                    x=not_accepted_data.batch,
                    mode="markers",
                    marker={
                        "color": "red",
                        "size": 9
                    },
                    name="not accepted",
                ),
            ]

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={"title": "Batch"},
                    yaxis={"title": "Objective function value"},
                ),
            }
Beispiel #18
0
 def user_download_data(
     data_requested,
     radio_value,
     realizations_check,
     realizations_input,
 ):
     if data_requested:
         content = get_data(self.csv_file)
         if realizations_check:
             realizations = parse_range(realizations_input)
             if realizations:
                 content = content[content["realization"].isin(
                     realizations)]
         if radio_value == "Statistics":
             filename = "objective_statistics.csv"
             content = calculate_statistics(content)
         else:
             filename = "objective_values.csv"
         return {
             "filename": filename,
             "content": base64encode(content.to_csv()),
             "mime_type": "text/csv",
         }
     return None
Beispiel #19
0
    def layout(self):
        axis_type = [(i, i) for i in ["Linear", "Log"]]
        axis_options = ["Normal", "Cumulative"]
        df = get_data(self.data_path)
        plot_keys = df.columns.unique()

        sidebar_configs = [
            (
                "radio",
                {
                    "title": "X-axis",
                    "item_id": self.axis_type_x_id,
                    "options": axis_type,
                },
            ),
            (
                "radio",
                {
                    "item_id": self.axis_opt_x_id,
                    "options": axis_options
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.keys_x_id,
                    "options": plot_keys
                },
            ),
            (
                "radio",
                {
                    "title": "Y-axis",
                    "item_id": self.axis_type_y_id,
                    "options": axis_type,
                },
            ),
            (
                "radio",
                {
                    "item_id": self.axis_opt_y_id,
                    "options": axis_options
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.keys_y_id,
                    "options": plot_keys
                },
            ),
        ]

        return html.Div([
            html.H1(
                children=self.title,
                style={"textAlign": "center"},
            ),
            html.Div([
                html.Div(
                    [get_sidebar_layout(sidebar_configs)],
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "displaylogo": False,
                                "toImageButtonOptions": {
                                    "filename": "crossplot"
                                },
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])
Beispiel #20
0
    def set_callbacks(self, app):
        @app.callback(self.plugin_data_output, [self.plugin_data_requested])
        def user_download_data(data_requested):
            if data_requested:
                return {
                    "filename": Path(self.csv_file).name,
                    "content":
                    base64encode(csv=get_data(self.csv_file).to_csv()),
                    "mime_type": "text/csv",
                }
            return None

        inputs = [Input(self.key_dropdown_id, "value")]
        data = get_data(self.csv_file)
        if "date" in data.columns:
            inputs.append(Input(self.date_dropdown_id, "value"))

        @app.callback(
            Output(self.graph_id, "figure"),
            inputs,
        )
        def update_graph(key_list, *args):
            if key_list is None:
                return {}

            data = get_data(self.csv_file)

            traces = []
            if "date" in data.columns:
                for key in key_list:
                    for date in args[0]:
                        selected_data = data[data["date"] == date].drop(
                            columns=["date"])
                        traces.append(
                            go.Bar(
                                y=selected_data[key],
                                x=selected_data["realization"],
                                name=f"{key}:{date}",
                                showlegend=True,
                            ), )
            else:
                for key in key_list:
                    traces.append(
                        go.Bar(
                            y=data[key],
                            x=data["realization"],
                            name=key,
                            showlegend=True,
                        ), )

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={
                        "title": "Realization",
                        "tickformat": ",d"
                    },
                    yaxis={
                        "title": "(best realization) - (initial realization)"
                    },
                ),
            }
Beispiel #21
0
        def update_graph(func_list, radio_value):
            # # The key_list arguments is the list of functions to plot.
            if func_list is None:
                return {}

            # # Get the data, setting its index.
            if radio_value == "Statistics":
                data = get_data(self.statistics_file).set_index("function")
            else:
                data = get_data(self.values_file).set_index("function")

            # Make a cycle iterator over the plotly colors.
            colors = cycle(DEFAULT_PLOTLY_COLORS)

            traces = []
            for color, key in zip(colors, func_list):
                # Select all data belonging to the current key.
                func_data = data.xs(key)

                # Make the traces, with mean, P10 and P90, shading in between.
                if radio_value == "Statistics":
                    traces.extend(
                        [
                            go.Scatter(
                                y=func_data["P90"],
                                x=func_data["batch"],
                                mode="lines",
                                marker={"size": 10},
                                line={"color": color},
                                name=key + "(P90)",
                                showlegend=False,
                            ),
                            go.Scatter(
                                y=func_data["P10"],
                                x=func_data["batch"],
                                mode="lines",
                                line={"color": color},
                                marker={"size": 10},
                                fill="tonexty",
                                name=key + "(P10)",
                                showlegend=False,
                            ),
                            go.Scatter(
                                y=func_data["Mean"],
                                x=func_data["batch"],
                                mode="lines",
                                marker={"size": 10},
                                line={"color": color},
                                name=key,
                                showlegend=True,
                            ),
                        ]
                    )
                else:
                    traces.append(
                        go.Scatter(
                            y=func_data["value"],
                            x=func_data["batch"],
                            mode="markers",
                            marker={"size": 10},
                            name=key,
                            showlegend=True,
                        )
                    )

            return {
                "data": traces,
                "layout": dict(
                    xaxis={"title": "Batch"}, yaxis={"title": "Function Key Value"},
                ),
            }
Beispiel #22
0
        def update_graph(func_list, radio_value, plot_mode, realizations_check,
                         realizations_input):
            # The key_list arguments is the list of functions to plot.
            if func_list is None:
                return {}

            # Get the data, filter if requested.
            data = get_data(self.csv_file)
            if realizations_check:
                realizations = parse_range(realizations_input)
                if realizations:
                    data = data[data["realization"].isin(realizations)]
            if len(data) == 0:
                return {}

            if radio_value == "Statistics":
                data = calculate_statistics(data)

            data = data.set_index("function")

            # Make a cycle iterator over the plotly colors.
            colors = cycle(DEFAULT_PLOTLY_COLORS)

            traces = []
            for color, key in zip(colors, func_list):
                # Select all data belonging to the current key.
                func_data = data.xs(key)

                # Make the traces, with mean, P10 and P90, shading in between.
                if radio_value == "Statistics":
                    traces.extend([
                        go.Scatter(
                            y=func_data["P90"],
                            x=func_data["batch"],
                            mode=plot_mode,
                            marker={"size": 10},
                            line={"color": color},
                            name=key + "(P90)",
                            showlegend=False,
                        ),
                        go.Scatter(
                            y=func_data["P10"],
                            x=func_data["batch"],
                            mode=plot_mode,
                            line={"color": color},
                            marker={"size": 10},
                            fill="tonexty",
                            name=key + "(P10)",
                            showlegend=False,
                        ),
                        go.Scatter(
                            y=func_data["Mean"],
                            x=func_data["batch"],
                            mode=plot_mode,
                            marker={"size": 10},
                            line={"color": color},
                            name=key,
                            showlegend=True,
                        ),
                    ])
                else:
                    y_values = func_data["value"]
                    if radio_value == "Normalized":
                        y_values = y_values * func_data["norm"]
                    elif radio_value == "Weighted + Normalized":
                        y_values = y_values * func_data["norm"] * func_data[
                            "weight"]

                    traces.append(
                        go.Scatter(
                            y=y_values,
                            x=func_data["batch"],
                            mode=plot_mode,
                            marker={"size": 10},
                            name=key,
                            showlegend=True,
                        ))

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={"title": "Batch"},
                    yaxis={"title": "Function Key Value"},
                ),
            }
Beispiel #23
0
    def layout(self):
        data = get_data(self.csv_file)

        functions = data["function"].unique()
        function_dropdown_options = [{
            "label": i,
            "value": i
        } for i in functions]
        func_elements = [
            html.Label("Functions to plot:"),
            dcc.Dropdown(
                id=self.function_dropdown_id,
                options=function_dropdown_options,
                multi=True,
                value=[functions[0]],
            ),
        ]

        radio_options = [
            "Statistics", "Values", "Normalized", "Weighted + Normalized"
        ]
        radio_elements = [
            dcc.RadioItems(
                id=self.radio_id,
                options=[{
                    "label": i,
                    "value": i
                } for i in radio_options],
                value=radio_options[1],
                labelStyle={"display": "inline-block"},
                style={"margin-top": 20},
            ),
            html.Label("Style:"),
            dcc.RadioItems(
                id=self.radio_id_mode,
                options=[
                    {
                        "label": "line",
                        "value": "lines"
                    },
                    {
                        "label": "scatter",
                        "value": "markers"
                    },
                ],
                value="lines",
                labelStyle={"display": "inline-block"},
            ),
        ]

        realization_elements = [
            html.Div(
                [
                    dcc.Checklist(
                        id=self.realization_filter_check_id,
                        options=[{
                            "label": "Filter realizations:",
                            "value": "filter"
                        }],
                        style={
                            "display": "inline-block",
                            "margin-right": 8
                        },
                    ),
                    dcc.Input(
                        id=self.realization_filter_input_id,
                        type="text",
                        placeholder="example: 0, 3, 6-10",
                        pattern=
                        r"\s*|([0-9]+(\s*-\s*[0-9]+)?)(\s*,\s*[0-9]+(\s*-\s*[0-9]+)?)*",
                        style={"display": "inline-block"},
                    ),
                ],
                style={"margin-top": 20},
            )
        ]

        return html.Div([
            html.Div([
                html.Div(
                    func_elements + radio_elements + realization_elements,
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "modeBarButtonsToRemove": ["toImage"],
                                "displaylogo": False,
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])
Beispiel #24
0
    def layout(self):
        data = get_data(self.csv_file)

        key_dropdown_options = [
            {"label": i, "value": i}
            for i in data.columns
            if i not in ["realization", "date"]
        ]

        if self.pre_select == "first":
            key_dropdown_value = [key_dropdown_options[0]["label"]]
        elif self.pre_select == "all":
            key_dropdown_value = [option["label"] for option in key_dropdown_options]
        elif self.pre_select == "none":
            key_dropdown_value = []
        else:
            raise RuntimeError(f"Invalid argument: 'pre_select={self.pre_select}")

        dropdown_elements = [
            html.Label("Values to plot:"),
            dcc.Dropdown(
                id=self.key_dropdown_id,
                options=key_dropdown_options,
                multi=True,
                value=key_dropdown_value,
            ),
        ]

        if "date" in data.columns:
            date_dropdown_options = [
                {"label": i, "value": i} for i in data["date"].unique()
            ]
            date_dropdown_value = (
                [date_dropdown_options[-1]["label"]] if date_dropdown_options else None
            )
            dropdown_elements.extend(
                [
                    html.Label("Dates to plot:"),
                    dcc.Dropdown(
                        id=self.date_dropdown_id,
                        options=date_dropdown_options,
                        multi=True,
                        value=date_dropdown_value,
                    ),
                ]
            )

        return html.Div(
            [
                html.Div(
                    [
                        html.Div(
                            dropdown_elements,
                            style={
                                "width": "29%",
                                "display": "inline-block",
                                "vertical-align": "top",
                            },
                        ),
                        html.Div(
                            [dcc.Graph(id=self.graph_id)],
                            style={"width": "69%", "display": "inline-block"},
                        ),
                    ]
                ),
            ]
        )
Beispiel #25
0
        def update_graph(key_list, line_list, radio_value, realizations_check,
                         realizations_input):
            # The key_list arguments is the list of keys to plot. The line_list
            # argument is a list of batches, or a list of dates to plot for
            # those keys.
            if key_list is None or line_list is None:
                return {}

            data = get_data(self.csv_file)
            if realizations_check:
                realizations = parse_range(realizations_input)
                if realizations:
                    data = data[data["realization"].isin(realizations)]

            if radio_value == "Statistics":
                data = calculate_statistics(data).set_index(
                    ["summary_key", "batch", "date"])
            else:
                data = data.set_index(["batch", "date"])

            # Make a cycle iterator over the plotly colors.
            colors = cycle(DEFAULT_PLOTLY_COLORS)

            # Choose between dates or batches for different lines.
            line_key = "batch" if self.xaxis == "date" else "date"

            traces = []
            for color, key in zip(colors, key_list):
                # Select all data belonging to the current key.
                if radio_value == "Statistics":
                    key_data = data.xs(key,
                                       level="summary_key",
                                       drop_level=True)
                else:
                    key_data = data[key]

                for line in line_list:
                    # Select all rows belonging the current batch or date.
                    line_data = key_data.xs(line,
                                            level=line_key,
                                            drop_level=True).reset_index()

                    # Set the name of the plotted line.
                    name = key
                    if len(line_list) > 1:
                        name += f", {line_key}:{line}"

                    # Make the traces, with mean, P10 and P90, shading in between.
                    if radio_value == "Statistics":
                        traces.extend([
                            go.Scatter(
                                y=line_data["P90"],
                                x=line_data[self.xaxis],
                                mode="lines",
                                marker={"size": 10},
                                line={"color": color},
                                name=name + "(P90)",
                                showlegend=False,
                            ),
                            go.Scatter(
                                y=line_data["P10"],
                                x=line_data[self.xaxis],
                                mode="lines",
                                line={"color": color},
                                marker={"size": 10},
                                fill="tonexty",
                                name=name + "(P10)",
                                showlegend=False,
                            ),
                            go.Scatter(
                                y=line_data["mean"],
                                x=line_data[self.xaxis],
                                mode="lines",
                                marker={"size": 10},
                                line={"color": color},
                                name=name,
                                showlegend=True,
                            ),
                        ])
                    else:
                        traces.append(
                            go.Scatter(
                                y=line_data[key],
                                x=line_data[self.xaxis],
                                mode="markers",
                                marker={"size": 10},
                                name=name,
                                showlegend=True,
                            ))

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={"title": self.xaxis.capitalize()},
                    yaxis={"title": "Summary Key Value"},
                ),
            }
Beispiel #26
0
    def layout(self):
        radio_options = ["Statistics", "Data"]
        data = get_data(self.csv_file).set_index(
            ["batch", "date", "realization"])
        key_dropdown_options = [{
            "label": i,
            "value": i
        } for i in list(data.columns.unique())]
        data = data.reset_index()
        xaxis_dropdown_options = [{
            "label": i,
            "value": i
        } for i in list(data["batch" if self.xaxis ==
                             "date" else "date"].unique())]
        xaxis_dropdown_title = ("Batches to plot"
                                if self.xaxis == "date" else "Dates to plot")

        # Keywords dropdown.
        keyword_elements = [
            html.Label("Keywords to plot:"),
            dcc.Dropdown(
                id=self.key_dropdown_id,
                options=key_dropdown_options,
                multi=True,
            ),
        ]

        # X-axis dropdown.
        xaxis_elements = [
            html.Label(xaxis_dropdown_title, style={"margin-top": 24}),
            dcc.Dropdown(
                id=self.xaxis_dropdown_id,
                options=xaxis_dropdown_options,
                multi=True,
                value=[xaxis_dropdown_options[0]["value"]],
            ),
        ]

        # Radio for switching between data and statistics.
        radio_elements = [
            dcc.RadioItems(
                id=self.radio_id,
                options=[{
                    "label": i,
                    "value": i
                } for i in radio_options],
                value=radio_options[0],
                labelStyle={"display": "inline-block"},
                style={"margin-top": 20},
            ),
        ]

        realization_elements = [
            html.Div(
                [
                    dcc.Checklist(
                        id=self.realization_filter_check_id,
                        options=[{
                            "label": "Filter realizations:",
                            "value": "filter"
                        }],
                        style={
                            "display": "inline-block",
                            "margin-right": 8
                        },
                    ),
                    dcc.Input(
                        id=self.realization_filter_input_id,
                        type="text",
                        placeholder="example: 0, 3, 6-10",
                        pattern=
                        r"\s*|([0-9]+(\s*-\s*[0-9]+)?)(\s*,\s*[0-9]+(\s*-\s*[0-9]+)?)*",
                        style={"display": "inline-block"},
                    ),
                ],
                style={"margin-top": 20},
            )
        ]

        return html.Div([
            html.Div([
                html.Div(
                    keyword_elements + xaxis_elements + radio_elements +
                    realization_elements,
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "modeBarButtonsToRemove": ["toImage"],
                                "displaylogo": False,
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])
Beispiel #27
0
    def layout(self):
        df = get_data(self.data_path)
        dropdown_options = list(
            identify_indexed_controls(df.columns.unique()).keys())
        realizations = df.index.values
        axis_type = [(i, i) for i in ["Linear", "Log"]]
        axis_options = ["Normal", "Cumulative"]
        interp_types = [
            ("None", None),
            ("Linear", "linear"),
            ("High value", "hv"),
            ("Low value", "vh"),
        ]

        side_bar_config = [
            (
                "radio",
                {
                    "title": "X-axis",
                    "item_id": self.axis_type_x_id,
                    "options": axis_type,
                },
            ),
            (
                "radio",
                {
                    "item_id": self.axis_options_x_id,
                    "options": axis_options
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.dropdown_x_id,
                    "options": dropdown_options
                },
            ),
            (
                "radio",
                {
                    "title": "Y-axis",
                    "item_id": self.axis_type_y_id,
                    "options": axis_type,
                },
            ),
            (
                "radio",
                {
                    "item_id": self.axis_options_y_id,
                    "options": axis_options
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.dropdown_y_id,
                    "options": dropdown_options
                },
            ),
            (
                "radio",
                {
                    "title": "Interpolation type",
                    "item_id": self.interpolation_id,
                    "options": interp_types,
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.dropdown_realization_id,
                    "options": realizations,
                    "multi": True,
                },
            ),
        ]

        return html.Div([
            html.H1(children=self.title, style={"textAlign": "center"}),
            html.Div([
                html.Div(
                    [get_sidebar_layout(side_bar_config)],
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "displaylogo": False,
                                "toImageButtonOptions": {
                                    "filename": "indexed_crossplot"
                                },
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])
Beispiel #28
0
        def update_graph(
            func_list,
            radio_value,
            plot_mode,
            realizations_check,
            realizations_input,
            click_data,
        ):
            # The key_list arguments is the list of functions to plot.
            if func_list is None or len(func_list) == 0:
                return {}

            # Get the data, filter if requested.
            data = get_data(self.csv_file)
            if realizations_check:
                realizations = parse_range(realizations_input)
                if realizations:
                    data = data[data["realization"].isin(realizations)]
            if len(data) == 0:
                return {}

            if radio_value == "Statistics":
                data = calculate_statistics(data)

            data = data.set_index("function")

            # Make a cycle iterator over the plotly colors.
            colors = cycle(DEFAULT_PLOTLY_COLORS)

            traces = []
            for color, key in zip(colors, func_list):
                # Select all data belonging to the current key.
                func_data = data.xs(key)

                # Make the traces, with mean, P10 and P90, shading in between.
                if radio_value == "Statistics":
                    traces.extend(
                        statistics_traces(color, func_data, key, plot_mode))
                else:
                    traces.extend(
                        function_traces(
                            func_list,
                            click_data,
                            color,
                            func_data,
                            key,
                            plot_mode,
                            radio_value,
                        ))

            return {
                "data":
                traces,
                "layout":
                dict(
                    xaxis={
                        "title": "Batch",
                        "tickformat": ",d"
                    },
                    yaxis={"title": "Function Key Value"},
                    hovermode="closest",
                ),
            }
Beispiel #29
0
 def update_dropwdown_y(selected_control):
     df = get_data(self.data_path)
     indexed_controls = identify_indexed_controls(df.columns.unique())
     return dropdown_callback(selected_control, indexed_controls)
Beispiel #30
0
    def layout(self):
        data = get_data(self.csv_file).set_index(
            ["batch", "date", "realization"])
        well_summary_keys = [
            i for i in list(data.columns.unique())
            if i.split(":")[0] in _WELL_RATE_KEYS
        ]
        data = data.reset_index()
        realizations = data["realization"].unique()
        batches = list(data["batch"].unique())
        statistics_toggle = ["Data", "Statistics"]
        target_rate_toggle = ["Off", "On"]

        side_bar_config = [
            (
                "dropdown",
                {
                    "item_id": self.dropdown_key,
                    "options": well_summary_keys,
                    "multi": True,
                },
            ),
            (
                "dropdown",
                {
                    "item_id": self.dropdown_batch,
                    "options": batches,
                    "multi": True
                },
            ),
            (
                "label",
                {
                    "item_id": self.label_id,
                    "text":
                    f"Statistics are calculated based on {len(realizations)} realizations",
                    "style": {},
                },
            ),
            (
                "radio",
                {
                    "item_id": self.radio_statistics,
                    "options": statistics_toggle
                },
            ),
            (
                "radio",
                {
                    "title": "Target rate",
                    "item_id": self.radio_target,
                    "options": target_rate_toggle,
                },
            ),
        ]

        return html.Div([
            html.H1(children=self.title, style={"textAlign": "center"}),
            html.Div([
                html.Div(
                    [get_sidebar_layout(side_bar_config)],
                    style={
                        "width": "29%",
                        "display": "inline-block",
                        "vertical-align": "top",
                    },
                ),
                html.Div(
                    [
                        dcc.Graph(
                            id=self.graph_id,
                            config={
                                "displaylogo": False,
                                "toImageButtonOptions": {
                                    "filename": "wells"
                                },
                            },
                        )
                    ],
                    style={
                        "width": "69%",
                        "display": "inline-block"
                    },
                ),
            ]),
        ])