Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
kmap
xsocs
Commits
5dfeeea0
Commit
5dfeeea0
authored
Nov 22, 2018
by
Thomas Vincent
Browse files
display fitted gaussian + background
parent
e037f994
Changes
2
Hide whitespace changes
Inline
Side-by-side
xsocs/gui/view/FitView.py
View file @
5dfeeea0
...
...
@@ -299,20 +299,23 @@ class FitView(Qt.QMainWindow):
plot
.
setGraphTitle
(
'{0} ({1})'
.
format
(
title
,
name
))
plot
.
addCurve
(
xAcq
,
yAcq
,
legend
=
'measured'
,
color
=
'blue'
)
background
=
None
if
backgroundMode
!=
BackgroundTypes
.
NONE
:
# Display background
indices
=
np
.
nonzero
(
np
.
in1d
(
xAcq
,
xFit
,
assume_unique
=
True
))[
0
]
if
len
(
indices
)
!=
len
(
xFit
):
_logger
.
error
(
"Cannot retrieve ROI: cannot display background"
)
else
:
background
=
background_estimation
(
backgroundMode
,
yAcq
[
indices
])
plot
.
addCurve
(
xFit
,
background
_estimation
(
backgroundMode
,
yAcq
[
indices
])
,
background
,
legend
=
'background'
,
linestyle
=
':'
,
color
=
'black'
)
plotter
.
plotFit
(
plot
,
xFit
,
peakParams
)
plotter
.
plotFit
(
plot
,
xFit
,
peakParams
,
background
)
def
_initGaussian
(
plots
,
fitH5Name
,
entry
,
process
):
...
...
xsocs/gui/view/fitview/Plotter.py
View file @
5dfeeea0
...
...
@@ -39,12 +39,14 @@ from ....util import gaussian
class
Plotter
(
object
):
"""Base class for fit result plotting"""
def
plotFit
(
self
,
plot
,
x
,
params
):
def
plotFit
(
self
,
plot
,
x
,
params
,
background
):
"""Update a plot to display fit/COM results
:param plot: PlotWidget to update
:param numpy.ndarray x: X values
:param List[float] params: Parameters of the fit/COM
:param Union[None,numpy.ndarray] background:
The background estimation or None if no background
"""
raise
NotImplementedError
(
'Not implemented'
)
...
...
@@ -59,16 +61,18 @@ class Plotter(object):
class
GaussianPlotter
(
Plotter
):
"""Plot gaussian fit results"""
def
plotFit
(
self
,
plot
,
x
,
p
eakP
arams
):
for
peakName
,
peak
in
p
eakP
arams
.
items
():
def
plotFit
(
self
,
plot
,
x
,
params
,
background
):
for
peakName
,
peak
in
params
.
items
():
height
=
peak
.
get
(
'Area'
)
position
=
peak
.
get
(
'Center'
)
width
=
peak
.
get
(
'Sigma'
)
params
=
[
height
,
position
,
width
]
gaussian_
params
=
[
height
,
position
,
width
]
if
numpy
.
all
(
numpy
.
isfinite
(
params
)):
fitted
=
gaussian
(
x
,
*
params
)
if
numpy
.
all
(
numpy
.
isfinite
(
gaussian_params
)):
fitted
=
gaussian
(
x
,
*
gaussian_params
)
if
background
is
not
None
:
fitted
+=
background
plot
.
addCurve
(
x
,
fitted
,
legend
=
'{0}'
.
format
(
peakName
),
...
...
@@ -81,16 +85,17 @@ class GaussianPlotter(Plotter):
class
CentroidPlotter
(
Plotter
):
"""Plot center-of-mass/Max results"""
def
plotFit
(
self
,
plot
,
x
,
p
eakP
arams
):
for
peakName
,
peak
in
p
eakP
arams
.
items
():
def
plotFit
(
self
,
plot
,
x
,
params
,
background
):
for
peakName
,
peak
in
params
.
items
():
center
=
peak
.
get
(
'COM'
)
xmax
=
peak
.
get
(
'Pos_max'
)
if
numpy
.
isfinite
(
center
):
plot
.
addXMarker
(
center
,
legend
=
'center of mass'
,
text
=
"com"
)
plot
.
addXMarker
(
xmax
,
legend
=
'maximum position'
,
text
=
"max"
,
color
=
"gray"
)
plot
.
addXMarker
(
xmax
,
legend
=
'maximum position'
,
text
=
"max"
,
color
=
"gray"
)
def
getPlotTitle
(
self
):
return
'Center Of Mass'
Write
Preview
Supports
Markdown
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