Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
students
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
Florian
students
Commits
bd446fc8
Commit
bd446fc8
authored
11 months ago
by
Roger Wolf
Browse files
Options
Downloads
Patches
Plain Diff
a few fixes
parent
b669ed4e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Gammaspektroskopie/tools/gamma_tools.py
+4
-6
4 additions, 6 deletions
Gammaspektroskopie/tools/gamma_tools.py
Gammaspektroskopie/tools/gamma_tools_example.ipynb
+15
-11
15 additions, 11 deletions
Gammaspektroskopie/tools/gamma_tools_example.ipynb
with
19 additions
and
17 deletions
Gammaspektroskopie/tools/gamma_tools.py
+
4
−
6
View file @
bd446fc8
...
...
@@ -34,8 +34,6 @@ def gaussian (x, mu, sigma = 50, baseline = 5, s = 0.9, N = 1000, xmin = 0, xmax
def
compton_edge
(
x
,
mu
,
sigma
=
10
,
A
=
1
,
B
=
0.5
,
baseline
=
5
,
s
=
0.9
,
N
=
1000
,
xmin
=
0
,
xmax
=
100
):
return
s
*
special
.
erfc
((
x
-
mu
)
/
(
np
.
sqrt
(
2
)
*
sigma
))
/
(
2
*
(
mu
-
xmin
))
*
(
1
+
(
A
*
(
x
/
(
mu
*
B
)
-
1
)
**
2
))
+
(
1
-
s
)
*
baseline
/
(
xmax
-
xmin
)
# return s * special.erfc((x-mu)/(np.sqrt(2) * sigma)) /(2*(mu-xmin)) + (1-s)*baseline/(xmax-xmin)
# return (s * special.erfc((x-mu)/(np.sqrt(2) * sigma)) * (1 + B * (x/mu - 0.5)**2))/(xmax-xmin) + (1-s)*baseline/(xmax-xmin)
...
...
@@ -43,7 +41,7 @@ def compton_edge (x, mu, sigma = 10, A = 1, B = 0.5, baseline = 5, s = 0.9, N =
# Fit a photopeak using a Gaussian model function #
# ##################################################
def
fit_peak
(
datax
,
datay
,
x1
=
None
,
x2
=
None
,
showResult
=
True
,
label
=
Non
e
,
**
initparams
):
def
fit_peak
(
datax
,
datay
,
x1
=
None
,
x2
=
None
,
label
=
None
,
xlabel
=
'
Channel
'
,
y
label
=
'
Count
'
,
showResult
=
Tru
e
,
**
initparams
):
# Check if a lower x-limit for the fit is given, otherwise use the minimum of the provided dataset
if
x1
==
None
:
x1
=
min
(
datax
)
...
...
@@ -54,7 +52,7 @@ def fit_peak (datax, datay, x1 = None, x2 = None, showResult = True, label = Non
datax_clipped
=
np
.
delete
(
datax
,
np
.
where
((
x1
>
datax
)
|
(
datax
>
x2
)))
datay_clipped
=
np
.
delete
(
datay
,
np
.
where
((
x1
>
datax
)
|
(
datax
>
x2
)))
# Set axis labels
axislabels
=
[
'
Chann
el
'
,
'
Count
'
]
axislabels
=
[
xlab
el
,
ylabel
]
# Perform a Gaussian fit on the remaining data, choosing the position of the maximum value in the data as an initial value for the position of the peak
fit
=
hist_fit_data
(
datax_clipped
,
datay_clipped
,
model
=
gaussian
,
limitedparams
=
[[
'
mu
'
,
{
'
lower
'
:
0
}],
[
'
sigma
'
,
{
'
lower
'
:
0
}],
[
'
s
'
,
{
'
lower
'
:
0
,
'
upper
'
:
1
}]],
fixedparams
=
[[
"
N
"
,
np
.
sum
(
datay_clipped
)],
[
"
xmin
"
,
x1
],
[
"
xmax
"
,
x2
]],
mu
=
datax_clipped
[
np
.
argmax
(
datay_clipped
)],
label
=
label
,
showResult
=
showResult
,
axislabels
=
axislabels
,
**
initparams
)
# Return fit object
...
...
@@ -66,7 +64,7 @@ def fit_peak (datax, datay, x1 = None, x2 = None, showResult = True, label = Non
# Fit a compton edge using a complementary error function #
# ##########################################################
def
fit_compton
(
datax
,
datay
,
x1
=
None
,
x2
=
None
,
showResult
=
True
,
label
=
Non
e
,
**
initparams
):
def
fit_compton
(
datax
,
datay
,
x1
=
None
,
x2
=
None
,
label
=
None
,
xlabel
=
'
Channel
'
,
y
label
=
'
Count
'
,
showResult
=
Tru
e
,
**
initparams
):
# Check if a lower x-limit for the fit is given, otherwise use the minimum of the provided dataset
if
x1
==
None
:
x1
=
min
(
datax
)
...
...
@@ -83,7 +81,7 @@ def fit_compton (datax, datay, x1 = None, x2 = None, showResult = True, label =
diffs
.
append
(
np
.
abs
(
np
.
sum
(
dif
[
i
:
i
+
25
])))
mu0
=
datax_clipped
[
np
.
argmax
(
diffs
)]
# Set axis labels
axislabels
=
[
'
Chann
el
'
,
'
Count
'
]
axislabels
=
[
xlab
el
,
ylabel
]
# Perform the fit on the remaining data using the estimated position as an initial value
fit
=
hist_fit_data
(
datax_clipped
,
datay_clipped
,
model
=
compton_edge
,
limitedparams
=
[[
'
mu
'
,
{
'
lower
'
:
0
}],
[
'
sigma
'
,
{
'
lower
'
:
0
}],
[
'
A
'
,
{
'
lower
'
:
0
}],
[
'
B
'
,
{
'
lower
'
:
0.3
,
'
upper
'
:
0.9
}],
[
'
s
'
,
{
'
lower
'
:
0
,
'
upper
'
:
1
}]],
fixedparams
=
[[
"
N
"
,
np
.
sum
(
datay_clipped
)],
[
"
xmin
"
,
x1
],
[
"
xmax
"
,
x2
]],
mu
=
mu0
,
B
=
mu0
,
label
=
label
,
axislabels
=
axislabels
,
showResult
=
showResult
,
**
initparams
)
# Return fit object
...
...
This diff is collapsed.
Click to expand it.
Gammaspektroskopie/tools/gamma_tools_example.ipynb
+
15
−
11
View file @
bd446fc8
Source diff could not be displayed: it is too large. Options to address this:
view the blob
.
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