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
29c855cd
Commit
29c855cd
authored
Jan 10, 2017
by
Damien Naudet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FitView specific code moved to own subfolder.
parent
ebb16102
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
835 additions
and
26 deletions
+835
-26
kmap/gui/view/FitView.py
kmap/gui/view/FitView.py
+21
-26
kmap/gui/view/fitview/DropPlotWidget.py
kmap/gui/view/fitview/DropPlotWidget.py
+453
-0
kmap/gui/view/fitview/FitModel.py
kmap/gui/view/fitview/FitModel.py
+289
-0
kmap/gui/view/fitview/__init__.py
kmap/gui/view/fitview/__init__.py
+30
-0
kmap/gui/view/setup.py
kmap/gui/view/setup.py
+42
-0
No files found.
kmap/gui/view/FitView.py
View file @
29c855cd
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-201
6
European Synchrotron Radiation Facility
# Copyright (c) 2015-201
7
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
...
...
@@ -45,7 +45,7 @@ from kmap.gui.widgets.Containers import GroupBox
from
kmap.io.FitH5
import
FitH5
from
..widgets.XsocsPlot2D
import
XsocsPlot2D
from
..
.
widgets.XsocsPlot2D
import
XsocsPlot2D
from
kmap.gui.model.TreeView
import
TreeView
from
kmap.gui.model.NodeEditor
import
EditorMixin
from
kmap.gui.project.Hdf5Nodes
import
H5Base
,
H5NodeClassDef
...
...
@@ -453,8 +453,6 @@ class FitView(Qt.QMainWindow):
self
.
setCentralWidget
(
centralWid
)
# self.__initPlots()
def
showEvent
(
self
,
event
):
# TODO : this is a workaround to the fact that
# plot ranges aren't set correctly when adding data when the plot
...
...
@@ -490,14 +488,8 @@ class FitView(Qt.QMainWindow):
def
__plotFitResults
(
self
,
xIdx
):
# TODO : the values could/should be loaded when the widget is shown for the
# first time
with
self
.
__fitH5
as
fitH5
:
# sampleX = fitH5.scan_x(self.__entry)
# sampleY = fitH5.scan_y(self.__entry)
#
# xIdx = ((sampleX - x)**2 + (sampleY - y)**2).argmin()
#
# x = sampleX[xIdx]
# y = sampleY[xIdx]
entry
=
self
.
__entry
...
...
@@ -540,18 +532,6 @@ class FitView(Qt.QMainWindow):
# TODO : popup
raise
ValueError
(
'Unknown process {0}.'
.
format
(
process
))
# self.__setSelectedPosition(x, y)
# def __setSelectedPosition(self, x, y):
# """Set the selected position.
#
# :param float x:
# :param float y:
# """
# for plot in self.__plots:
# plot.addXMarker(x, legend='Xselection', color='pink')
# plot.addYMarker(y, legend='Yselection', color='pink')
# TODO : allow users to register plot functions associated with the kind
# of process results that are being displayed
...
...
@@ -560,7 +540,7 @@ def _plotLeastSq(plots, index, fitH5,
xAcqQX
,
xAcqQY
,
xAcqQZ
,
yAcqQX
,
yAcqQY
,
yAcqQZ
):
"""
Plots the "leastsq" fit results
:param plots: plot widgets
:param index: index of the selected point (in the results array)
:param fitH5: instance of FitH5. This instance may be already opened by
...
...
@@ -624,6 +604,21 @@ def _plotCentroid(plots, index, fitH5,
entry
,
process
,
xAcqQX
,
xAcqQY
,
xAcqQZ
,
yAcqQX
,
yAcqQY
,
yAcqQZ
):
"""
Plot the results from a "centroid" fit.
:param plots:
:param index:
:param fitH5:
:param entry:
:param process:
:param xAcqQX:
:param xAcqQY:
:param xAcqQZ:
:param yAcqQX:
:param yAcqQY:
:param yAcqQZ:
:return:
"""
# TODO : put all this in a toolbox, so it can be shared between
# the plot and the fit functions
...
...
@@ -645,7 +640,7 @@ def _plotCentroid(plots, index, fitH5,
def
_initLeastSq
(
plots
,
fitH5Name
,
entry
,
process
):
"""
Sets up the plots when the interface is shown for the first time.
:param plots:
:param fitH5Name:
:param entry:
...
...
@@ -664,7 +659,7 @@ def _initLeastSq(plots, fitH5Name, entry, process):
def
_initCentroid
(
plots
,
fitH5Name
,
entry
,
process
):
"""
Sets up the plots when the interface is shown for the first time.
:param plots:
:param fitH5Name:
:param entry:
...
...
kmap/gui/view/fitview/DropPlotWidget.py
0 → 100644
View file @
29c855cd
This diff is collapsed.
Click to expand it.
kmap/gui/view/fitview/FitModel.py
0 → 100644
View file @
29c855cd
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2017 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"
]
__license__
=
"MIT"
__date__
=
"01/01/2017"
import
numpy
as
np
from
silx.gui
import
qt
as
Qt
from
silx.gui.plot
import
PlotWindow
,
PlotWidget
from
matplotlib
import
cm
from
kmap.gui.model.Model
import
Model
,
RootNode
from
kmap.gui.project.Hdf5Nodes
import
H5File
from
kmap.gui.model.ModelDef
import
ModelRoles
,
ModelColumns
from
kmap.gui.project.XsocsH5Factory
import
h5NodeToProjectItem
from
kmap.gui.widgets.Containers
import
GroupBox
from
kmap.io.FitH5
import
FitH5
from
..widgets.XsocsPlot2D
import
XsocsPlot2D
from
kmap.gui.model.TreeView
import
TreeView
from
kmap.gui.model.NodeEditor
import
EditorMixin
from
kmap.gui.project.Hdf5Nodes
import
H5Base
,
H5NodeClassDef
class
FitResultEditor
(
EditorMixin
,
PlotWidget
):
persistent
=
True
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
FitResultEditor
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
_backend
.
_enableAxis
(
'left'
,
False
)
self
.
_backend
.
_enableAxis
(
'right'
,
False
)
self
.
_backend
.
ax
.
get_xaxis
().
set_visible
(
False
)
self
.
_backend
.
ax
.
set_xmargin
(
0
)
self
.
_backend
.
ax
.
set_ymargin
(
0
)
self
.
setActiveCurveHandling
(
False
)
self
.
setKeepDataAspectRatio
(
True
)
self
.
setDataMargins
(
0
,
0
,
0
,
0
)
def
setEditorData
(
self
,
index
):
node
=
index
.
data
(
ModelRoles
.
InternalDataRole
)
if
node
and
not
node
.
setEditorData
(
self
,
index
.
column
()):
value
=
index
.
data
(
Qt
.
Qt
.
EditRole
)
return
self
.
setModelValue
(
value
)
return
True
def
setModelValue
(
self
,
value
):
return
False
def
getEditorData
(
self
):
pass
def
sizeHint
(
self
):
return
Qt
.
QSize
(
100
,
100
)
def
minimumSizeHint
(
self
):
return
Qt
.
QSize
(
100
,
100
)
def
maximumSize
(
self
):
return
Qt
.
QSize
(
100
,
100
)
@
H5NodeClassDef
(
'FitH5'
)
class
FitH5Node
(
H5File
):
# TODO : check the file format (make sure that all required
# groups/datasets are there)
def
_loadChildren
(
self
):
base
=
self
.
h5Path
.
rstrip
(
'/'
)
children
=
[]
with
FitH5
(
self
.
h5File
,
mode
=
'r'
)
as
h5f
:
entries
=
h5f
.
entries
()
for
entry
in
entries
:
child
=
FitEntryNode
(
self
.
h5File
,
base
+
'/'
+
entry
)
children
.
append
(
child
)
return
children
@
H5NodeClassDef
(
'FitEntry'
)
class
FitEntryNode
(
H5Base
):
entry
=
property
(
lambda
self
:
self
.
h5Path
.
lstrip
(
'/'
).
split
(
'/'
)[
0
])
def
_loadChildren
(
self
):
base
=
self
.
h5Path
.
rstrip
(
'/'
)
entry
=
self
.
entry
children
=
[]
with
FitH5
(
self
.
h5File
,
mode
=
'r'
)
as
h5f
:
processes
=
h5f
.
processes
(
entry
)
for
process
in
processes
:
child
=
FitProcessNode
(
self
.
h5File
,
base
+
'/'
+
process
)
children
.
append
(
child
)
return
children
class
FitProcessNode
(
FitEntryNode
):
process
=
property
(
lambda
self
:
self
.
h5Path
.
split
(
'/'
)[
1
])
def
_loadChildren
(
self
):
base
=
self
.
h5Path
.
rstrip
(
'/'
)
entry
=
self
.
entry
process
=
self
.
process
children
=
[]
with
FitH5
(
self
.
h5File
,
mode
=
'r'
)
as
h5f
:
results
=
h5f
.
results
(
entry
,
process
)
for
result
in
results
:
child
=
FitResultNode
(
self
.
h5File
,
base
+
'/'
+
result
)
children
.
append
(
child
)
return
children
class
FitResultNode
(
FitProcessNode
):
result
=
property
(
lambda
self
:
self
.
h5Path
.
split
(
'/'
)[
-
1
])
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
dragEnabledColumns
=
[
False
,
True
,
True
,
True
]
super
(
FitResultNode
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_setupNode
(
self
):
self
.
setData
(
1
,
'Qx'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
1
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
self
.
setData
(
2
,
'Qy'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
2
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
self
.
setData
(
3
,
'Qz'
,
Qt
.
Qt
.
DisplayRole
)
self
.
setData
(
3
,
Qt
.
Qt
.
AlignCenter
,
Qt
.
Qt
.
TextAlignmentRole
)
def
_loadChildren
(
self
):
return
[
FitThumbnailNode
(
self
.
h5File
,
self
.
h5Path
)]
class
FitThumbnailNode
(
FitResultNode
):
editors
=
[
None
,
FitResultEditor
,
FitResultEditor
,
FitResultEditor
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
dragEnabledColumns
=
[
False
,
True
,
True
,
True
]
super
(
FitThumbnailNode
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_setupNode
(
self
):
self
.
setData
(
ModelColumns
.
NameColumn
,
None
,
Qt
.
Qt
.
DisplayRole
)
def
_loadChildren
(
self
):
return
[]
def
sizeHint
(
self
,
column
):
if
column
==
ModelColumns
.
ValueColumn
:
return
Qt
.
QSize
(
100
,
100
)
return
super
(
FitResultNode
,
self
).
sizeHint
(
column
)
def
setEditorData
(
self
,
editor
,
column
):
if
not
isinstance
(
editor
,
FitResultEditor
):
return
False
with
FitH5
(
self
.
h5File
)
as
fitH5
:
x
=
fitH5
.
scan_x
(
self
.
entry
)
y
=
fitH5
.
scan_y
(
self
.
entry
)
if
column
==
1
:
data
=
fitH5
.
get_qx_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
elif
column
==
2
:
data
=
fitH5
.
get_qy_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
else
:
data
=
fitH5
.
get_qz_result
(
self
.
entry
,
self
.
process
,
self
.
result
)
min_
,
max_
=
data
.
min
(),
data
.
max
()
colormap
=
cm
.
jet
colors
=
colormap
(
(
data
.
astype
(
np
.
float64
)
-
min_
)
/
(
max_
-
min_
))
editor
.
addCurve
(
x
,
y
,
color
=
colors
,
symbol
=
's'
,
linestyle
=
''
)
return
True
def
_setModelData
(
self
,
editor
,
column
):
"""
This is called by the View's delegate just before the editor is closed,
it allows this item to update itself with data from the editor.
:param editor:
:return:
"""
return
False
def
_openedEditorEvent
(
self
,
editor
,
column
,
args
=
None
,
kwargs
=
None
):
"""
This is called by custom editors while they're opened in the view.
See ItemDelegate.__notifyView. Defqult implementation calls
_setModelData on this node.
:param editor:
:param column:
:param args: event's args
:param kwargs: event's kwargs
:return:
"""
return
self
.
_setModelData
(
editor
,
column
)
class
FitRootNode
(
RootNode
):
ColumnNames
=
[
'Param'
,
'Qx'
,
'Qy'
,
'Qz'
]
class
FitModel
(
Model
):
RootNode
=
FitRootNode
ColumnsWithDelegates
=
[
1
,
2
,
3
]
def
mimeData
(
self
,
indexes
):
if
len
(
indexes
)
>
1
:
raise
ValueError
(
'Drag&Drop of more than one item is not'
'supported yet.'
)
index
=
indexes
[
0
]
node
=
index
.
data
(
ModelRoles
.
InternalDataRole
)
if
not
isinstance
(
node
,
FitResultNode
):
return
super
(
Model
,
self
).
mimeData
(
indexes
)
if
index
.
column
()
==
1
:
q_axis
=
FitH5
.
qx_axis
elif
index
.
column
()
==
2
:
q_axis
=
FitH5
.
qy_axis
elif
index
.
column
()
==
3
:
q_axis
=
FitH5
.
qz_axis
else
:
raise
ValueError
(
'Unexpected column.'
)
h5file
=
node
.
h5File
entry
=
node
.
entry
process
=
node
.
process
result
=
node
.
result
data
=
Qt
.
QByteArray
()
stream
=
Qt
.
QDataStream
(
data
,
Qt
.
QIODevice
.
WriteOnly
)
stream
.
writeString
(
h5file
)
stream
.
writeString
(
entry
)
stream
.
writeString
(
process
)
stream
.
writeString
(
result
)
stream
.
writeInt
(
q_axis
)
mimeData
=
Qt
.
QMimeData
()
mimeData
.
setData
(
'application/FitModel'
,
data
)
return
mimeData
if
__name__
==
'__main__'
:
pass
kmap/gui/view/fitview/__init__.py
0 → 100644
View file @
29c855cd
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2017 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"
]
__license__
=
"MIT"
__date__
=
"01/01/2017"
kmap/gui/view/setup.py
0 → 100644
View file @
29c855cd
# /*##########################################################################
# coding: utf-8
# Copyright (C) 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.
#
# ############################################################################*/
__authors__
=
[
"D. Naudet"
]
__license__
=
"MIT"
__date__
=
"01/03/2016"
from
numpy.distutils.misc_util
import
Configuration
def
configuration
(
parent_package
=
''
,
top_path
=
None
):
config
=
Configuration
(
'view'
,
parent_package
,
top_path
)
config
.
add_subpackage
(
'fitview'
)
return
config
if
__name__
==
"__main__"
:
from
numpy.distutils.core
import
setup
setup
(
configuration
=
configuration
)
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