Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToolBox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
SCS
ToolBox
Commits
b16d3c06
Commit
b16d3c06
authored
5 years ago
by
Laurent Mercadier
Browse files
Options
Downloads
Patches
Plain Diff
Handles case where fit does not work
parent
77c198d1
No related branches found
No related tags found
1 merge request
!75
Handles case where fit does not work
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
knife_edge.py
+27
-13
27 additions, 13 deletions
knife_edge.py
with
27 additions
and
13 deletions
knife_edge.py
+
27
−
13
View file @
b16d3c06
...
@@ -76,20 +76,28 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
...
@@ -76,20 +76,28 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
funcStr
=
'
a*erfc(-np.sqrt(2)*(x-x0)/w0) + b
'
funcStr
=
'
a*erfc(-np.sqrt(2)*(x-x0)/w0) + b
'
if
p0
is
None
:
if
p0
is
None
:
p0
=
[
np
.
mean
(
pos_sel
),
0.1
,
np
.
max
(
int_sel
)
/
2
,
0
]
p0
=
[
np
.
mean
(
pos_sel
),
0.1
,
np
.
max
(
int_sel
)
/
2
,
0
]
popt
,
pcov
=
curve_fit
(
func
,
pos_sel
,
int_sel
,
p0
=
p0
)
try
:
print
(
'
fitting function:
'
,
funcStr
)
popt
,
pcov
=
curve_fit
(
func
,
pos_sel
,
int_sel
,
p0
=
p0
)
print
(
'
w0 = (%.1f +/- %.1f) um
'
%
(
popt
[
1
]
*
1e3
,
pcov
[
1
,
1
]
**
0.5
*
1e3
))
print
(
'
fitting function:
'
,
funcStr
)
print
(
'
x0 = (%.3f +/- %.3f) mm
'
%
(
popt
[
0
],
pcov
[
0
,
0
]
**
0.5
))
print
(
'
w0 = (%.1f +/- %.1f) um
'
%
(
popt
[
1
]
*
1e3
,
pcov
[
1
,
1
]
**
0.5
*
1e3
))
print
(
'
a = %e +/- %e
'
%
(
popt
[
2
],
pcov
[
2
,
2
]
**
0.5
))
print
(
'
x0 = (%.3f +/- %.3f) mm
'
%
(
popt
[
0
],
pcov
[
0
,
0
]
**
0.5
))
print
(
'
b = %e +/- %e
'
%
(
popt
[
3
],
pcov
[
3
,
3
]
**
0.5
))
print
(
'
a = %e +/- %e
'
%
(
popt
[
2
],
pcov
[
2
,
2
]
**
0.5
))
print
(
'
b = %e +/- %e
'
%
(
popt
[
3
],
pcov
[
3
,
3
]
**
0.5
))
fitSuccess
=
True
except
:
print
(
'
Could not fit the data with ercf function.
'
+
'
Try adjusting the axisRange and the initial parameters p0
'
)
fitSuccess
=
False
if
plot
:
if
plot
:
xfit
=
np
.
linspace
(
positions
.
min
(),
positions
.
max
(),
1000
)
yfit
=
func
(
xfit
,
*
popt
)
plt
.
figure
(
figsize
=
(
7
,
4
))
plt
.
figure
(
figsize
=
(
7
,
4
))
plt
.
scatter
(
positions
,
intensities
,
color
=
'
C1
'
,
label
=
'
exp
'
,
s
=
2
,
alpha
=
0.1
)
plt
.
scatter
(
positions
,
intensities
,
color
=
'
C1
'
,
label
=
'
exp
'
,
s
=
2
,
alpha
=
0.1
)
plt
.
plot
(
xfit
,
yfit
,
color
=
'
C4
'
,
if
fitSuccess
:
label
=
r
'
fit $\rightarrow$ $w_0=$(%.1f $\pm$ %.1f) $\mu$m
'
%
(
popt
[
1
]
*
1e3
,
pcov
[
1
,
1
]
**
0.5
*
1e3
))
xfit
=
np
.
linspace
(
positions
.
min
(),
positions
.
max
(),
1000
)
yfit
=
func
(
xfit
,
*
popt
)
plt
.
plot
(
xfit
,
yfit
,
color
=
'
C4
'
,
label
=
r
'
fit $\rightarrow$ $w_0=$(%.1f $\pm$ %.1f) $\mu$m
'
%
(
popt
[
1
]
*
1e3
,
pcov
[
1
,
1
]
**
0.5
*
1e3
))
leg
=
plt
.
legend
()
leg
=
plt
.
legend
()
for
lh
in
leg
.
legendHandles
:
for
lh
in
leg
.
legendHandles
:
lh
.
set_alpha
(
1
)
lh
.
set_alpha
(
1
)
...
@@ -98,6 +106,12 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
...
@@ -98,6 +106,12 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
plt
.
title
(
nrun
.
attrs
[
'
runFolder
'
])
plt
.
title
(
nrun
.
attrs
[
'
runFolder
'
])
plt
.
tight_layout
()
plt
.
tight_layout
()
if
full
:
if
full
:
return
popt
,
pcov
,
func
if
fitSuccess
:
return
popt
,
pcov
,
func
else
:
return
np
.
zeros
(
4
),
np
.
zeros
(
2
),
None
else
:
else
:
return
np
.
array
([
popt
[
1
],
pcov
[
1
,
1
]
**
0.5
])
if
fitSuccess
:
return
np
.
array
([
popt
[
1
],
pcov
[
1
,
1
]
**
0.5
])
else
:
return
np
.
zeros
(
2
)
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