Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xsocs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kmap
xsocs
Commits
edce4b3e
Commit
edce4b3e
authored
Jan 18, 2017
by
Damien Naudet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the fit functions to their own file.
parent
9814b763
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
587 additions
and
103 deletions
+587
-103
kmap/process/fit_funcs.py
kmap/process/fit_funcs.py
+104
-0
kmap/process/peak_fit.py
kmap/process/peak_fit.py
+483
-103
No files found.
kmap/process/fit_funcs.py
0 → 100644
View file @
edce4b3e
#!/usr/bin/python
# coding: utf8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from
__future__
import
absolute_import
__authors__
=
[
"D. Naudet"
]
__date__
=
"01/06/2016"
__license__
=
"MIT"
import
numpy
as
np
from
scipy.optimize
import
leastsq
# Some constants
_const_inv_2_pi_
=
np
.
sqrt
(
2
*
np
.
pi
)
# 1d Gaussian func
# TODO : optimize
def
gaussian
(
x
,
a
,
c
,
s
):
"""
Returns (a / (sqrt(2 * pi) * s)) * exp(- 0.5 * ((x - c) / s)^2)
:param x: values for which the gaussian must be computed
:param a: area under curve ( amplitude * s * sqrt(2 * pi) )
:param c: center
:param stdev: standard deviation
:return: (a / (sqrt(2 * pi) * s)) * exp(- 0.5 * ((x - c) / s)^2)
"""
return
(
a
*
(
1.
/
(
_const_inv_2_pi_
*
s
))
*
np
.
exp
(
-
0.5
*
((
x
-
c
)
/
s
)
**
2
))
# 1d Gaussian fit
# TODO : optimize
def
gaussian_fit_err
(
p
,
x
,
y
):
"""
:param p:
:param x:
:param y:
:return:
"""
return
gaussian
(
x
,
*
p
)
-
y
def
gaussian_fit
(
x
,
y
,
p
):
"""
Fits (leastsq) a gaussian on the provided data f(x) = y.
p = (a, c, s)
and f(x) = (a / (sqrt(2 * pi) * s)) * exp(- 0.5 * ((x - c) / s)^2)
:param x:
:param y:
:param p:
:return:
"""
result
=
leastsq
(
gaussian_fit_err
,
p
,
args
=
(
x
,
y
,),
maxfev
=
100000
,
full_output
=
True
)
if
result
[
4
]
not
in
[
1
,
2
,
3
,
4
]:
raise
ValueError
(
'Failed to fit : {0}.'
.
format
(
result
[
3
]))
return
result
[
0
]
def
centroid
(
x
,
y
,
p
):
"""
Computes the center of mass of the provided data.
Returns the value closest to the center of mass, and the
the center of mass
:param x:
:param y:
:param p:
:return: list
"""
# TODO : throw exception if fit failed
com
=
x
.
dot
(
y
)
/
y
.
sum
()
idx
=
np
.
abs
(
x
-
com
).
argmin
()
return
[
y
[
idx
],
com
,
np
.
nan
]
kmap/process/peak_fit.py
View file @
edce4b3e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment