Commit f7772634 authored by Damien Naudet's avatar Damien Naudet

Added XsocsPlot2D

parent 8862464d
......@@ -45,6 +45,7 @@ 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
......@@ -283,7 +284,7 @@ class FitModel(Model):
return mimeData
class DropPlotWidget(PlotWindow):
class DropPlotWidget(XsocsPlot2D):
sigSelected = Qt.Signal(object)
def __init__(self, *args, **kwargs):
......@@ -342,16 +343,17 @@ class DropPlotWidget(PlotWindow):
data = getMeth(entry, process, result)
scan_x = h5f.scan_x(entry)
scan_y = h5f.scan_y(entry)
data = np.log(data)
min_, max_ = data.min(), data.max()
colormap = cm.jet
colors = colormap(
(data.astype(np.float64) - min_) / (max_ - min_))
self.__legend = self.addCurve(scan_x,
scan_y,
color=colors,
symbol='s',
linestyle='')
# data = np.log(data)
# min_, max_ = data.min(), data.max()
# colormap = cm.jet
# colors = colormap(
# (data.astype(np.float64) - min_) / (max_ - min_))
self.__legend = self.setPlotData(scan_x, scan_y, data)
# self.addCurve(scan_x,
# scan_y,
# color=colors,
# symbol='s',
# linestyle='')
self.setGraphTitle(result + '/' + q_axis)
......
......@@ -39,6 +39,7 @@ from matplotlib import cm
from ..model.TreeView import TreeView
from ..model.ModelDef import ModelColumns, ModelRoles
from ..project.XsocsH5Factory import h5NodeToProjectItem
from ..widgets.XsocsPlot2D import XsocsPlot2D
try:
from silx.gui.plot.ImageRois import ImageRoiManager
......@@ -183,13 +184,15 @@ class IntensityView(Qt.QMainWindow):
**kwargs):
super(IntensityView, self).__init__(parent=parent)
self.__plotWindow = plotWindow = PlotWindow(aspectRatio=True,
curveStyle=False,
mask=False,
roi=False,
**kwargs)
plotWindow.setKeepDataAspectRatio(True)
plotWindow.setActiveCurveHandling(False)
# self.__plotWindow = plotWindow = PlotWindow(aspectRatio=True,
# curveStyle=False,
# mask=False,
# roi=False,
# **kwargs)
# plotWindow.setKeepDataAspectRatio(True)
# plotWindow.setActiveCurveHandling(False)
self.__plotWindow = plotWindow = XsocsPlot2D()
dock = Qt.QDockWidget(self)
tree = IntensityTree(self, model=model)
......@@ -221,32 +224,33 @@ class IntensityView(Qt.QMainWindow):
def setPlotData(self, x, y, data):
plot = self.__plotWindow
if data.ndim == 1:
# scatter
min_, max_ = data.min(), data.max()
colormap = cm.jet
colors = colormap((data.astype(np.float64) - min_) / (max_ - min_))
plot.addCurve(x, y,
color=colors,
symbol='s',
linestyle='')
elif data.ndim == 2:
# image
min_, max_ = data.min(), data.max()
colormap = {'name': 'temperature',
'normalization': 'linear',
'autoscale': True,
'vmin': min_,
'vmax': max_}
origin = x[0], y[0]
scale = (x[-1] - x[0]) / len(x), (y[-1] - y[0]) / len(y)
plot.addImage(data,
origin=origin,
scale=scale,
colormap=colormap)
else:
raise ValueError('data has {0} dimensions, expected 1 or 2.'
''.format(data.ndim))
plot.setPlotData(x, y, data)
# if data.ndim == 1:
# # scatter
# min_, max_ = data.min(), data.max()
# colormap = cm.jet
# colors = colormap((data.astype(np.float64) - min_) / (max_ - min_))
# plot.addCurve(x, y,
# color=colors,
# symbol='s',
# linestyle='')
# elif data.ndim == 2:
# # image
# min_, max_ = data.min(), data.max()
# colormap = {'name': 'temperature',
# 'normalization': 'linear',
# 'autoscale': True,
# 'vmin': min_,
# 'vmax': max_}
# origin = x[0], y[0]
# scale = (x[-1] - x[0]) / len(x), (y[-1] - y[0]) / len(y)
# plot.addImage(data,
# origin=origin,
# scale=scale,
# colormap=colormap)
# else:
# raise ValueError('data has {0} dimensions, expected 1 or 2.'
# ''.format(data.ndim))
def __roiApplied(self, roi):
self.sigProcessApplied.emit(roi)
......
......@@ -45,7 +45,6 @@ from ..widgets.RangeSlider import RangeSlider
from ..widgets.Input import StyledLineEdit
from ..widgets.XsocsPlot2D import XsocsPlot2D
from ..project.XsocsH5Factory import h5NodeToProjectItem
from ...gui.icons import getQIcon as getKmapIcon
class QSpaceTree(TreeView):
......
# coding: utf-8
# /*##########################################################################
#
# 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"]
__license__ = "MIT"
__date__ = "15/09/2016"
import numpy as np
from matplotlib import cm
from silx.gui import qt as Qt
from silx.gui.plot import PlotWindow
from ...gui.icons import getQIcon as getKmapIcon
class XsocsPlot2D(PlotWindow):
def __init__(self, *args, **kwargs):
super(XsocsPlot2D, self).__init__(*args, **kwargs)
self.setActiveCurveHandling(False)
self.setKeepDataAspectRatio(True)
self.__logScatter = False
self.__colormap = cm.jet
self.__values = {}
toolbars = self.findChildren(Qt.QToolBar)
for toolbar in toolbars:
toolbar.hide()
centralWid = self.centralWidget()
self.__optionsBase = optionsBase = Qt.QWidget(centralWid)
optionsLayout = Qt.QHBoxLayout(optionsBase)
optionsLayout.setContentsMargins(0, 0, 0, 0)
icon = getKmapIcon('gears')
options = Qt.QToolButton()
options.setToolTip('Options')
options.setIcon(icon)
options.setPopupMode(Qt.QToolButton.InstantPopup)
menu = Qt.QMenu()
# apply log values
self.__logAction = logAction = menu.addAction('Log')
logAction.setIconVisibleInMenu(True)
logAction.setDisabled(True)
logAction.setCheckable(True)
logAction.triggered.connect(self.__logActionTriggered)
# save to file action
self.saveAction.setIconVisibleInMenu(True)
menu.addAction(self.saveAction)
# print action
self.printAction.setIconVisibleInMenu(True)
menu.addAction(self.printAction)
# screenshot action
self.copyAction.setIconVisibleInMenu(True)
menu.addAction(self.copyAction)
options.setMenu(menu)
rstZoomAction = self.resetZoomAction
rstToolBn = Qt.QToolButton()
rstToolBn.setDefaultAction(rstZoomAction)
optionsLayout.addWidget(options)
optionsLayout.addWidget(rstToolBn)
def resizeEvent(self, event):
super(XsocsPlot2D, self).resizeEvent(event)
optionsBase = self.__optionsBase
geom = self.centralWidget().geometry()
newPos = Qt.QPoint(0, geom.height() - optionsBase.height())
optionsBase.move(newPos)
def __logActionTriggered(self, checked):
for curve, values in self.__values.items():
info = self.getCurve(curve)
if info is None:
continue
if checked:
values = np.log(values - values.min() + 1)
min_, max_ = values.min(), values.max()
colormap = cm.jet
colors = colormap(
(values.astype(np.float64) - min_) / (max_ - min_))
# [x, y, legend, info, parameters]
self.addCurve(info[0], info[1], color=colors, legend=curve,
resetzoom=False)
def removeCurve(self, *args, **kwargs):
super(XsocsPlot2D, self).removeCurve(*args, **kwargs)
curves = set(self.getAllCurves())
thisCurves = set(self.__values.keys())
diff = thisCurves - curves
for curve in diff:
del self.__values[curve]
if len(self.__values) > 0:
self.__logAction.setDisabled(True)
def setPlotData(self, x, y,
values=None,
symbol='s',
linestyle='',
resetzoom=True,
**kwargs):
colors = None
if values is not None:
min_, max_ = values.min(), values.max()
colormap = cm.jet
colors = colormap(
(values.astype(np.float64) - min_) / (max_ - min_))
if 'color' in kwargs:
del kwargs['color']
print('In XsocsPlot2D.setPlotData : keyword color is ignored.')
legend = self.addCurve(x,
y,
color=colors,
symbol=symbol,
linestyle=linestyle,
resetzoom=resetzoom,
**kwargs)
if values is not None:
self.__values[legend] = values
if len(self.__values) > 0:
self.__logAction.setDisabled(False)
return legend
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment