@@ -134,7 +134,6 @@ def show_tab2():
134134 dcc .Input (id = 'theme' , type = 'text' , value = f'{ theme } ' , style = {'display' : 'none' }),
135135 dcc .Interval (id = 'interval-component' , interval = millisec , n_intervals = 0 ),
136136 html .Div (id = 'settings_output' , children = '' ),
137-
138137 html .Div (id = 'bar_chart_div' , children = [
139138 html .A ("Learn" , id = "tooltip-link" , href = "#" , style = {"fontSize" : "small" , "textDecoration" : "underline" , "color" : "blue" , "margin-left" :"30px" }),
140139 html .Div (id = 'calibration-output' , children = '' ),
@@ -148,7 +147,7 @@ def show_tab2():
148147
149148 html .Div (id = 't2_setting_div1' , children = [
150149 html .Button ('START' , id = 'start' , n_clicks = 0 ),
151- html . Div ( id = 'start-text' , children = '' ),
150+
152151 html .Div (id = 'counts-output' , children = '' ),
153152 html .Div ('' ),
154153 html .Div (['Max Counts' , dcc .Input (id = 'max_counts' , type = 'number' , step = 1 , readOnly = False , value = max_counts , className = 'input' )]),
@@ -160,7 +159,6 @@ def show_tab2():
160159 html .Div (id = 't2_setting_div2' , children = [
161160 dcc .Store (id = 'store-device' , data = device ),
162161 html .Button ('STOP' , id = 'stop' , className = 'action_button' ),
163- html .Div (id = 'stop-text' , children = '' ),
164162 html .Div (id = 'elapsed' , children = '' ),
165163 html .Div (['Max Seconds' , dcc .Input (id = 'max_seconds' , type = 'number' , step = 1 , readOnly = False , value = max_seconds , className = 'input' )]),
166164 html .Div (id = 'cps' , children = '' ),
@@ -177,9 +175,11 @@ def show_tab2():
177175 {'label' : '8192 Bins' , 'value' : '1' },
178176 ], value = compression , clearable = False )], style = {'display' : serial }),
179177
180- html .Div (['Select existing file:' , dcc .Dropdown (id = 'filenamelist' , options = options_sorted , value = filename , optionHeight = 40 , style = {'textAlign' :'left' , 'textWrap' :None })]),
178+ html .Div (['Select existing file:' , dcc .Dropdown (id = 'filenamelist' , options = filtered_options , value = filename , optionHeight = 40 , style = {'textAlign' :'left' , 'textWrap' :None })]),
181179
182180 html .Div (['Or create new file:' , dcc .Input (id = 'filename' , type = 'text' , value = filename , placeholder = 'Enter new filename' , disabled = False )]),
181+ html .Div (id = 'stop-text' , children = '' ),
182+ html .Div (id = 'start-text' , children = '' ),
183183
184184
185185 dbc .Modal ([
@@ -217,13 +217,15 @@ def show_tab2():
217217 html .Div (['Show Comparison' , daq .BooleanSwitch (id = 'compare_switch' , on = False , color = 'green' )]),
218218 html .Div (['Subtract Comparison' , daq .BooleanSwitch (id = 'difference_switch' , on = False , color = 'green' )]),
219219 html .Div (['Coincidence' , daq .BooleanSwitch (id = 'coi-switch' , on = coi_switch , color = 'green' )], style = {'display' : audio }),
220+ html .Div (['Supress Last Bin' , daq .BooleanSwitch (id = 'slb-switch' , on = slb_switch , color = 'green' )], style = {'display' : serial }),
221+
220222 ]),
221223
222224 html .Div (id = 't2_setting_div6' , children = [
223225 html .Div (['Energy by bin' , daq .BooleanSwitch (id = 'epb-switch' , on = epb_switch , color = 'green' )]),
224226 html .Div (['Show log(y)' , daq .BooleanSwitch (id = 'log-switch' , on = log_switch , color = 'green' )]),
225227 html .Div (['Calibration' , daq .BooleanSwitch (id = 'cal-switch' , on = cal_switch , color = 'green' )]),
226- html .Div (['Supress Last Bin ' , daq .BooleanSwitch (id = 'slb-switch ' , on = slb_switch , color = 'green' )], style = { 'display' : serial } ),
228+ html .Div (['values <-> isotopes ' , daq .BooleanSwitch (id = 'val-flag ' , on = val_flag , color = 'green' )]),
227229 ]),
228230
229231 html .Div (id = 't2_setting_div7' , children = [
@@ -240,11 +242,13 @@ def show_tab2():
240242 ])], id = "confirmation-modal" , centered = True , size = "md" , className = "custom-modal" ),
241243
242244 dcc .Store (id = "confirmation-output" , data = '' ),
243- #html.Button('isotope flags', id='toggle-annotations-button', n_clicks=0, className="action_button"),
244245 dcc .Store (id = 'store-gaussian' ),
245246 dcc .Store (id = 'store-annotations' , data = []),
246247 html .Div ('Gaussian (sigma)' ),
247248 html .Div (dcc .Slider (id = 'sigma' , min = 0 , max = 3 , step = 0.25 , value = sigma , marks = {0 : '0' , 1 : '1' , 2 : '2' , 3 : '3' })),
249+ html .Div ('Peak width (bins)' ),
250+ html .Div (dcc .Slider (id = 'peakfinder' , min = 0 , max = 15 , step = 1 , value = peakfinder , marks = {0 :'off' , 1 :'' ,3 :'' ,5 :'' ,7 :'' ,9 :'' ,11 :'' , 13 :'' , 15 :'15' })),
251+ html .Div ('Isotope lists' ),
248252 dcc .Dropdown (id = 'flags' , options = flag_options , style = {'height' : '15px' , 'fontSize' : '10px' , 'borderwidth' : '0px' , 'textAlign' :'left' }, value = flags_selected , optionHeight = 15 , clearable = False ),
249253 ]),
250254
@@ -255,11 +259,10 @@ def show_tab2():
255259 html .Div (dcc .Input (id = 'calib_bin_3' , type = 'number' , value = calib_bin_3 , className = 'input' )),
256260 html .Div (dcc .Input (id = 'calib_bin_4' , type = 'number' , value = calib_bin_4 , className = 'input' )),
257261 html .Div (dcc .Input (id = 'calib_bin_5' , type = 'number' , value = calib_bin_5 , className = 'input' )),
258- html .Div ('Peak width (bins)' ),
259- html .Div (dcc .Slider (id = 'peakfinder' , min = 0 , max = 15 , step = None , value = peakfinder , marks = {'~' :0 , 1 :'1' ,3 :'3' ,5 :'5' ,7 :'7' ,9 :'9' ,11 :'11' , 13 :'13' , 15 :'15' })),
260- html .Div (['values <-> isotopes' , daq .BooleanSwitch (id = 'val-flag' , on = val_flag , color = 'green' )]),
261-
262+ html .Button ('Re-calibrate' , id = 'recalibrate' , className = 'action_button' ),
262263 html .Div (id = 'publish-output' , children = '' ),
264+ html .Div (id = 'publish-output2' , children = '' ),
265+
263266 ]),
264267
265268 html .Div (id = 't2_setting_div9' , children = [
@@ -280,17 +283,30 @@ def show_tab2():
280283
281284 return html_tab2
282285
283- # User selection of existing file
286+ # Dropdown filename selection or start new file
284287@app .callback (
285- Output ('filename' , 'value' ),
286- [Input ('filenamelist' , 'value' )],
287- [State ('filename' , 'value' )]
288+ [Output ('filename' , 'value' ),
289+ Output ('spec-notes-input' , 'value' )],
290+ [Input ('filenamelist' , 'value' )],
291+ [State ('filename' , 'value' )]
288292)
289293def update_filename_from_dropdown (selected_file , current_filename ):
290294 if selected_file :
295+ clear_global_vars (2 )
291296 load_histogram (selected_file )
292- return selected_file
293- return current_filename
297+
298+ with global_vars .write_lock :
299+ spec_notes = global_vars .spec_notes
300+
301+ return selected_file , spec_notes
302+
303+ clear_global_vars (2 )
304+ with global_vars .write_lock :
305+ spec_notes = global_vars .spec_notes
306+ current_filename = global_vars .filename
307+
308+
309+ return current_filename , spec_notes
294310
295311# Modal - pop up confirmation screen
296312@app .callback (
@@ -361,12 +377,15 @@ def start_new_2d_spectrum(confirm_clicks, start_clicks, filename, compression, t
361377 dispatcher .start ()
362378
363379 shproto .dispatcher .process_03 ('-mode 0' )
380+ time .sleep (0.05 )
364381 logger .info (f'tab2 restores -mode 0\n ' )
365382
366383 shproto .dispatcher .process_03 ('-rst' )
384+ time .sleep (0.05 )
367385 logger .info (f'tab2 sends reset command -rst\n ' )
368386
369387 shproto .dispatcher .process_03 ('-sta' )
388+ time .sleep (0.05 )
370389 logger .info (f'tab2 sends start command -sta\n ' )
371390
372391 shproto .dispatcher .process_01 (filename , compression , "MAX" , t_interval )
@@ -384,7 +403,7 @@ def start_new_2d_spectrum(confirm_clicks, start_clicks, filename, compression, t
384403
385404# Stop Button function--------------
386405@app .callback (
387- Output ('stop-text' , 'children' ),
406+ [ Output ('stop-text' , 'children' )] ,
388407 [Input ('stop' , 'n_clicks' )],
389408 [State ('store-device' , 'data' )]
390409)
@@ -407,7 +426,11 @@ def stop_button(n_clicks, dn):
407426 else :
408427 stop_recording ()
409428 logger .info ('tab2-stop button device is PRO\n ' )
410- return
429+
430+ options_sorted = get_options ()
431+ filtered_options = [option for option in options_sorted if not option ['label' ].startswith ('•' )]
432+
433+ return ["Recording stopped" ]
411434
412435# Update histogram interval function
413436@app .callback ([
@@ -420,8 +443,8 @@ def stop_button(n_clicks, dn):
420443 [Input ('interval-component' , 'n_intervals' ),
421444 Input ('bar_chart' , 'relayoutData' ),
422445 Input ('store-annotations' , 'data' ),
423- Input ('filename' , 'value' )],
424- [State ('epb-switch' , 'on' ),
446+ Input ('filename' , 'value' )],
447+ [State ('epb-switch' , 'on' ),
425448 State ('log-switch' , 'on' ),
426449 State ('cal-switch' , 'on' ),
427450 State ('filename_2' , 'value' ),
@@ -473,7 +496,7 @@ def update_graph(
473496 date = now .strftime ('%d-%m-%Y' )
474497 prefixx = 'bin'
475498 prefixy = 'cts'
476- isotopes_data = get_isotopes (flags )
499+ isotopes_data = get_isotopes (flags or {} )
477500
478501 if epb_switch :
479502 log_switch = False
@@ -605,9 +628,10 @@ def update_graph(
605628 # If calibrated, find isotopes matches
606629 if cal_switch :
607630 calibrated_peaks = [(np .polyval (np .poly1d (coefficients_1 ), peak ), y [peak ]) for peak in peaks ]
608- isotopes_match = matching_isotopes (calibrated_peaks , isotopes_data , peakfinder )
609- else :
610- isotopes_match = {}
631+ try :
632+ isotopes_match = matching_isotopes (calibrated_peaks , isotopes_data , peakfinder )
633+ except :
634+ isotopes_match = {}
611635
612636 # Annotate peaks if peakfinder != 0
613637 if peakfinder != 0 :
@@ -705,7 +729,7 @@ def update_graph(
705729 title_dict = {
706730 'text' : f'{ filename } - { counts } valid counts - { dropped_counts } lost counts - { elapsed } seconds - { coincidence } - { date } ' ,
707731 'x' : 0.02 ,
708- 'y' : 0.95 ,
732+ 'y' : 0.96 ,
709733 'xanchor' : 'left' ,
710734 'yanchor' : 'top' ,
711735 'font' : {'family' : 'Arial' , 'size' : 15 , 'color' : line_color },
@@ -801,7 +825,7 @@ def update_graph(
801825 title = title_dict
802826 )
803827
804- return fig , f'{ counts } ' , f'{ elapsed } ' , f'cps { cps } ' , f'{ dropped_counts } lost counts ' , gaussian
828+ return fig , f'{ counts or 0 } ' , f'{ elapsed or 0 } ' , f'cps { cps or 0 } ' , f'{ dropped_counts or 0 } lost counts ' , gaussian or []
805829
806830# Save settings callback function
807831@app .callback (
@@ -864,12 +888,14 @@ def save_settings(*args):
864888 Input ('calib_bin_3' , 'value' ), # [2]
865889 Input ('calib_bin_4' , 'value' ), # [3]
866890 Input ('calib_bin_5' , 'value' ), # [4]
867- Input ('calib_e_1' , 'value' ), # [5]
868- Input ('calib_e_2' , 'value' ), # [6]
869- Input ('calib_e_3' , 'value' ), # [7]
870- Input ('calib_e_4' , 'value' ), # [8]
871- Input ('calib_e_5' , 'value' )] # [9]
872- )
891+ Input ('calib_e_1' , 'value' ), # [5]
892+ Input ('calib_e_2' , 'value' ), # [6]
893+ Input ('calib_e_3' , 'value' ), # [7]
894+ Input ('calib_e_4' , 'value' ), # [8]
895+ Input ('calib_e_5' , 'value' ),
896+ Input ('cal-switch' , 'on' ),
897+ Input ('val-flag' , 'on' )],
898+ )
873899def save_calibrations (* args ):
874900 # Ensure that only valid numerical inputs (not None and greater than 0) are included
875901 x_bins = [x for x in [args [0 ], args [1 ], args [2 ], args [3 ], args [4 ]] if x is not None and x > 0 ]
@@ -918,7 +944,7 @@ def save_calibrations(*args):
918944
919945 polynomial_fn = np .poly1d (coefficients_1 )
920946
921- return f'{ message } = { polynomial_fn } '
947+ return f'{ message } [ { polynomial_fn } ] '
922948
923949
924950# Callback function for playing sound
@@ -998,13 +1024,17 @@ def display_confirmation_result(confirm_publish_clicks, cancel_publish_clicks, f
9981024
9991025 return ""
10001026
1001- #update spectrum notes
1027+ #update spectrum notes and calibration
10021028@app .callback (
10031029 Output ('spec-notes-output' , 'children' ),
1004- [Input ('spec-notes-input' , 'value' ),
1005- Input ('filename' , 'value' )],
1030+ Output ('publish-output2' , 'children' ),
1031+ Input ('recalibrate' , 'n_clicks' ),
1032+ [State ('spec-notes-input' , 'value' ),
1033+ State ('filename' , 'value' )],
10061034)
1007- def update_spectrum_notes (spec_notes , filename ):
1035+ def update_spectrum_notes (n_clicks , spec_notes , filename ):
1036+ if n_clicks is None :
1037+ raise PreventUpdate
10081038
10091039 with global_vars .write_lock :
10101040 global_vars .spec_notes = spec_notes
@@ -1013,13 +1043,16 @@ def update_spectrum_notes(spec_notes, filename):
10131043
10141044 update_json_notes (filename , spec_notes )
10151045
1016- logger .info (f'tab2 spectrum notes updated { spec_notes } \n ' )
10171046
1018- return spec_notes
1047+ logger .info (f'tab2 spectrum notes updated { spec_notes } \n ' )
1048+
1049+ confirmation = f"Spectrum notes and calibration written to { filename } .json"
1050+
1051+ return spec_notes , confirmation
10191052
10201053# callback for exporting to csv
10211054@app .callback (Output ('export_histogram_output' , 'children' ),
1022- Input ('export-histogram' , 'value' ),
1055+ Input ('export-histogram' , 'value' ),
10231056 State ('cal-switch' , 'on' )
10241057 )
10251058def export_histogram (filename , cal_switch ):
0 commit comments