Skip to content

Commit bcc8fc9

Browse files
committed
Improved peakfinder
1 parent 2e3958a commit bcc8fc9

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

Diff for: code/functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def peak_finder(y_values, prominence, min_width, smoothing_window=11):
403403
peaks, _ = find_peaks(smoothed_y_values, prominence=prominence, distance=40)
404404

405405
# Calculate widths at relative height 0.3
406-
widths, _, _, _ = peak_widths(smoothed_y_values, peaks, rel_height=0.3)
406+
widths, _, _, _ = peak_widths(smoothed_y_values, peaks, rel_height=0.5)
407407

408408
# Filter peaks based on minimum width
409409
filtered_peaks = [p for i, p in enumerate(peaks) if widths[i] >= min_width]

Diff for: code/impulse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
app.layout = html.Div([
2525
dcc.Tabs(id='tabs', value='tab_1', children=[
2626
dcc.Tab(label='My Details' , value='tab_0'),
27-
dcc.Tab(label='impulse (v2.1.8)', value='tab_1'),
27+
dcc.Tab(label='impulse (v2.1.9)', value='tab_1'),
2828
dcc.Tab(label='2D Histogram' , value='tab_2'),
2929
dcc.Tab(label='3D Histogram' , value='tab_3'),
3030
dcc.Tab(label='Count Rate' , value='tab_4'),

Diff for: code/tab2.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ def show_tab2():
132132

133133
html_tab2 = html.Div(id='tab2', children=[
134134
html.Div(id='main-div', children= [
135-
#html.Div(id='polynomial', children=''),
136-
#html.Div(id='output-roi', children=''),
135+
137136
html.Div(id='bar_chart_div', children=[
138-
139-
dcc.Interval(id='interval-component', interval=millisec, n_intervals=0), # Refresh rate 1s.
137+
html.A("Learn", id="tooltip-link", href="#", style={"fontSize": "small", "textDecoration": "underline", "color": "blue", "margin-left":"30px"}),
138+
dbc.Tooltip("Click and drag to zoom • use box select to select peak • double click on chart to reset • use camera icon to save chart as png" ,target="tooltip-link",placement="right"),
139+
dcc.Interval(id='interval-component', interval=millisec, n_intervals=0),
140140
dcc.Graph(id='bar_chart'),
141141
]),
142142

@@ -259,7 +259,7 @@ def show_tab2():
259259
html.Div(dcc.Input(id='calib_bin_4', type='number', value=calib_bin_4, className='input')),
260260
html.Div(dcc.Input(id='calib_bin_5', type='number', value=calib_bin_5, className='input')),
261261
html.Div('peakfinder'),
262-
html.Div(dcc.Slider(id='peakfinder', min=0, max=5, step=0.1, value=peakfinder, marks={0: '0', 1: '1',2: '2', 3: '3' , 4: '4', 5: '5'})),
262+
html.Div(dcc.Slider(id='peakfinder', min=0, max=10, step=1, value=peakfinder, marks={0:'0',2:'2',4:'4',6:'6',8:'8',10:'10'})),
263263
html.Div(id='publish-output', children=''),
264264
]),
265265

@@ -466,6 +466,9 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
466466
now = datetime.now()
467467
date = now.strftime('%d-%m-%Y')
468468
max_log_value = 0
469+
prefixx = 'bin'
470+
prefixy = 'cts'
471+
min_width = 0
469472

470473
with global_vars.write_lock:
471474
counts = global_vars.counts
@@ -499,7 +502,7 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
499502
plot_bgcolor='#f0f0f0',
500503
showlegend=False,
501504
height=460,
502-
margin=dict(t=20, b=0, l=0, r=0),
505+
margin=dict(t=50, b=0, l=0, r=0),
503506
autosize=True,
504507
yaxis=dict(range=[0, 'auto']),
505508
xaxis=dict(range=[0, 'auto'],
@@ -527,7 +530,8 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
527530

528531
if counts > 0:
529532

530-
prominence = 0.5
533+
prominence = peakfinder * 1.5
534+
min_width = peakfinder * 1
531535

532536
if sigma == 0:
533537
gaussian = []
@@ -550,6 +554,7 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
550554
if epb_switch:
551555
y = [i * count for i, count in enumerate(histogram)]
552556
gaussian = [i * count for i, count in enumerate(gaussian)]
557+
prefixy = 'E'
553558

554559
trace1 = go.Bar(
555560
x=x,
@@ -570,14 +575,14 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
570575
)
571576
fig.add_trace(trace1)
572577

573-
peaks, fwhm = peak_finder(y, prominence, peakfinder)
578+
peaks, fwhm = peak_finder(y, prominence, min_width)
574579

575580
for i in range(len(peaks)):
576581
peak_value = peaks[i]
577582
bin_counts = y[peaks[i]]
578583
x_pos = peaks[i]
579584
y_pos = y[peaks[i]]
580-
y_pos_ann = int(y_pos * 1.05)
585+
y_pos_ann = int(y_pos * 1.1)
581586
resolution = (fwhm[i] / peaks[i]) * 100
582587

583588
if y_pos_ann > (max_value * 0.9):
@@ -587,10 +592,10 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
587592
peak_value = np.polyval(np.poly1d(coefficients_1), peak_value)
588593
x_pos = peak_value
589594
suffix = "keV"
590-
prefix = " "
595+
prefixx = ""
591596
else:
592597
suffix =" "
593-
prefix = "bin "
598+
prefixx = "bin "
594599

595600
if log_switch:
596601
y_pos_ann = np.log10(y_pos * 1.05)
@@ -601,10 +606,12 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
601606
y=y_pos_ann,
602607
xref='x',
603608
yref='y',
604-
text=f'cts {bin_counts}<br>{prefix}{peak_value:.1f} {suffix}<br>{resolution:.1f}%',
609+
text=f'{prefixy} {bin_counts}<br>{prefixx}{peak_value:.1f} {suffix}<br>{resolution:.1f}%',
605610
font=dict(size=10),
606-
align='center',
611+
align='left',
612+
xanchor='left',
607613
showarrow=True,
614+
arrowcolor='red',
608615
arrowhead=0,
609616
ax=0,
610617
ay=-60,
@@ -625,9 +632,9 @@ def update_graph(n, relayoutData, isotopes, filename, epb_switch, log_switch, ca
625632
fig.update_layout(
626633
annotations=annotations,
627634
title={
628-
'text': f'{filename}<br>{date}<br>{counts} valid counts<br>{dropped_counts} lost counts<br>{elapsed} seconds<br>{coincidence}',
629-
'x': 0.85,
630-
'y': 0.9,
635+
'text': f'{filename}<br>{counts} valid counts<br>{dropped_counts} lost counts<br>{elapsed} seconds<br>{coincidence}<br>{date}',
636+
'x': 0.9,
637+
'y': 0.85,
631638
'xanchor': 'center',
632639
'yanchor': 'top',
633640
'font': {'family': 'Arial', 'size': 14, 'color': 'black'},

Diff for: code/tab6.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def show_tab6():
6767
html.Div(id='tab6_text_div', children=[
6868
html.Hr(),
6969
html.Div(id='manual', children=[
70-
html.H1('Impulse V2.1.8 Manual (Serial Devices)', style={'display': serial}),
71-
html.H1('Impulse V2.1.8 Manual (Audio Devices)', style={'display': audio}),
70+
html.H1('Impulse V2.1.9 Manual (Serial Devices)', style={'display': serial}),
71+
html.H1('Impulse V2.1.9 Manual (Audio Devices)', style={'display': audio}),
7272

7373
html.P('Thank you for downloading and installing Impulse MCA, this open source software is written in Python with the intention that users may modify and adapt it to their own experiments.'),
7474
html.P('In the following text I shall describe how the software works and what each setting parameter does.'),

0 commit comments

Comments
 (0)