Skip to content

Commit

Permalink
add fit block for approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
ikaryss committed Apr 19, 2023
1 parent dfad192 commit 37fad1b
Show file tree
Hide file tree
Showing 11 changed files with 2,863 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ tech_tests.ipynb
/pyquac/tts_noisy.csv
/pyquac/tts_fit.csv
/pyquac/sts_default.csv
/pyquac/q5_12-25-43.csv
/pyquac/q6_17-22-18.csv
/pyquac/Showcase.ipynb
/pyquac/app_error_test.py
/pyquac/maindash.py
29 changes: 28 additions & 1 deletion pyquac/assets/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ window.dash_clientside = Object.assign({}, window.dash_clientside, {
click,
close_modal,
close_modal_db,
fit,
x_fit,
y_fit,
fit_curve_show,
x,
y,
z,
Expand All @@ -17,7 +21,8 @@ window.dash_clientside = Object.assign({}, window.dash_clientside, {
xz_scatter,
line_switch,
x_title,
y_title
y_title,

) {
const triggered_id = dash_clientside.callback_context.triggered.map(
(t) => t.prop_id
Expand All @@ -28,6 +33,11 @@ window.dash_clientside = Object.assign({}, window.dash_clientside, {
}
figure = JSON.parse(JSON.stringify(fig));

// figure["layout"]["yaxis"]["range"][0] = Math.min(y);
// figure["layout"]["yaxis"]["range"][1] = Math.max(y);
// figure["layout"]["xaxis"]["range"][0] = Math.min(x);
// figure["layout"]["xaxis"]["range"][1] = Math.max(x);

if (x_click === undefined) {
figure["layout"]["shapes"][0]["visible"] = false;
figure["layout"]["shapes"][1]["visible"] = false;
Expand All @@ -52,6 +62,11 @@ window.dash_clientside = Object.assign({}, window.dash_clientside, {

figure["layout"]["shapes"][1]["y0"] = y_click;
figure["layout"]["shapes"][1]["y1"] = y_click;

// figure["layout"]["yaxis"]["range"][0] = Math.min(y);
// figure["layout"]["yaxis"]["range"][1] = Math.max(y);
// figure["layout"]["xaxis"]["range"][0] = Math.min(x);
// figure["layout"]["xaxis"]["range"][1] = Math.max(x);
}
if (triggered_id === "modal_close.n_clicks") {
figure["layout"]["xaxis"]["title"]["text"] = x_title;
Expand All @@ -76,6 +91,18 @@ window.dash_clientside = Object.assign({}, window.dash_clientside, {
figure["data"][0]["x"] = x;
figure["data"][0]["y"] = y;
figure["data"][0]["z"] = z;

// figure["layout"]["yaxis"]["range"][0] = Math.min(y);
// figure["layout"]["yaxis"]["range"][1] = Math.max(y);
// figure["layout"]["xaxis"]["range"][0] = Math.min(x);
// figure["layout"]["xaxis"]["range"][1] = Math.max(x);
}
if (triggered_id === "fit.n_clicks") {
figure["data"][3]["x"] = x_fit;
figure["data"][3]["y"] = y_fit;
}
if (triggered_id === "fit_curve_show.on") {
figure["data"][3]["visible"] = fit_curve_show;
}
return figure;
},
Expand Down
1 change: 1 addition & 0 deletions pyquac/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
from .navbar import navbar
from .sidebar import sidebar, content
from .modal import modal
from .fit_block import fit_block

# from .property_nav import property_nav
294 changes: 294 additions & 0 deletions pyquac/components/fit_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
from dash.dependencies import Input, Output, State
from dash import html
from dash.exceptions import PreventUpdate
import dash_bootstrap_components as dbc
import dash_daq as daq
from dash import dcc
from pyquac.settings import settings

FIT_STYLE = {
"position": "fixed",
"top": "70px",
"left": "64rem",
"bottom": 0,
"width": "16rem",
"height": "100%",
"z-index": 1,
"overflow-x": "hidden",
"transition": settings.transition_time,
"padding": "0.5rem 1rem",
}

FIT_HIDEN = {
"position": "fixed",
"top": "70px",
"left": "45rem",
"bottom": 0,
"width": "16rem",
"height": "100%",
"z-index": 1,
"overflow-x": "hidden",
"transition": settings.transition_time,
"padding": "0.5rem 1rem",
}


def tooltip_settings(setting_type: str, setting_descr: str):
return html.Div(
[
html.P(
[
html.Span(
setting_type,
id=f"tooltip-target_{setting_type}",
style={"textDecoration": "underline", "cursor": "pointer"},
),
],
className="small",
),
dbc.Tooltip(
setting_descr,
target=f"tooltip-target_{setting_type}",
autohide=False,
),
]
)


def input_settings(
setting_type: str,
setting_descr: str,
setting_id: str,
min_value,
max_value,
default_value,
disabled=True,
):
return (
dbc.NavItem(
[
dbc.Input(
id=setting_id,
type="number",
min=min_value,
max=max_value,
placeholder=setting_type,
disabled=disabled,
html_size=16,
size="sm",
value=default_value,
),
tooltip_settings(setting_type, setting_descr),
]
),
)


thres = input_settings(
"Threshold",
"thres : float between [0., 1.]\nNormalized threshold. Only the peaks with amplitude higher than the threshold will be detected",
"thres",
min_value=0.0,
max_value=1.0,
default_value=0.7,
)

min_dist = input_settings(
"Minimum distance",
"min_dist : int\nMinimum distance between each detected peak. The peak with the highest amplitude is preferred to satisfy this constraint.",
"min_dist",
min_value=1,
max_value=100000,
default_value=75,
)

n_last = input_settings(
"N last",
"n_last : int\nThe number of the highest values (relative to the mean), which are taken into account when searching for peak values",
"n_last",
min_value=1,
max_value=100000,
default_value=20,
)

deg = input_settings(
"Degree value",
"deg : int\nDegree of the fitting polynomial",
"deg",
min_value=1,
max_value=100,
default_value=2,
disabled=False,
)

resolving_zone = input_settings(
"Resolving band value",
"deg : float (0:1)\nRelative part of the captured scan when applying the approximation.",
"res_bnd",
min_value=0.001,
max_value=0.99,
default_value=0.05,
disabled=False,
)

# info_eq = (
# "Polynomial: "
# + r"$$p(x)=c_0+c_1x+...+c_nx^n$$"
# + "\nCosine: "
# + r"$$p(x)=A_1cos(2*\pi\omega x+\theta)$$"
# )
info_eq = r"$$p(x)=c_0+c_1x+...+c_nx^n$$"

# collapse = html.Div(
# [
# dbc.Button(
# "Open fit settings",
# id="collapse-button",
# className="mb-3",
# color="primary",
# n_clicks=0,
# ),
# dbc.Collapse(
# [
# # dbc.Card(dbc.CardBody("Settings for curve fitting")),
# dcc.Markdown(info_eq, className="small", mathjax=True),
# *deg,
# *resolving_zone,
# ],
# id="collapse",
# is_open=False,
# ),
# ]
# )

fit_block = html.Div(
[
dbc.Nav(
[
dbc.NavItem(html.H5("Fit block")),
html.Hr(),
dbc.NavItem(
[
dbc.Row(
[
dbc.Col(
dbc.Row(
daq.BooleanSwitch(
id="x_selection",
on=False,
color="#3459e6",
label="Select x points",
),
)
# dbc.Button(
# "Select x points",
# id="x_selection",
# title="If no points are selected, then fits regarding all existing points",
# size="sm",
# ),
),
dbc.Col(
dbc.Button(
"Clear selection",
id="clear_selection",
title="clearing cache",
size="sm",
),
),
]
),
# html.Div(
# "If no points are selected, then fits regarding all existing points",
# className="small",
# ),
],
class_name="mt-3",
),
dbc.NavItem(
[
html.Div(
children="Points selected: ", id="points_selected_output"
)
],
class_name=["mt-2", "small", "mb-3"],
),
# dbc.NavItem(
# dbc.RadioItems(
# options=[
# {"label": "Polynomial", "value": "poly"},
# {"label": "Cosine", "value": "cos"},
# ],
# value=1,
# id="radioitems-inline-input",
# inline=True,
# )
# ),
html.Hr(),
dcc.Markdown(info_eq, className="small", mathjax=True),
*deg,
*resolving_zone,
# *thres,
# *min_dist,
# *n_last,
dbc.NavItem(
[
dbc.Row(
[
dbc.Col(
html.Div(
"Fit based on manual selection",
className="small",
),
width=8,
),
dbc.Col(
daq.BooleanSwitch(
id="manual_fit",
on=True,
color="#3459e6",
disabled=True,
),
width=4,
),
]
),
],
style={"margin-bottom": "0.5rem"},
),
dbc.NavItem(
[
dbc.Row(
[
dbc.Col(
html.Div(
"Show fitted curve on heatmap",
className="small",
),
width=8,
),
dbc.Col(
daq.BooleanSwitch(
id="fit_curve_show",
on=True,
color="#3459e6",
),
width=4,
),
]
),
],
style={"margin-bottom": "0.5rem"},
),
dbc.NavItem(
dbc.Button(
"Fit Curve",
id="fit",
title="Fit Curve",
),
),
]
),
],
style=FIT_STYLE,
id="fit_block",
)
Loading

0 comments on commit 37fad1b

Please sign in to comment.