orGUI 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orGUI-1.0.1.dist-info/LICENSE +21 -0
- orGUI-1.0.1.dist-info/METADATA +147 -0
- orGUI-1.0.1.dist-info/RECORD +83 -0
- orGUI-1.0.1.dist-info/WHEEL +5 -0
- orGUI-1.0.1.dist-info/entry_points.txt +2 -0
- orGUI-1.0.1.dist-info/top_level.txt +1 -0
- orgui/__init__.py +36 -0
- orgui/app/ArrayTableDialog.py +433 -0
- orgui/app/QReflectionSelector.py +538 -0
- orgui/app/QScanSelector.py +692 -0
- orgui/app/QUBCalculator.py +1210 -0
- orgui/app/__init__.py +36 -0
- orgui/app/database.py +487 -0
- orgui/app/orGUI.py +2613 -0
- orgui/app/qutils.py +51 -0
- orgui/backend/__init__.py +32 -0
- orgui/backend/backends.py +157 -0
- orgui/backend/beamline/ID31DiffractLinTilt.py +77 -0
- orgui/backend/beamline/P212_tools.py +577 -0
- orgui/backend/beamline/__init__.py +36 -0
- orgui/backend/beamline/fio_reader.py +110 -0
- orgui/backend/beamline/id31_tools.py +651 -0
- orgui/backend/scans.py +95 -0
- orgui/backend/udefaults.py +163 -0
- orgui/backend/universalScanLoader.py +105 -0
- orgui/datautils/__init__.py +32 -0
- orgui/datautils/util.py +705 -0
- orgui/datautils/xrayutils/CTRcalc.py +3022 -0
- orgui/datautils/xrayutils/CTRopt.py +623 -0
- orgui/datautils/xrayutils/CTRplotutil.py +904 -0
- orgui/datautils/xrayutils/DetectorCalibration.py +685 -0
- orgui/datautils/xrayutils/HKLVlieg.py +1360 -0
- orgui/datautils/xrayutils/ReciprocalNavigation.py +401 -0
- orgui/datautils/xrayutils/_CTRcalc_accel.py +181 -0
- orgui/datautils/xrayutils/__init__.py +46 -0
- orgui/datautils/xrayutils/element_data.py +213 -0
- orgui/datautils/xrayutils/test/__init__.py +57 -0
- orgui/datautils/xrayutils/test/test_CTRcalc.py +152 -0
- orgui/datautils/xrayutils/test/test_DetectorCalibration.py +336 -0
- orgui/datautils/xrayutils/test/test_HKLcalc.py +88 -0
- orgui/datautils/xrayutils/unitcells/Fe3O4(100).bul +59 -0
- orgui/datautils/xrayutils/unitcells/Pt100.bul +7 -0
- orgui/datautils/xrayutils/unitcells/Pt100_small.bul +5 -0
- orgui/datautils/xrayutils/unitcells/Pt110.bul +5 -0
- orgui/datautils/xrayutils/unitcells/Pt111.bul +6 -0
- orgui/datautils/xrayutils/unitcells/Pt310.bul +13 -0
- orgui/datautils/xrayutils/unitcells/Pt3O4(100).bul +19 -0
- orgui/datautils/xrayutils/unitcells/PtO(001).bul +9 -0
- orgui/datautils/xrayutils/unitcells/PtO(010).bul +9 -0
- orgui/datautils/xrayutils/unitcells/PtO(100).bul +9 -0
- orgui/datautils/xrayutils/unitcells/__init__.py +67 -0
- orgui/datautils/xrayutils/unitcells/a-PtO2(0001).bul +6 -0
- orgui/main.py +101 -0
- orgui/resources/__init__.py +40 -0
- orgui/resources/icons/alpha.png +0 -0
- orgui/resources/icons/alpha.svg +67 -0
- orgui/resources/icons/diffractometer_v3.png +0 -0
- orgui/resources/icons/disable-image.png +0 -0
- orgui/resources/icons/disable-image.svg +68 -0
- orgui/resources/icons/document-nx-open.png +0 -0
- orgui/resources/icons/document-nx-open.svg +152 -0
- orgui/resources/icons/document-nx-save.png +0 -0
- orgui/resources/icons/document-nx-save.svg +73 -0
- orgui/resources/icons/logo.png +0 -0
- orgui/resources/icons/logo.svg +808 -0
- orgui/resources/icons/max_image.png +0 -0
- orgui/resources/icons/max_image.svg +77 -0
- orgui/resources/icons/max_image2.png +0 -0
- orgui/resources/icons/max_image2.svg +83 -0
- orgui/resources/icons/search-image.png +0 -0
- orgui/resources/icons/search-image.svg +94 -0
- orgui/resources/icons/search-reflection.png +0 -0
- orgui/resources/icons/search-reflection.svg +126 -0
- orgui/resources/icons/search.png +0 -0
- orgui/resources/icons/search.svg +91 -0
- orgui/resources/icons/select-image.png +0 -0
- orgui/resources/icons/select-image.svg +60 -0
- orgui/resources/icons/set-reflection.png +0 -0
- orgui/resources/icons/set-reflection.svg +91 -0
- orgui/resources/icons/sum_image.png +0 -0
- orgui/resources/icons/sum_image.svg +63 -0
- orgui/resources/icons/sum_image2.png +0 -0
- orgui/resources/icons/sum_image2.svg +75 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# /*##########################################################################
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2020-2024 Timo Fuchs
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
# furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
# THE SOFTWARE.
|
|
23
|
+
#
|
|
24
|
+
# ###########################################################################*/
|
|
25
|
+
__author__ = "Timo Fuchs"
|
|
26
|
+
__copyright__ = "Copyright 2020-2024 Timo Fuchs"
|
|
27
|
+
__license__ = "MIT License"
|
|
28
|
+
__version__ = "1.0.0"
|
|
29
|
+
__maintainer__ = "Timo Fuchs"
|
|
30
|
+
__email__ = "fuchs@physik.uni-kiel.de"
|
|
31
|
+
|
|
32
|
+
import sys
|
|
33
|
+
import traceback
|
|
34
|
+
import os
|
|
35
|
+
from io import StringIO
|
|
36
|
+
from silx.gui import qt
|
|
37
|
+
from .ArrayTableDialog import ArrayEditWidget
|
|
38
|
+
from collections import OrderedDict
|
|
39
|
+
from dataclasses import dataclass, field
|
|
40
|
+
from typing import ClassVar
|
|
41
|
+
|
|
42
|
+
import numpy as np
|
|
43
|
+
from ..datautils.xrayutils import HKLVlieg
|
|
44
|
+
|
|
45
|
+
from .. import resources
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class HKLReflection:
|
|
49
|
+
xy: np.ndarray
|
|
50
|
+
hkl: np.ndarray
|
|
51
|
+
imageno: int
|
|
52
|
+
identifier : str
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def fromStr(cls,string):
|
|
56
|
+
h,k,l,x,y,imageno = string.split()
|
|
57
|
+
refl = cls([x,y],[h,k,l],int(imageno))
|
|
58
|
+
return refl
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def fromArray(arr, identifier):
|
|
62
|
+
reflist = []
|
|
63
|
+
if arr.ndim == 1:
|
|
64
|
+
h,k,l,x,y,imageno = arr
|
|
65
|
+
refl = HKLReflection([x,y],[h,k,l],int(imageno), identifier)
|
|
66
|
+
return refl
|
|
67
|
+
if len(identifier) != len(arr):
|
|
68
|
+
raise ValueError("Mismatch between number of reflections in array and identifiers.")
|
|
69
|
+
for row, ident in zip(arr, identifier):
|
|
70
|
+
h,k,l,x,y,imageno = row
|
|
71
|
+
reflist.append(HKLReflection([x,y],[h,k,l],int(imageno), ident))
|
|
72
|
+
return reflist
|
|
73
|
+
|
|
74
|
+
def __array__(self):
|
|
75
|
+
return np.concatenate([self.hkl,self.xy,[self.imageno]])
|
|
76
|
+
|
|
77
|
+
class QReflectionSelector(qt.QSplitter):
|
|
78
|
+
sigQueryImageChange = qt.pyqtSignal(int)
|
|
79
|
+
sigQuerySaveReflections = qt.pyqtSignal()
|
|
80
|
+
sigQueryLoadReflections = qt.pyqtSignal()
|
|
81
|
+
#sigImagePathChanged = qt.pyqtSignal(object)
|
|
82
|
+
#sigImageNoChanged = qt.pyqtSignal(object)
|
|
83
|
+
def __init__(self,plot, ubcalc, parent=None):
|
|
84
|
+
qt.QSplitter.__init__(self, parent=None)
|
|
85
|
+
self.setOrientation(qt.Qt.Vertical)
|
|
86
|
+
self.plot = plot
|
|
87
|
+
self.ubcalc = ubcalc
|
|
88
|
+
self.orparent = parent
|
|
89
|
+
|
|
90
|
+
self.reflections = []
|
|
91
|
+
self.reflBragg = []
|
|
92
|
+
|
|
93
|
+
self.nextNo = 0
|
|
94
|
+
self.imageno = 0
|
|
95
|
+
|
|
96
|
+
self._showReferenceReflections = True
|
|
97
|
+
self.showBraggReflections = False
|
|
98
|
+
|
|
99
|
+
self.activeReflection = None
|
|
100
|
+
|
|
101
|
+
self.plot.sigKeyPressDelete.connect(self._onDelete)
|
|
102
|
+
|
|
103
|
+
editorTabWidget = qt.QTabWidget()
|
|
104
|
+
|
|
105
|
+
self.refleditor = ArrayEditWidget(True, 1)
|
|
106
|
+
header = ['H', 'K', 'L', 'x', 'y', 'imageno']
|
|
107
|
+
self.refleditor.setArrayData(np.array([]).reshape((-1,6)), editable=True, header=header)
|
|
108
|
+
#self.updateEditor()
|
|
109
|
+
self.refleditor.model.dataChanged.connect(self._onDataChanged)
|
|
110
|
+
self.refleditor.sigRowAdded.connect(self._onRowAdded)
|
|
111
|
+
self.refleditor.sigDataLoaded.connect(self.reflectionsFromEditor)
|
|
112
|
+
self.refleditor.sigRowsDeleted.connect(self._onRowsDeleted)
|
|
113
|
+
self.refleditor.view.setSelectionBehavior(qt.QAbstractItemView.SelectRows)
|
|
114
|
+
self.refleditor.view.selectionModel().currentRowChanged.connect(self._onSelectedRowChanged)
|
|
115
|
+
|
|
116
|
+
spacer_widget = qt.QWidget()
|
|
117
|
+
spacer_widget.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Preferred)
|
|
118
|
+
self.refleditor.toolbar.addWidget(spacer_widget)
|
|
119
|
+
|
|
120
|
+
self.setImageAct = qt.QAction(resources.getQicon('select-image'), "select Image", self)
|
|
121
|
+
self.setImageAct.setToolTip("set this image for the chosen reflection")
|
|
122
|
+
self.setImageAct.triggered.connect(self._onSetImage)
|
|
123
|
+
self.refleditor.toolbar.addAction(self.setImageAct)
|
|
124
|
+
|
|
125
|
+
self.gotoImageAct = qt.QAction(resources.getQicon('search-image'), "search image",self)
|
|
126
|
+
self.gotoImageAct.setToolTip("diplay image with the chosen reflection")
|
|
127
|
+
self.gotoImageAct.triggered.connect(self._onGotoImage)
|
|
128
|
+
self.refleditor.toolbar.addAction(self.gotoImageAct)
|
|
129
|
+
|
|
130
|
+
editorTabWidget.addTab(self.refleditor, "intrinsic coord")
|
|
131
|
+
|
|
132
|
+
self.refleditor_angles = ArrayEditWidget(True, -1, False)
|
|
133
|
+
header = ['H', 'K', 'L', 'alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']
|
|
134
|
+
self.refleditor_angles.setArrayData(np.array([]).reshape((-1,9)), editable=False, header=header)
|
|
135
|
+
self.refleditor_angles.view.setSelectionBehavior(qt.QAbstractItemView.SelectRows)
|
|
136
|
+
self.refleditor_angles.view.selectionModel().currentRowChanged.connect(self._onSelectedRowChanged)
|
|
137
|
+
editorTabWidget.addTab(self.refleditor_angles, "SIXC angles")
|
|
138
|
+
|
|
139
|
+
self.addWidget(editorTabWidget)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _onDataChanged(self, *dat):
|
|
143
|
+
data = self.refleditor.getData()
|
|
144
|
+
idx_no = dat[0].row()
|
|
145
|
+
identifier = self.reflections[idx_no].identifier
|
|
146
|
+
if data.ndim > 1:
|
|
147
|
+
refl = HKLReflection.fromArray(data[idx_no], identifier)
|
|
148
|
+
else:
|
|
149
|
+
refl = HKLReflection.fromArray(data, identifier)
|
|
150
|
+
self.reflections[idx_no] = refl
|
|
151
|
+
if self.activeReflection != identifier:
|
|
152
|
+
self.setReflectionActive(identifier)
|
|
153
|
+
else:
|
|
154
|
+
self.redrawActiveReflection()
|
|
155
|
+
|
|
156
|
+
def anglesReflection(self, refl):
|
|
157
|
+
if self.orparent.fscan is None:
|
|
158
|
+
return np.array([np.nan,np.nan,np.nan, np.nan, np.nan, np.nan])
|
|
159
|
+
print(refl.imageno)
|
|
160
|
+
mu, om = self.orparent.getMuOm(refl.imageno)
|
|
161
|
+
|
|
162
|
+
gamma, delta = self.ubcalc.detectorCal.surfaceAnglesPoint(np.array([refl.xy[1]]),np.array([refl.xy[0]]), mu)
|
|
163
|
+
pos = [mu,delta[0],gamma[0],om,self.ubcalc.chi,self.ubcalc.phi]
|
|
164
|
+
pos = HKLVlieg.crystalAngles(pos,self.ubcalc.n)
|
|
165
|
+
return np.array(pos)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _onRowAdded(self, row):
|
|
169
|
+
identifier = 'ref_'+str(self.nextNo)
|
|
170
|
+
if self.refleditor.getData().ndim > 1:
|
|
171
|
+
refl = HKLReflection.fromArray(self.refleditor.getData()[row], identifier)
|
|
172
|
+
else:
|
|
173
|
+
refl = HKLReflection.fromArray(self.refleditor.getData(), identifier)
|
|
174
|
+
self.nextNo += 1
|
|
175
|
+
angles = np.concatenate([refl.hkl,np.rad2deg(self.anglesReflection(refl))])
|
|
176
|
+
angledata = self.refleditor_angles.getData()
|
|
177
|
+
if angledata.ndim > 1:
|
|
178
|
+
angledata = np.insert(angledata, row, angles, axis=0)
|
|
179
|
+
elif angledata.ndim == 1:
|
|
180
|
+
if row == 0:
|
|
181
|
+
angledata = np.vstack([angles, angledata])
|
|
182
|
+
elif row == 1:
|
|
183
|
+
angledata = np.vstack([angledata, angles])
|
|
184
|
+
else:
|
|
185
|
+
angledata = angles[np.newaxis,:]
|
|
186
|
+
self.refleditor_angles.updateArrayData(angledata)
|
|
187
|
+
|
|
188
|
+
if self._showReferenceReflections:
|
|
189
|
+
self.plot.addMarker(*refl.xy,legend=refl.identifier,text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='blue',selectable=True,draggable=True,symbol='.')
|
|
190
|
+
self.reflections.insert(row, refl)
|
|
191
|
+
self.setReflectionActive(refl.identifier)
|
|
192
|
+
|
|
193
|
+
def _onRowsDeleted(self, rows):
|
|
194
|
+
idents = []
|
|
195
|
+
for r in rows:
|
|
196
|
+
idents.append(self.reflections[r].identifier)
|
|
197
|
+
for ident in idents:
|
|
198
|
+
self.deleteReflection(ident)
|
|
199
|
+
"""
|
|
200
|
+
print(self.refleditor_angles.getData())
|
|
201
|
+
angledata = np.atleast_2d(self.refleditor_angles.getData())
|
|
202
|
+
print(angledata)
|
|
203
|
+
mask = np.ones(len(angledata),dtype=bool)
|
|
204
|
+
print(mask)
|
|
205
|
+
mask[np.array(rows)] = False
|
|
206
|
+
angledata = angledata[mask]
|
|
207
|
+
print(angledata)
|
|
208
|
+
print(angledata.ndim )
|
|
209
|
+
if angledata.ndim == 1:
|
|
210
|
+
angledata = angledata[np.newaxis,:]
|
|
211
|
+
elif angledata.ndim == 0:
|
|
212
|
+
angledata = np.array([]).reshape((-1,9))
|
|
213
|
+
self.refleditor_angles.updateArrayData(angledata)
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
def _onSelectedRowChanged(self, selected, deselected):
|
|
217
|
+
row = selected.row()
|
|
218
|
+
refl = self.reflections[row]
|
|
219
|
+
if self._showReferenceReflections:
|
|
220
|
+
if self.activeReflection is not None:
|
|
221
|
+
self.setReflectionInactive(self.activeReflection)
|
|
222
|
+
self.plot.removeMarker(refl.identifier)
|
|
223
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=refl.identifier,text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='red',selectable=True,draggable=True,symbol='.')
|
|
224
|
+
self.activeReflection = refl.identifier
|
|
225
|
+
else:
|
|
226
|
+
self.activeReflection = refl.identifier
|
|
227
|
+
|
|
228
|
+
def setBraggReflectionsVisible(self, visible):
|
|
229
|
+
if visible:
|
|
230
|
+
self.showBraggReflections = True
|
|
231
|
+
self.redrawBraggReflections()
|
|
232
|
+
else:
|
|
233
|
+
self.showBraggReflections = False
|
|
234
|
+
self.clearPlotBraggReflections()
|
|
235
|
+
|
|
236
|
+
def setBraggReflections(self, hkls, yx, angles):
|
|
237
|
+
self.__cached_bragg_refl = hkls, yx, angles
|
|
238
|
+
if self.showBraggReflections:
|
|
239
|
+
self.clearPlotBraggReflections()
|
|
240
|
+
self.reflBragg.clear()
|
|
241
|
+
for i, (hkl, yxr, pos) in enumerate(zip(hkls, yx, angles)):
|
|
242
|
+
identifier = 'bragg_'+str(i)
|
|
243
|
+
self.reflBragg.append(HKLReflection(yxr[::-1], hkl,1, identifier))
|
|
244
|
+
if self.showBraggReflections:
|
|
245
|
+
self.redrawBraggReflections()
|
|
246
|
+
else:
|
|
247
|
+
self.clearPlotBraggReflections()
|
|
248
|
+
|
|
249
|
+
def getBraggReflections(self):
|
|
250
|
+
if hasattr(self, "__cached_bragg_refl") and self.showBraggReflections:
|
|
251
|
+
return self.__cached_bragg_refl
|
|
252
|
+
else:
|
|
253
|
+
raise ValueError("Bragg reflections are not calculated or are not shown!")
|
|
254
|
+
|
|
255
|
+
def setReferenceReflectionsVisible(self, visible):
|
|
256
|
+
if visible:
|
|
257
|
+
self._showReferenceReflections = True
|
|
258
|
+
self.redrawRefReflections()
|
|
259
|
+
else:
|
|
260
|
+
self._showReferenceReflections = False
|
|
261
|
+
self.clearPlotRefReflections()
|
|
262
|
+
|
|
263
|
+
def setImage(self,imageno):
|
|
264
|
+
self.imageno = imageno
|
|
265
|
+
|
|
266
|
+
def _onSaveReflections(self):
|
|
267
|
+
self.sigQuerySaveReflections.emit()
|
|
268
|
+
|
|
269
|
+
def _onLoadReflections(self):
|
|
270
|
+
self.sigQueryLoadReflections.emit()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def updateEditor(self):
|
|
274
|
+
if self.reflections:
|
|
275
|
+
array = np.vstack(self.reflections)
|
|
276
|
+
self.refleditor.updateArrayData(array)
|
|
277
|
+
anglearray = []
|
|
278
|
+
for refl in self.reflections:
|
|
279
|
+
anglearray.append(np.concatenate([refl.hkl,np.rad2deg(self.anglesReflection(refl))]))
|
|
280
|
+
anglearray = np.vstack(anglearray)
|
|
281
|
+
self.refleditor_angles.updateArrayData(anglearray)
|
|
282
|
+
else:
|
|
283
|
+
self.refleditor.updateArrayData(np.array([]).reshape((-1,6)))
|
|
284
|
+
self.refleditor_angles.updateArrayData(np.array([]).reshape((-1,9)))
|
|
285
|
+
try:
|
|
286
|
+
idx = self.indexReflection(self.activeReflection)
|
|
287
|
+
self.refleditor.view.selectRow(idx)
|
|
288
|
+
self.refleditor_angles.view.selectRow(idx)
|
|
289
|
+
except:
|
|
290
|
+
if self.reflections:
|
|
291
|
+
self.setReflectionActive(self.reflections[0].identifier)
|
|
292
|
+
else:
|
|
293
|
+
self.activeReflection = None
|
|
294
|
+
return
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def reflectionsFromEditor(self):
|
|
298
|
+
data = self.refleditor.getData()
|
|
299
|
+
idents = ['ref_'+str(i) for i in range(len(data))]
|
|
300
|
+
self.nextNo = len(data)
|
|
301
|
+
try:
|
|
302
|
+
if len(data) > 1:
|
|
303
|
+
reflist = HKLReflection.fromArray(data, idents)
|
|
304
|
+
self.setReflections(reflist)
|
|
305
|
+
else:
|
|
306
|
+
self.setReflections([])
|
|
307
|
+
except Exception:
|
|
308
|
+
qt.QMessageBox.critical(self,"Cannot read reflections", "Cannot read reeflections %s" % traceback.format_exc())
|
|
309
|
+
return
|
|
310
|
+
|
|
311
|
+
def clearPlotRefReflections(self):
|
|
312
|
+
for refl in self.reflections:
|
|
313
|
+
self.plot.removeMarker(refl.identifier)
|
|
314
|
+
|
|
315
|
+
def clearPlotBraggReflections(self):
|
|
316
|
+
for refl in self.reflBragg:
|
|
317
|
+
self.plot.removeMarker(refl.identifier)
|
|
318
|
+
|
|
319
|
+
def redrawBraggReflections(self):
|
|
320
|
+
self.clearPlotBraggReflections()
|
|
321
|
+
if self.showBraggReflections:
|
|
322
|
+
for refl in self.reflBragg:
|
|
323
|
+
#refl = self.reflBragg[identifier]
|
|
324
|
+
#text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl)
|
|
325
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=refl.identifier,color='g',selectable=False,draggable=False,symbol='x', text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl))
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def redrawRefReflections(self):
|
|
329
|
+
self.setReflections(self.reflections)
|
|
330
|
+
|
|
331
|
+
def setReflections(self,refls):
|
|
332
|
+
self.clearPlotRefReflections()
|
|
333
|
+
self.activeReflection = None
|
|
334
|
+
self.nextNo = 0
|
|
335
|
+
self.reflections.clear()
|
|
336
|
+
for refl in refls:
|
|
337
|
+
refl.identifier = 'ref_'+str(self.nextNo)
|
|
338
|
+
if self._showReferenceReflections:
|
|
339
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=refl.identifier,text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='blue',selectable=True,draggable=True,symbol='.')
|
|
340
|
+
|
|
341
|
+
self.reflections.append(refl)
|
|
342
|
+
self.nextNo += 1
|
|
343
|
+
if self.reflections:
|
|
344
|
+
newactive = self.reflections[0].identifier
|
|
345
|
+
self.setReflectionActive(newactive)
|
|
346
|
+
|
|
347
|
+
def addReflection(self,eventdict,imageno,hkl=np.array([np.nan,np.nan,np.nan])):
|
|
348
|
+
identifier = 'ref_'+str(self.nextNo)
|
|
349
|
+
refl = HKLReflection([eventdict['x'],eventdict['y']],hkl,imageno,identifier)
|
|
350
|
+
if self._showReferenceReflections:
|
|
351
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=refl.identifier,text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='blue',selectable=True,draggable=True,symbol='.')
|
|
352
|
+
self.reflections.append(refl)
|
|
353
|
+
self.nextNo += 1
|
|
354
|
+
self.updateEditor()
|
|
355
|
+
self.setReflectionActive(identifier)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def indexReflection(self, identifier):
|
|
359
|
+
return [ref.identifier for ref in self.reflections].index(identifier)
|
|
360
|
+
|
|
361
|
+
def setReflectionActive(self,identifier):
|
|
362
|
+
idx = self.indexReflection(identifier)
|
|
363
|
+
refl = self.reflections[idx]
|
|
364
|
+
if self._showReferenceReflections:
|
|
365
|
+
if self.activeReflection is not None:
|
|
366
|
+
self.setReflectionInactive(self.activeReflection)
|
|
367
|
+
self.plot.removeMarker(identifier)
|
|
368
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=str(identifier),text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='red',selectable=True,draggable=True,symbol='.')
|
|
369
|
+
self.activeReflection = identifier
|
|
370
|
+
else:
|
|
371
|
+
self.activeReflection = identifier
|
|
372
|
+
selectModel = self.refleditor.view.selectionModel()
|
|
373
|
+
if idx != selectModel.currentIndex().row():
|
|
374
|
+
self.refleditor.view.selectRow(idx)
|
|
375
|
+
self.refleditor_angles.view.selectRow(idx)
|
|
376
|
+
|
|
377
|
+
def setReflectionInactive(self,identifier):
|
|
378
|
+
if self._showReferenceReflections:
|
|
379
|
+
self.plot.removeMarker(identifier)
|
|
380
|
+
refl = self.reflections[self.indexReflection(identifier)]
|
|
381
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=str(identifier),text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='blue',selectable=True,draggable=True,symbol='.')
|
|
382
|
+
|
|
383
|
+
def moveReflection(self,identifier,xy):
|
|
384
|
+
self.reflections[self.indexReflection(identifier)].xy = xy
|
|
385
|
+
self.updateEditor()
|
|
386
|
+
|
|
387
|
+
def redrawActiveReflection(self):
|
|
388
|
+
if self._showReferenceReflections:
|
|
389
|
+
self.plot.removeMarker(self.activeReflection)
|
|
390
|
+
refl = self.reflections[self.indexReflection(self.activeReflection)]
|
|
391
|
+
self.plot.addMarker(refl.xy[0],refl.xy[1],legend=str(self.activeReflection),text="(%0.1f,%0.1f,%0.1f)" % tuple(refl.hkl),color='red',selectable=True,draggable=True,symbol='.')
|
|
392
|
+
|
|
393
|
+
def _onGotoImage(self):
|
|
394
|
+
if self.activeReflection is not None:
|
|
395
|
+
self.sigQueryImageChange.emit(self.reflections[self.indexReflection(self.activeReflection)].imageno)
|
|
396
|
+
|
|
397
|
+
def _onSetImage(self):
|
|
398
|
+
if self.activeReflection is not None:
|
|
399
|
+
self.reflections[self.indexReflection(self.activeReflection)].imageno = self.imageno
|
|
400
|
+
self.updateEditor()
|
|
401
|
+
|
|
402
|
+
def _onDelete(self):
|
|
403
|
+
try:
|
|
404
|
+
idx = self.indexReflection(self.activeReflection)
|
|
405
|
+
except:
|
|
406
|
+
return
|
|
407
|
+
refl = self.reflections[idx]
|
|
408
|
+
btn = qt.QMessageBox.question(self, "Delete reflection?",
|
|
409
|
+
"Do you want to delete the reflection?\n%s" % refl.hkl,
|
|
410
|
+
qt.QMessageBox.Yes | qt.QMessageBox.No, qt.QMessageBox.Yes)
|
|
411
|
+
if btn == qt.QMessageBox.Yes:
|
|
412
|
+
self.deleteReflection(self.activeReflection)
|
|
413
|
+
|
|
414
|
+
def deleteReflection(self,identifier):
|
|
415
|
+
try:
|
|
416
|
+
del self.reflections[self.indexReflection(identifier)]
|
|
417
|
+
except:
|
|
418
|
+
return
|
|
419
|
+
|
|
420
|
+
if self._showReferenceReflections:
|
|
421
|
+
self.plot.removeMarker(identifier)
|
|
422
|
+
if self.activeReflection == identifier:
|
|
423
|
+
self.activeReflection = None
|
|
424
|
+
if self.reflections:
|
|
425
|
+
newactive = self.reflections[0]
|
|
426
|
+
self.setReflectionActive(newactive.identifier)
|
|
427
|
+
self.updateEditor()
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
class QReflectionAnglesDialog(qt.QDialog):
|
|
432
|
+
"""Displays the angles for a reflection. Allows for multiple solutions.
|
|
433
|
+
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
class QSelectableLabel(qt.QLabel):
|
|
437
|
+
def __init__(self, *args, **kwags):
|
|
438
|
+
qt.QLabel.__init__(self,*args, **kwags)
|
|
439
|
+
self.setTextInteractionFlags(qt.Qt.TextSelectableByKeyboard | qt.Qt.TextSelectableByMouse)
|
|
440
|
+
|
|
441
|
+
def __init__(self,reflection, message, parent=None):
|
|
442
|
+
qt.QDialog.__init__(self, parent=None)
|
|
443
|
+
|
|
444
|
+
layout = qt.QVBoxLayout()
|
|
445
|
+
|
|
446
|
+
layout.addWidget(qt.QLabel(message))
|
|
447
|
+
|
|
448
|
+
layout.addWidget(QReflectionAnglesDialog.QSelectableLabel("Reflection: %s" % reflection['hkl']))
|
|
449
|
+
|
|
450
|
+
reflectionLayout = qt.QGridLayout()
|
|
451
|
+
|
|
452
|
+
available_data = [k.split('_')[0] for k in reflection.keys()]
|
|
453
|
+
self.header = ""
|
|
454
|
+
self.idx_dict = {}
|
|
455
|
+
i = 1
|
|
456
|
+
if 'xy' in available_data:
|
|
457
|
+
for lbl in ['x', 'y']:
|
|
458
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel(lbl), 0, i)
|
|
459
|
+
self.idx_dict[lbl] = i
|
|
460
|
+
i += 1
|
|
461
|
+
self.header += lbl + '\t'
|
|
462
|
+
if 'angles' in available_data:
|
|
463
|
+
for lbl in ['mu', 'delta', 'gamma', 'theta', 'chi', 'phi']:
|
|
464
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel(lbl), 0, i)
|
|
465
|
+
self.idx_dict[lbl] = i
|
|
466
|
+
i += 1
|
|
467
|
+
self.header += lbl + '\t'
|
|
468
|
+
if 'imageno' in available_data:
|
|
469
|
+
for lbl in ['imageno']:
|
|
470
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel(lbl), 0, i)
|
|
471
|
+
self.idx_dict[lbl] = i
|
|
472
|
+
i += 1
|
|
473
|
+
self.header += lbl + '\t'
|
|
474
|
+
|
|
475
|
+
self.checkboxes = []
|
|
476
|
+
self.datastr = ""
|
|
477
|
+
number_refl = max([int(k.split('_')[-1]) for k in reflection.keys() if '_' in k])
|
|
478
|
+
for i in range(1,number_refl+1):
|
|
479
|
+
box = qt.QCheckBox()
|
|
480
|
+
reflectionLayout.addWidget(box, i, 0)
|
|
481
|
+
|
|
482
|
+
if not reflection.get('selectable_%s' % i, False):
|
|
483
|
+
box.setEnabled(False)
|
|
484
|
+
|
|
485
|
+
self.checkboxes.append(box)
|
|
486
|
+
if 'xy_%s' % i in reflection.keys():
|
|
487
|
+
xy = reflection['xy_%s' % i]
|
|
488
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % xy[0]), i, self.idx_dict['x'])
|
|
489
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % xy[1]), i, self.idx_dict['y'])
|
|
490
|
+
self.datastr += "%.5f\t" % xy[0]
|
|
491
|
+
self.datastr += "%.5f\t" % xy[1]
|
|
492
|
+
elif 'xy' in available_data:
|
|
493
|
+
self.datastr += "\t\t"
|
|
494
|
+
|
|
495
|
+
if 'angles_%s' % i in reflection.keys():
|
|
496
|
+
angles = np.rad2deg(reflection['angles_%s' % i])
|
|
497
|
+
angles[3] *= -1. # to theta
|
|
498
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[0]), i, self.idx_dict['mu'])
|
|
499
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[1]), i, self.idx_dict['delta'])
|
|
500
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[2]), i, self.idx_dict['gamma'])
|
|
501
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[3]), i, self.idx_dict['theta'])
|
|
502
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[4]), i, self.idx_dict['chi'])
|
|
503
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%.5f" % angles[5]), i, self.idx_dict['phi'])
|
|
504
|
+
for ang in angles:
|
|
505
|
+
self.datastr += "%.5f\t" % ang
|
|
506
|
+
elif 'angles' in available_data:
|
|
507
|
+
self.datastr += "\t\t\t\t\t\t"
|
|
508
|
+
|
|
509
|
+
if 'imageno_%s' % i in reflection.keys():
|
|
510
|
+
imageno = reflection['imageno_%s' % i]
|
|
511
|
+
reflectionLayout.addWidget(QReflectionAnglesDialog.QSelectableLabel("%s" % imageno), i, self.idx_dict['imageno'])
|
|
512
|
+
self.datastr += "%s" % imageno
|
|
513
|
+
elif 'imageno' in available_data:
|
|
514
|
+
self.datastr += "\t"
|
|
515
|
+
self.datastr += "\n"
|
|
516
|
+
layout.addLayout(reflectionLayout)
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
buttons = qt.QDialogButtonBox(qt.QDialogButtonBox.Ok | qt.QDialogButtonBox.Cancel,
|
|
520
|
+
qt.Qt.Horizontal)
|
|
521
|
+
copybutton = buttons.addButton("Copy to clipboad",qt.QDialogButtonBox.HelpRole)
|
|
522
|
+
copybutton.clicked.connect(self.copy_to_clipboard)
|
|
523
|
+
|
|
524
|
+
layout.addWidget(buttons)
|
|
525
|
+
|
|
526
|
+
okbtn = buttons.button(qt.QDialogButtonBox.Ok)
|
|
527
|
+
cancelbtn = buttons.button(qt.QDialogButtonBox.Cancel)
|
|
528
|
+
|
|
529
|
+
okbtn.clicked.connect(self.accept)
|
|
530
|
+
cancelbtn.clicked.connect(self.reject)
|
|
531
|
+
|
|
532
|
+
self.setLayout(layout)
|
|
533
|
+
|
|
534
|
+
def copy_to_clipboard(self):
|
|
535
|
+
app = qt.QApplication.instance()
|
|
536
|
+
app.clipboard().setText(self.header + "\n" + self.datastr)
|
|
537
|
+
|
|
538
|
+
|