feat: Sampling function in settings popup
This commit is contained in:
@ -5,9 +5,13 @@ import dash_bootstrap_components as dbc
|
||||
|
||||
|
||||
# on crée l'application
|
||||
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.DARKLY, dbc.icons.BOOTSTRAP], use_pages=True)
|
||||
app = dash.Dash(
|
||||
__name__,
|
||||
external_stylesheets=[dbc.themes.DARKLY, dbc.icons.BOOTSTRAP],
|
||||
use_pages=True,
|
||||
)
|
||||
|
||||
print('Reloading...')
|
||||
print("Reloading...")
|
||||
|
||||
|
||||
# on lit le fichier modal.md pour le tuto
|
||||
@ -35,16 +39,54 @@ modal_settings = dbc.Modal(
|
||||
value=False,
|
||||
className="me-2",
|
||||
),
|
||||
dbc.Input(
|
||||
id="echantillonage-x",
|
||||
type="number",
|
||||
placeholder="Echantillonage X",
|
||||
style={"width": "100px"},
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Col(
|
||||
[
|
||||
dbc.Label("X Sampling"),
|
||||
dbc.Input(
|
||||
id="echantillonage-x",
|
||||
type="number",
|
||||
placeholder="X Sampling",
|
||||
value=1,
|
||||
),
|
||||
]
|
||||
),
|
||||
dbc.Col(
|
||||
[
|
||||
dbc.Label("Y Sampling"),
|
||||
dbc.Input(
|
||||
id="echantillonage-y",
|
||||
type="number",
|
||||
placeholder="Y Sampling",
|
||||
value=32,
|
||||
),
|
||||
]
|
||||
),
|
||||
dbc.Col(
|
||||
[
|
||||
dbc.Label("Z Sampling"),
|
||||
dbc.Input(
|
||||
id="echantillonage-z",
|
||||
type="number",
|
||||
placeholder="Z Sampling",
|
||||
value=1,
|
||||
),
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
dbc.ModalFooter(
|
||||
dbc.Button("Close", id="settings-close", className="settings-bn"),
|
||||
[
|
||||
dbc.Button(
|
||||
dbc.Spinner(html.Div("Apply", id="settings-spinner")),
|
||||
id="settings-apply",
|
||||
color="success",
|
||||
),
|
||||
dbc.Button("Close", id="settings-close", className="settings-bn"),
|
||||
]
|
||||
),
|
||||
],
|
||||
id="settings-modal",
|
||||
@ -156,7 +198,11 @@ nav_bar = dbc.Navbar(
|
||||
[
|
||||
dbc.Collapse(
|
||||
dbc.Nav(
|
||||
[dbc.NavItem(button_howto), dbc.NavItem(button_gh), dbc.NavItem(button_settings)],
|
||||
[
|
||||
dbc.NavItem(button_howto),
|
||||
dbc.NavItem(button_gh),
|
||||
dbc.NavItem(button_settings),
|
||||
],
|
||||
className="ml-auto",
|
||||
navbar=True,
|
||||
),
|
||||
@ -182,7 +228,19 @@ nav_bar = dbc.Navbar(
|
||||
|
||||
# on défini le layout de l'application
|
||||
app.layout = dbc.Container(
|
||||
[nav_bar, dash.page_container],
|
||||
[
|
||||
nav_bar,
|
||||
dash.page_container,
|
||||
dcc.Store(
|
||||
id="store-settings",
|
||||
data={
|
||||
"use_real_values": False,
|
||||
"echantillonage_x": 1,
|
||||
"echantillonage_y": 32,
|
||||
"echantillonage_z": 1,
|
||||
},
|
||||
),
|
||||
],
|
||||
fluid=True,
|
||||
)
|
||||
|
||||
@ -198,6 +256,7 @@ def toggle_modal(n1, n2, is_open):
|
||||
return not is_open
|
||||
return is_open
|
||||
|
||||
|
||||
@app.callback(
|
||||
Output("settings-modal", "is_open"),
|
||||
[Input("settings-open", "n_clicks"), Input("settings-close", "n_clicks")],
|
||||
@ -223,4 +282,4 @@ def toggle_offcanvas(n, is_open):
|
||||
|
||||
# on lance l'application
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, port="8051")
|
||||
app.run(debug=True, port="8051", threaded=True)
|
||||
|
@ -159,7 +159,7 @@ layout = html.Div(
|
||||
max=dim_x,
|
||||
value=1,
|
||||
step=1,
|
||||
marks={str(i): str(i) for i in range(1, dim_x + 1, 1)},
|
||||
marks={str(i): str(i) for i in range(1, dim_x + 1, max(1, int(dim_x / 20)))},
|
||||
),
|
||||
dbc.Label("z"),
|
||||
dcc.RangeSlider(
|
||||
@ -169,7 +169,7 @@ layout = html.Div(
|
||||
value=[dim_y / dim_y, dim_y],
|
||||
step=1,
|
||||
marks={
|
||||
str(i): str(i) for i in range(0, dim_x + 1, max(1, int(dim_x / 20)))
|
||||
str(i): str(i) for i in range(0, dim_y + 1, max(1, int(dim_y / 20)))
|
||||
},
|
||||
),
|
||||
dbc.Row(
|
||||
@ -414,16 +414,16 @@ def update_heatmap_ascan(
|
||||
data_avec_traitement = switch_case(
|
||||
data_avec_traitement,
|
||||
int(select_filtre_1),
|
||||
float(fs_filtre_1),
|
||||
float(cutoff_filtre_1),
|
||||
float(fs_filtre_1), # type: ignore
|
||||
float(cutoff_filtre_1), # type: ignore
|
||||
int(order_filtre_1),
|
||||
int(windowsize_filtre_1),
|
||||
)
|
||||
data_avec_traitement = switch_case(
|
||||
data_avec_traitement,
|
||||
int(select_filtre_2),
|
||||
float(fs_filtre_2),
|
||||
float(cutoff_filtre_2),
|
||||
float(fs_filtre_2), # type: ignore
|
||||
float(cutoff_filtre_2), # type: ignore
|
||||
int(order_filtre_2),
|
||||
int(windowsize_filtre_2),
|
||||
)
|
||||
@ -433,16 +433,16 @@ def update_heatmap_ascan(
|
||||
data_traits = switch_case(
|
||||
data_traits,
|
||||
int(select_filtre_1),
|
||||
float(fs_filtre_1),
|
||||
float(cutoff_filtre_1),
|
||||
float(fs_filtre_1), # type: ignore
|
||||
float(cutoff_filtre_1), # type: ignore
|
||||
int(order_filtre_1),
|
||||
int(windowsize_filtre_1),
|
||||
)
|
||||
data_traits = switch_case(
|
||||
data_traits,
|
||||
int(select_filtre_2),
|
||||
float(fs_filtre_2),
|
||||
float(cutoff_filtre_2),
|
||||
float(fs_filtre_2), # type: ignore
|
||||
float(cutoff_filtre_2), # type: ignore
|
||||
int(order_filtre_2),
|
||||
int(windowsize_filtre_2),
|
||||
)
|
||||
@ -460,16 +460,16 @@ def update_heatmap_ascan(
|
||||
data_bscan = switch_case(
|
||||
data_bscan,
|
||||
int(select_filtre_1),
|
||||
float(fs_filtre_1),
|
||||
float(cutoff_filtre_1),
|
||||
float(fs_filtre_1), # type: ignore
|
||||
float(cutoff_filtre_1), # type: ignore
|
||||
int(order_filtre_1),
|
||||
int(windowsize_filtre_1),
|
||||
)
|
||||
data_bscan = switch_case(
|
||||
data_bscan,
|
||||
int(select_filtre_2),
|
||||
float(fs_filtre_2),
|
||||
float(cutoff_filtre_2),
|
||||
float(fs_filtre_2), # type: ignore
|
||||
float(cutoff_filtre_2), # type: ignore
|
||||
int(order_filtre_2),
|
||||
int(windowsize_filtre_2),
|
||||
)
|
||||
@ -480,4 +480,4 @@ def update_heatmap_ascan(
|
||||
title="B-scan ZX",
|
||||
)
|
||||
|
||||
return [fig, fig2, "Valider"]
|
||||
return [fig, fig2, "Valider"]
|
@ -458,7 +458,6 @@ layout = html.Div(
|
||||
),
|
||||
dcc.Store(id="store-bscan-xy-layer", data=1),
|
||||
dcc.Store(id="store-bscan-zx-layer", data=0),
|
||||
dcc.Store(id="store-settings", data={"use_real_values": False, "echantillonage_x": 1, "echantillonage_y": 32, "echantillonage_z": 1}),
|
||||
]
|
||||
)
|
||||
|
||||
@ -771,8 +770,60 @@ def update_bscan_layers(bscan_xy, bscan_zx):
|
||||
|
||||
|
||||
@callback(
|
||||
Output("store-settings", "data"),
|
||||
[Input("use-real-values", "value")],
|
||||
[Output("store-settings", "data"), Output("settings-apply", "n_clicks")],
|
||||
[
|
||||
Input("use-real-values", "value"),
|
||||
Input("echantillonage-x", "value"),
|
||||
Input("echantillonage-y", "value"),
|
||||
Input("echantillonage-z", "value"),
|
||||
Input("settings-apply", "n_clicks"),
|
||||
],
|
||||
prevent_initial_call=True,
|
||||
)
|
||||
def update_settings(use_real_values):
|
||||
return {"use_real_values": use_real_values}
|
||||
def update_settings(
|
||||
use_real_values,
|
||||
echantillonage_x_value,
|
||||
echantillonage_y_value,
|
||||
echantillonage_z_value,
|
||||
clicks,
|
||||
):
|
||||
if clicks != None and clicks == 1:
|
||||
return [
|
||||
{
|
||||
"use_real_values": use_real_values,
|
||||
"echantillonage_x": echantillonage_x_value,
|
||||
"echantillonage_y": echantillonage_y_value,
|
||||
"echantillonage_z": echantillonage_z_value,
|
||||
},
|
||||
0,
|
||||
]
|
||||
|
||||
|
||||
@callback(
|
||||
[
|
||||
Output("layer-slider-bscan-zx", "max"),
|
||||
Output("layer-slider-bscan-zx", "marks"),
|
||||
Output("layer-slider-bscan-xy", "max"),
|
||||
Output("layer-slider-bscan-xy", "marks"),
|
||||
Output("settings-spinner", "children")
|
||||
],
|
||||
Input("store-settings", "data"),
|
||||
prevent_initial_call=True
|
||||
)
|
||||
def redef_data(data):
|
||||
global volume, dim_x, dim_y, dim_z, X, Y, Z
|
||||
volume = pre_volume[
|
||||
:: data["echantillonage_x"],
|
||||
:: data["echantillonage_y"],
|
||||
:: data["echantillonage_z"],
|
||||
]
|
||||
dim_x, dim_y, dim_z = volume.shape
|
||||
X, Y, Z = np.mgrid[0:dim_x, 0:dim_y, 0:dim_z]
|
||||
|
||||
return [
|
||||
dim_x - 1,
|
||||
{str(i): str(i) for i in range(0, dim_x, max(1, int(dim_x / 20)))},
|
||||
dim_z - 1,
|
||||
{str(i): str(i) for i in range(1, dim_z + 1, max(1, int(dim_z / 20)))},
|
||||
"Apply",
|
||||
]
|
||||
|
Reference in New Issue
Block a user