Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redpitaya-MCPHA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Günter Quast
redpitaya-MCPHA
Commits
e2cb77d1
Commit
e2cb77d1
authored
1 year ago
by
Guenter Quast
Browse files
Options
Downloads
Patches
Plain Diff
added legend to plots
parent
9fea1fa7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/findPeaks.py
+25
-6
25 additions, 6 deletions
examples/findPeaks.py
with
25 additions
and
6 deletions
examples/findPeaks.py
+
25
−
6
View file @
e2cb77d1
#!/usr/bin/env python3
"""
findPeaks: find and fit peaks in gamma spectrum
algorithm: perform a tow-stage determination of peak posisions:
1. scipi.signal.find_peaks() is run on a smoothed histogram
of channel counts.
1. the output is used as a starting point for histogram fits
with kafe2 based on the binned neg-log-likelhood cost function.
"""
import
argparse
...
...
@@ -163,17 +170,28 @@ ax1.set_xlabel('Channel #')
ax1
.
grid
(
linestyle
=
'
dotted
'
,
which
=
'
both
'
)
if
plot
:
# show spectrum and result of find_peaks
xhst
=
np
.
linspace
(
0
,
len
(
hst
),
len
(
hst
),
endpoint
=
False
)
+
0.5
ax0
.
errorbar
(
xhst
,
hst
,
yerr
=
np
.
sqrt
(
hst
),
fmt
=
'
.
'
,
color
=
'
grey
'
,
markersize
=
2
,
linewidth
=
2
)
ax1
.
errorbar
(
xhst
,
hst
,
yerr
=
np
.
sqrt
(
hst
),
fmt
=
'
.
'
,
color
=
'
grey
'
,
alpha
=
0.1
)
colors
=
(
'
cadetblue
'
,
'
orange
'
,
'
olive
'
,
'
orchid
'
,
'
turquoise
'
,
'
tomato
'
,
'
green
'
,
'
pink
'
,
'
salmon
'
,
'
yellowgreen
'
)
ax0
.
plot
(
xhst
,
hst_s
,
'
b-
'
,
linewidth
=
3
,
label
=
'
smoothed channel counts
'
)
ax0
.
errorbar
(
xhst
,
hst
,
yerr
=
np
.
sqrt
(
hst
),
label
=
'
channel counts
'
,
fmt
=
'
.
'
,
color
=
'
grey
'
,
markersize
=
2
,
linewidth
=
2
,
alpha
=
0.5
)
ax0
.
plot
(
peaks
,
hst_s
[
peaks
],
'
*
'
,
color
=
'
red
'
,
markersize
=
10
,
label
=
'
result of find_peaks()
'
)
ax0
.
legend
(
loc
=
'
best
'
)
# show fitted peaks
ax1
.
errorbar
(
xhst
,
hst
,
yerr
=
np
.
sqrt
(
hst
),
fmt
=
'
.
'
,
color
=
'
grey
'
,
alpha
=
0.1
,
label
=
'
channel counts
'
)
# select colors for peaks
pcolors
=
(
'
cadetblue
'
,
'
orange
'
,
'
olive
'
,
'
orchid
'
,
'
turquoise
'
,
'
tomato
'
,
'
green
'
,
'
pink
'
,
'
salmon
'
,
'
yellowgreen
'
)
for
i
,
fit
in
enumerate
(
fit_results
):
# plot fitted peak in fit range
colr
=
colors
[
i
%
10
]
colr
=
p
colors
[
i
%
10
]
xplt
=
np
.
linspace
(
plot_ranges
[
i
][
0
],
plot_ranges
[
i
][
1
],
10
*
int
((
plot_ranges
[
i
][
1
]
-
plot_ranges
[
i
][
0
])))
ax1
.
plot
(
xplt
,
gauss_plus_bkg
(
xplt
,
*
fit
.
parameter_values
),
linestyle
=
'
solid
'
,
linewidth
=
3
,
color
=
colr
)
linestyle
=
'
solid
'
,
linewidth
=
3
,
color
=
colr
,
label
=
'
peak
'
+
str
(
i
+
1
)
+
'
@
'
+
str
(
int
(
10
*
fit
.
parameter_values
[
1
])
/
10.
)
)
# plot fitted peak near fit region
xplt2
=
np
.
linspace
(
plot_ranges2
[
i
][
0
],
plot_ranges2
[
i
][
1
],
10
*
int
((
plot_ranges
[
i
][
1
]
-
plot_ranges
[
i
][
0
])))
...
...
@@ -190,7 +208,8 @@ if plot:
ax1
.
vlines
(
mu
,
0
,
mx
-
h
,
linewidth
=
1
,
linestyle
=
'
dashed
'
,
color
=
'
goldenrod
'
)
ax1
.
hlines
(
mx
-
h
/
2
,
mu
-
fwhm
/
2
,
mu
+
fwhm
/
2
,
linewidth
=
2
,
color
=
'
gold
'
)
linewidth
=
2
,
color
=
'
gold
'
)
ax1
.
legend
(
loc
=
'
best
'
)
if
kafe2_plots
:
# kafe2 plots
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment