Coverage for larch/qtrixs/items.py: 0%
91 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-16 21:04 +0000
1#!/usr/bin/env python
2# coding: utf-8
3"""
4RIXS items
5"""
6from silx.gui import qt
7from larch.qtlib.items import TreeItem
10class RixsItem(TreeItem):
11 """Qt item for adding RixsData to the application and handling plots interaction"""
13 def __init__(self, name=None, parentItem=None, isChecked=False, data=None):
15 super(RixsItem, self).__init__(name, parentItem, isChecked)
16 self._plotWindows = None
17 self._currentPlotWindow = None
18 self._data = data
20 def data(self, column, name, role):
21 if role == qt.Qt.CheckStateRole:
22 if column == 0:
23 if self.isChecked:
24 return qt.Qt.Checked
25 else:
26 return qt.Qt.Unchecked
27 return super(RixsItem, self).data(column, name, role)
29 def setData(self, column, name, value, role):
30 if role == qt.Qt.CheckStateRole:
31 if value == qt.Qt.Checked:
32 self.isChecked = True
33 else:
34 self.isChecked = False
35 return True
36 return super(RixsItem, self).setData(column, name, value, role)
38 def flags(self, column):
39 flags = super(RixsItem, self).flags(column)
40 if column == 0:
41 return flags | qt.Qt.ItemIsUserCheckable
42 else:
43 return flags
45 @property
46 def currentPlotWindowIndex(self):
47 if self.currentPlotWindow is not None:
48 return str(self.currentPlotWindow.index())
49 else:
50 return None
52 @currentPlotWindowIndex.setter
53 def currentPlotWindowIndex(self, value):
54 try:
55 self._currentPlotWindowIndex = int(value)
56 except ValueError:
57 self.currentPlotWindow = None
58 else:
59 self.currentPlotWindow = self.plotWindows[self._currentPlotWindowIndex] # noqa
61 @property
62 def currentPlotWindow(self):
63 if self._currentPlotWindow is None:
64 if self.plotWindows:
65 self._currentPlotWindow = self.plotWindows[0]
66 else:
67 if self._currentPlotWindow not in self.plotWindows:
68 if self.plotWindows:
69 self._currentPlotWindow = self.plotWindows[0]
70 else:
71 self._currentPlotWindow = None
72 return self._currentPlotWindow
74 @currentPlotWindow.setter
75 def currentPlotWindow(self, value):
76 self._currentPlotWindow = value
78 @property
79 def plotWindowsIndexes(self):
80 indexes = list()
81 if self.plotWindows is not None:
82 for index, _ in enumerate(self.plotWindows):
83 indexes.append(str(index))
84 return indexes
86 @property
87 def plotWindows(self):
88 return self._plotWindows
90 @plotWindows.setter
91 def plotWindows(self, value):
92 self._plotWindows = value
94 def _plot_rixs(self, plotWindow):
95 """Plot rixs full plane"""
96 plotWindow.addImage(self._data.rixs_map,
97 x=self._data.ene_in,
98 y=self._data.ene_out,
99 title=self._data.sample_name,
100 xlabel=self._data.ene_in_label,
101 ylabel=self._data.ene_out_label)
103 def _plot_rixs_et(self, plotWindow):
104 """Plot rixs_et full plane"""
105 plotWindow.addImage(self._data.rixs_et_map,
106 x=self._data.ene_in,
107 y=self._data.ene_et,
108 title=self._data.sample_name,
109 xlabel=self._data.ene_in_label,
110 ylabel=self._data.ene_et_label)
112 def _plot_rixs_crop(self, plotWindow):
113 """Plot rixs_et crop_area plane"""
114 _title = f"{self._data.sample_name} [CROP: {self._data._crop_area}]"
115 plotWindow.addImage(self._data.rixs_map_crop,
116 x=self._data.ene_in_crop,
117 y=self._data.ene_out_crop,
118 title=_title,
119 xlabel=self._data.ene_in_label,
120 ylabel=self._data.ene_out_label)
122 def _plot_rixs_et_crop(self, plotWindow):
123 """Plot rixs_et crop_area plane"""
124 _title = f"{self._data.sample_name} [CROP: {self._data._crop_area}]"
125 plotWindow.addImage(self._data.rixs_et_map_crop,
126 x=self._data.ene_in_crop,
127 y=self._data.ene_et_crop,
128 title=_title,
129 xlabel=self._data.ene_in_label,
130 ylabel=self._data.ene_et_label)
132 def plot(self, crop=False, rixs_et=False, nlevels=50):
133 """Data plotter"""
134 plotter = self.currentPlotWindow()
135 if plotter is None:
136 return
137 plotter.reset()
138 if type(crop) is tuple:
139 self._data.crop(crop)
140 if crop:
141 if rixs_et:
142 self._plot_rixs_et_crop(plotter)
143 else:
144 self._plot_rixs_crop(plotter)
145 else:
146 if rixs_et:
147 self._plot_rixs_et(plotter)
148 else:
149 self._plot_rixs_et(plotter)
150 plotter.addContours(nlevels)
151 plotter.show()