-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
1412 lines (1258 loc) · 43.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# In[]:
# Import required libraries
import numpy as np
import plotly.graph_objs as go
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State
import dash_daq as daq
from dash_daq_drivers import keithley_instruments
# Instance of a Keithley2400 connected with Prologix GPIB to USB controller
iv_generator = keithley_instruments.KT2400(
mock_mode=False
)
def is_instrument_port(port_name):
"""test if a string can be a com of gpib port"""
answer = False
if isinstance(port_name, str):
ports = ['COM', 'com', 'GPIB0::', 'gpib0::']
for port in ports:
if port in port_name:
answer = not (port == port_name)
return answer
class UsefulVariables:
"""Class to store information useful to callbacks"""
def __init__(self):
self.n_clicks = 0
self.n_clicks_clear_graph = 0
self.n_refresh = 0
self.source = 'V'
self.is_source_being_changed = False
self.mode = 'single'
self.sourced_values = []
self.measured_values = []
def change_n_clicks(self, nclicks):
self.n_clicks = nclicks
def change_n_clicks_clear_graph(self, nclicks):
self.n_clicks_clear_graph = nclicks
def reset_n_clicks(self):
self.n_clicks = 0
self.n_clicks_clear_graph = 0
def change_n_refresh(self, nrefresh):
self.n_refresh = nrefresh
def reset_interval(self):
self.n_refresh = 0
def clear_graph(self):
self.sourced_values = []
self.measured_values = []
def sorted_values(self):
""" Sort the data so the are ascending according to the source """
data_array = np.vstack(
[
local_vars.sourced_values,
local_vars.measured_values
]
)
data_array = data_array[:, data_array[0, :].argsort()]
return data_array
local_vars = UsefulVariables()
# font and background colors associated with each themes
bkg_color = {'dark': '#2a3f5f', 'light': '#F3F6FA'}
grid_color = {'dark': 'white', 'light': '#C8D4E3'}
text_color = {'dark': 'white', 'light': '#506784'}
# Define the app
app = dash.Dash(__name__)
server = app.server
app.config.suppress_callback_exceptions = False
# Load css file
external_css = ["https://codepen.io/bachibouzouk/pen/ZRjdZN.css"]
for css in external_css:
app.css.append_css({"external_url": css})
def get_source_labels(source='V'):
"""labels for source/measure elements"""
if source == 'V':
# we source voltage and measure current
source_label = 'Voltage'
measure_label = 'Current'
elif source == 'I':
# we source current and measure voltage
source_label = 'Current'
measure_label = 'Voltage'
return source_label, measure_label
def get_source_units(source='V'):
"""units for source/measure elements"""
if source == 'V':
# we source voltage and measure current
source_unit = 'V'
measure_unit = 'A'
elif source == 'I':
# we source current and measure voltage
source_unit = 'μA'
measure_unit = 'V'
return source_unit, measure_unit
def get_source_max(source='V'):
"""units for source/measure elements"""
if source == 'V':
# we source voltage and measure current
return 20
elif source == 'I':
# we source current and measure voltage
return 100
h_style = {
'display': 'flex',
'flex-direction': 'row',
'alignItems': 'center',
'justifyContent': 'space-between',
'margin': '5px'
}
# Create controls using a function
def generate_main_layout(
theme='light',
src_type='V',
mode_val='single',
fig=None,
sourcemeter=iv_generator
):
"""generate the layout of the app"""
source_label, measure_label = get_source_labels(src_type)
source_unit, measure_unit = get_source_units(src_type)
source_max = get_source_max(src_type)
if mode_val == 'single':
single_style = {
'display': 'flex',
'flex-direction': 'column',
'alignItems': 'center'
}
sweep_style = {'display': 'none'}
label_btn = 'Single measure'
else:
single_style = {'display': 'none'}
sweep_style = {
'display': 'flex',
'flex-direction': 'column',
'alignItems': 'center'
}
label_btn = 'Start sweep'
# As the trigger-measure btn will have its n_clicks reset by the reloading
# of the layout we need to reset this one as well
local_vars.reset_n_clicks()
# Doesn't clear the data of the graph
if fig is None:
data = []
else:
data = fig['data']
html_layout = [
html.Div(
className='row',
children=[
# graph to trace out the result(s) of the measurement(s)
html.Div(
id='IV_graph_div',
className="eight columns",
children=[
dcc.Graph(
id='IV_graph',
figure={
'data': data,
'layout': dict(
paper_bgcolor=bkg_color[theme],
plot_bgcolor=bkg_color[theme],
font=dict(
color=text_color[theme],
size=15,
),
xaxis={
'color': grid_color[theme],
'gridcolor': grid_color[theme]
},
yaxis={
'color': grid_color[theme],
'gridcolor': grid_color[theme]
}
)
}
)
]
),
# controls and options for the IV tracer
html.Div(
className="two columns",
id='IV-options_div',
children=[
html.H4(
'Sourcing',
title='Choose whether you want to source voltage '
'and measure current or source current and '
'measure voltage'
),
dcc.RadioItems(
id='source-choice',
options=[
{'label': 'Voltage', 'value': 'V'},
{'label': 'Current', 'value': 'I'}
],
value=src_type
),
html.Br(),
html.H4(
'Measure mode',
title='Choose if you want to do single measurement'
' or to start a sweep'
),
dcc.RadioItems(
id='mode-choice',
options=[
{'label': 'Single measure', 'value': 'single'},
{'label': 'Sweep', 'value': 'sweep'}
],
value=mode_val
),
html.Br(),
html.Div(
daq.StopButton(
id='clear-graph_btn',
buttonText='Clear graph',
size=150
),
style={
'alignItems': 'center',
'display': 'flex',
'flex-direction': 'row'
}
),
html.Br(),
daq.Indicator(
id='clear-graph_ind',
value=False,
style={'display': 'none'}
)
]
),
# controls for the connexion to the instrument
html.Div(
id='instr_controls',
children=[
html.H4(
sourcemeter.instr_user_name,
),
# A button to turn the instrument on or off
html.Div(
children=[
html.Div(
id='power_button_div',
children=daq.PowerButton(
id='power_button',
on='false'
)
),
html.Br(),
html.Div(
children=daq.Indicator(
id='mock_indicator',
value=sourcemeter.mock_mode,
label='is mock?'
),
style={'margin': '20px'},
title='If the indicator is on, it means '
'the instrument is in mock mode'
)
],
style=h_style
),
# An input to choose the COM/GPIB port
dcc.Input(
id='instr_port_input',
placeholder='Enter port name...',
type='text',
value=''
),
html.Br(),
# A button which will initiate the connexion
daq.StopButton(
id='instr_port_button',
buttonText='Connect',
disabled=True
),
html.Br(),
html.Div(
id='instr_status_div',
children="",
style={'margin': '10 px'}
)
],
style={
'display': 'flex',
'flex-direction': 'column',
'alignItems': 'center',
'justifyContent': 'space-between',
'border': '2px solid #C8D4E3',
'background': '#f2f5fa'
}
)
]
),
html.Div(
id='measure_controls_div',
className='row',
children=[
# Sourcing controls
html.Div(
id='source-div',
className="three columns",
children=[
# To perform single measures adjusting the source with
# a knob
html.Div(
id='single_div',
children=[
daq.Knob(
id='source-knob',
value=0.00,
min=0,
max=source_max,
label='%s (%s)' % (
source_label,
source_unit
)
),
daq.LEDDisplay(
id="source-knob-display",
label='Knob readout',
value=0.00
)
],
style=single_style
),
# To perfom automatic sweeps of the source
html.Div(
id='sweep_div',
children=[
html.Div(
id='sweep-title',
children=html.H4(
"%s sweep:" % source_label
)
),
html.Div(
[
'Start',
html.Br(),
daq.PrecisionInput(
id='sweep-start',
precision=4,
min=0,
max=source_max,
label=' %s' % source_unit,
labelPosition='right',
value=1,
style={'margin': '5px'}
),
],
title='The lowest value of the sweep',
style=h_style
),
html.Div(
[
'Stop',
daq.PrecisionInput(
id='sweep-stop',
precision=4,
min=0,
max=source_max,
label=' %s' % source_unit,
labelPosition='right',
value=9,
style={'margin': '5px'}
)
],
title='The highest value of the sweep',
style=h_style
),
html.Div(
[
'Step',
daq.PrecisionInput(
id='sweep-step',
precision=4,
min=0,
max=source_max,
label=' %s' % source_unit,
labelPosition='right',
value=source_max / 20.,
style={'margin': '5px'}
)
],
title='The increment of the sweep',
style=h_style
),
html.Div(
[
'Time of a step',
daq.NumericInput(
id='sweep-dt',
value=0.5,
min=0.1,
style={'margin': '5px'}
),
's'
],
title='The time spent on each increment',
style=h_style
),
html.Div(
[
daq.Indicator(
id='sweep-status',
label='Sweep active',
value=False
)
],
title='Indicates if the sweep is running',
style=h_style
)
],
style=sweep_style
)
]
),
# measure button and indicator
html.Div(
id='trigger_div',
className="two columns",
children=[
daq.StopButton(
id='trigger-measure_btn',
buttonText=label_btn,
size=150
),
daq.Indicator(
id='measure-triggered',
value=False,
label='Measure active'
),
]
),
# Display the sourced and measured values
html.Div(
id='measure_div',
className="five columns",
children=[
daq.LEDDisplay(
id="source-display",
label='Applied %s (%s)' % (
source_label,
source_unit
),
value="0.0000"
),
daq.LEDDisplay(
id="measure-display",
label='Measured %s (%s)' % (
measure_label,
measure_unit
),
value="0.0000"
)
]
)
],
style={
'width': '100%',
'flexDirection': 'column',
'alignItems': 'center',
'justifyContent': 'space-between'
}
),
html.Div(
children=[
html.Div(
children=dcc.Markdown('''
**What is this app about?**
This is an app to show the graphic elements of Dash DAQ used to create an
interface for an IV curve tracer using a Keithley 2400 SourceMeter. This mock
demo does not actually connect to a physical instrument the values displayed
are generated from an IV curve model for demonstration purposes.
**How to use the app**
First choose if you want to source (apply) current or voltage, using the radio
item located on the right of the graph area. Then choose if you want to operate
in a single measurement mode or in a sweep mode.
***Single measurement mode***
Adjust the value of the source with the knob at the bottom of the graph area
and click on the `SINGLE MEASURE` button, the measured value will be displayed.
Repetition of this procedure for different source values will reveal the full
IV curve.
***Sweep mode***
Set the sweep parameters `start`, `stop` and `step` as well as the time
spent on each step, then click on the button `START SWEEP`, the result of the
sweep will be displayed on the graph.
The data is never erased unless the button `CLEAR GRAPH is pressed` or if the
source type is changed.
You can purchase the Dash DAQ components at [
dashdaq.io](https://www.dashdaq.io/)
'''),
style={
'max-width': '600px',
'margin': '15px auto 300 px auto',
'padding': '40px',
'alignItems': 'left',
'box-shadow': '10px 10px 5px rgba(0, 0, 0, 0.2)',
'border': '1px solid #DFE8F3',
'color': text_color[theme],
'background': bkg_color[theme]
}
)
]
)
]
if theme == 'dark':
return daq.DarkThemeProvider(children=html_layout)
elif theme == 'light':
return html_layout
root_layout = html.Div(
id='main_page',
children=[
dcc.Location(id='url', refresh=False),
dcc.Interval(id='refresher', interval=1000000),
html.Div(
id='header',
className='banner',
children=[
html.H2('Dash DAQ: IV curve tracer'),
daq.ToggleSwitch(
id='toggleTheme',
label='Dark/Light layout',
size=30,
style={'display': 'none'}
),
html.Img(
src='https://s3-us-west-1.amazonaws.com/plotly'
'-tutorials/excel/dash-daq/dash-daq-logo'
'-by-plotly-stripe.png',
style={
'height': '100',
'float': 'right',
}
)
],
style={
'width': '100%',
'display': 'flex',
'flexDirection': 'row',
'alignItems': 'center',
'justifyContent': 'space-between',
'background': '#A2B1C6',
'color': '#506784'
}
),
html.Div(
id='page-content',
children=generate_main_layout(),
# className='ten columns',
style={
'width': '100%'
}
)
]
)
# In[]:
# Create app layout
app.layout = root_layout
# In[]:
# Create callbacks
# ======= Dark/light themes callbacks =======
@app.callback(
Output('page-content', 'children'),
[
Input('toggleTheme', 'value')
],
[
State('source-choice', 'value'),
State('mode-choice', 'value'),
State('IV_graph', 'figure')
]
)
def page_layout(value, src_type, mode_val, fig):
"""update the theme of the daq components"""
if value:
return generate_main_layout('dark', src_type, mode_val, fig)
else:
return generate_main_layout('light', src_type, mode_val, fig)
@app.callback(
Output('page-content', 'style'),
[Input('toggleTheme', 'value')],
[State('page-content', 'style')]
)
def page_style(value, style_dict):
"""update the theme of the app"""
if value:
theme = 'dark'
else:
theme = 'light'
style_dict['color'] = text_color[theme]
style_dict['background'] = bkg_color[theme]
return style_dict
# ======= Power on/off toggle callbacks =======
@app.callback(
Output('instr_port_button', 'disabled'),
[
Input('power_button', 'on'),
Input('instr_port_input', 'value')
],
[
State('instr_port_input', 'value'),
State('instr_port_input', 'placeholder')
]
)
def instrument_port_btn_update(pwr_status, _, text, placeholder):
"""enable or disable the connect button
depending on the port name
"""
answer = True
if text != placeholder:
if is_instrument_port(text):
answer = not pwr_status
return answer
@app.callback(
Output('instr_status_div', 'children'),
[Input('instr_port_button', 'n_clicks')],
[State('instr_port_input', 'value')],
)
def instrument_port_btn_click(_, text):
"""reconnect the instrument to the new com port"""
iv_generator.connect(text)
print(iv_generator.ask('*IDN?'))
return str(iv_generator.ask('*IDN?'))
def automatic_grey_out_callback(div_id, app):
"""generate a callback for the gauges which number can vary from instrument
to instrument.
"""
@app.callback(
Output(div_id, 'style'),
[Input('power_button', 'on')],
[State(div_id, 'style')],
)
def grey_out(pwr_status, style_dict):
if style_dict is None:
answer = {}
else:
answer = style_dict
if pwr_status:
answer['opacity'] = 1
else:
answer['opacity'] = 0.3
return answer
grey_out.__name__ = 'grey_out_%s' % div_id
return grey_out
for div_id in [
'IV_graph_div',
'IV-options_div',
'measure_controls_div',
'measure_div',
'trigger_div'
]:
automatic_grey_out_callback(div_id, app)
def automatic_enable_callback(div_id, app):
"""generate a callback for the gauges which number can vary from instrument
to instrument.
"""
@app.callback(
Output(div_id, 'disabled'),
[Input('power_button', 'on')]
)
def enable(pwr_status):
return not pwr_status
enable.__name__ = 'enable_%s' % div_id
return enable
for div_id in [
'clear-graph_btn',
'trigger-measure_btn',
'source-knob'
]:
automatic_enable_callback(div_id, app)
# ======= Callbacks for changing labels =======
@app.callback(
Output('source-knob', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def source_knob_label(src_type, _):
"""update label upon modification of Radio Items"""
source_label, measure_label = get_source_labels(src_type)
return source_label
@app.callback(
Output('source-knob-display', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def source_knob_display_label(scr_type, _):
"""update label upon modification of Radio Items"""
source_label, measure_label = get_source_labels(scr_type)
source_unit, measure_unit = get_source_units(scr_type)
return 'Value : %s (%s)' % (source_label, source_unit)
@app.callback(
Output('sweep-start', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def sweep_start_label(src_type, _):
"""update label upon modification of Radio Items"""
source_unit, measure_unit = get_source_units(src_type)
return '(%s)' % source_unit
@app.callback(
Output('sweep-stop', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def sweep_stop_label(src_type, _):
"""update label upon modification of Radio Items"""
source_unit, measure_unit = get_source_units(src_type)
return '(%s)' % source_unit
@app.callback(
Output('sweep-step', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def sweep_step_label(src_type, _):
"""update label upon modification of Radio Items"""
source_unit, measure_unit = get_source_units(src_type)
return '(%s)' % source_unit
@app.callback(
Output('sweep-title', 'children'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def sweep_title_label(src_type, _):
"""update label upon modification of Radio Items"""
source_label, measure_label = get_source_labels(src_type)
return html.H4("%s sweep:" % source_label)
@app.callback(
Output('source-display', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def source_display_label(src_type, _):
"""update label upon modification of Radio Items"""
source_label, measure_label = get_source_labels(src_type)
source_unit, measure_unit = get_source_units(src_type)
return 'Applied %s (%s)' % (source_label, source_unit)
@app.callback(
Output('measure-display', 'label'),
[
Input('source-choice', 'value'),
Input('mode-choice', 'value')
],
)
def measure_display_label(src_type, _):
"""update label upon modification of Radio Items"""
source_label, measure_label = get_source_labels(src_type)
source_unit, measure_unit = get_source_units(src_type)
return 'Measured %s (%s)' % (measure_label, measure_unit)
# ======= Callbacks to change elements in the layout =======
@app.callback(
Output('single_div', 'style'),
[Input('mode-choice', 'value')]
)
def single_div_toggle_style(mode_val):
"""toggle the layout for single measure"""
if mode_val == 'single':
return {
'display': 'flex',
'flex-direction': 'column',
'alignItems': 'center'
}
else:
return {'display': 'none'}
@app.callback(
Output('sweep_div', 'style'),
[Input('mode-choice', 'value')]
)
def sweep_div_toggle_style(mode_val):
"""toggle the layout for sweep"""
if mode_val == 'single':
return {'display': 'none'}
else:
return {
'display': 'flex',
'flex-direction': 'column',
'alignItems': 'center'
}
@app.callback(
Output('source-knob', 'max'),
[Input('source-choice', 'value')]
)
def source_knob_max(src_type):
"""update max value upon changing source type"""
return get_source_max(src_type)
@app.callback(
Output('sweep-start', 'max'),
[Input('source-choice', 'value')]
)
def sweep_start_max(src_type):
"""update max value upon changing source type"""
return get_source_max(src_type)
@app.callback(
Output('sweep-stop', 'max'),
[Input('source-choice', 'value')]
)
def sweep_stop_max(src_type):
"""update max value upon changing source type"""
return get_source_max(src_type)
@app.callback(
Output('sweep-step', 'max'),
[Input('source-choice', 'value')]
)
def sweep_step_max(src_type):
"""update max value upon changing source type"""
return get_source_max(src_type)
@app.callback(
Output('trigger-measure_btn', 'buttonText'),
[
Input('measure-triggered', 'value'),
Input('mode-choice', 'value')
],
[
State('trigger-measure_btn', 'buttonText'),
]
)
def toggle_trigger_measure_button_label(measure_triggered, mode_val, btn_text):
"""change the label of the trigger button"""
if mode_val == 'single':
return 'Single measure'
else:
if measure_triggered:
if btn_text == 'Start sweep':
return 'Stop sweep'
else:
return 'Start sweep'
else:
return 'Start sweep'
# ======= Applied/measured values display =======
@app.callback(
Output('source-knob', 'value'),
[Input('source-choice', 'value')],
[State('source-knob', 'value')]
)
def source_change(src_type, src_val):
"""modification upon source-change
change the source type in local_vars
reset the knob to zero
reset the measured values on the graph
"""
if src_type == local_vars.source:
local_vars.is_source_being_changed = False
return src_val
else:
local_vars.is_source_being_changed = True
local_vars.source = src_type
return 0.00
# ======= Interval callbacks =======
@app.callback(
Output('refresher', 'interval'),
[
Input('sweep-status', 'value')
],
[
State('mode-choice', 'value'),
State('sweep-dt', 'value')
]
)
def interval_toggle(swp_on, mode_val, dt):
"""change the interval to high frequency for sweep"""
if dt <= 0:
# Precaution against the user
dt = 0.5
if mode_val == 'single':
return 1000000