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,433 @@
|
|
|
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 numpy as np
|
|
33
|
+
import os
|
|
34
|
+
import traceback
|
|
35
|
+
from silx.gui import qt
|
|
36
|
+
from silx.gui.data import ArrayTableWidget, ArrayTableModel
|
|
37
|
+
from silx.gui.widgets.TableWidget import TableView
|
|
38
|
+
from silx.gui.dialog.DataFileDialog import DataFileDialog
|
|
39
|
+
from silx.gui import icons
|
|
40
|
+
|
|
41
|
+
from silx.io.utils import save1D, savespec, NEXUS_HDF5_EXT
|
|
42
|
+
from silx.io.nxdata import save_NXdata
|
|
43
|
+
|
|
44
|
+
from orgui import resources
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def is_number(s):
|
|
49
|
+
try:
|
|
50
|
+
float(s)
|
|
51
|
+
return True
|
|
52
|
+
except ValueError:
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class DeleteRowAction(qt.QAction):
|
|
57
|
+
"""QAction to delete rows in a ArrayTableWidget
|
|
58
|
+
|
|
59
|
+
:param table: :class:`QTableView` to which this action belongs.
|
|
60
|
+
"""
|
|
61
|
+
def __init__(self, table, arrayTableWidget):
|
|
62
|
+
if not isinstance(table, qt.QTableView):
|
|
63
|
+
raise ValueError('DeleteRowAction must be initialised ' +
|
|
64
|
+
'with a QTableWidget.')
|
|
65
|
+
super(DeleteRowAction, self).__init__(table)
|
|
66
|
+
self.table = table
|
|
67
|
+
self.arrayTableWidget = arrayTableWidget
|
|
68
|
+
self.setText("Delete row")
|
|
69
|
+
self.setShortcut(qt.QKeySequence.Delete)
|
|
70
|
+
self.setShortcutContext(qt.Qt.WidgetShortcut)
|
|
71
|
+
self.setToolTip("Delete row of the array.")
|
|
72
|
+
self.triggered.connect(self.deleteSelectedRows)
|
|
73
|
+
|
|
74
|
+
def deleteSelectedRows(self):
|
|
75
|
+
"""Paste text from clipboard into the table.
|
|
76
|
+
|
|
77
|
+
:return: *True* in case of success, *False* if failed.
|
|
78
|
+
"""
|
|
79
|
+
selected_idx = self.table.selectedIndexes()
|
|
80
|
+
if len(selected_idx) < 1:
|
|
81
|
+
#msgBox = qt.QMessageBox(parent=self.table)
|
|
82
|
+
#msgBox.setText("A single cell must be selected to delete data")
|
|
83
|
+
#msgBox.exec()
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
data_model = self.table.model()
|
|
88
|
+
data = data_model.getData()
|
|
89
|
+
|
|
90
|
+
selected_row = np.unique([idx.row() for idx in selected_idx])
|
|
91
|
+
mask = np.ones(data.shape[0], dtype=np.bool_)
|
|
92
|
+
mask[selected_row] = False
|
|
93
|
+
|
|
94
|
+
self.arrayTableWidget.updateArrayData(data[mask])
|
|
95
|
+
self.arrayTableWidget.sigRowsDeleted.emit(selected_row)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class AddRowAction(qt.QAction):
|
|
99
|
+
"""QAction to add a row in a ArrayTableWidget
|
|
100
|
+
|
|
101
|
+
:param table: :class:`QTableView` to which this action belongs.
|
|
102
|
+
"""
|
|
103
|
+
def __init__(self, table, arrayTableWidget, fill_value=-1):
|
|
104
|
+
if not isinstance(table, qt.QTableView):
|
|
105
|
+
raise ValueError('AddRowAction must be initialised ' +
|
|
106
|
+
'with a QTableWidget.')
|
|
107
|
+
super(AddRowAction, self).__init__(table)
|
|
108
|
+
self.fill_value = fill_value
|
|
109
|
+
self.table = table
|
|
110
|
+
self.arrayTableWidget = arrayTableWidget
|
|
111
|
+
self.setText("Add row")
|
|
112
|
+
self.setShortcut(qt.QKeySequence.New)
|
|
113
|
+
self.setShortcutContext(qt.Qt.WidgetShortcut)
|
|
114
|
+
self.setToolTip("Add row to the array.")
|
|
115
|
+
self.triggered.connect(self.addRow)
|
|
116
|
+
|
|
117
|
+
def addRow(self):
|
|
118
|
+
"""Paste text from clipboard into the table.
|
|
119
|
+
|
|
120
|
+
:return: *True* in case of success, *False* if failed.
|
|
121
|
+
"""
|
|
122
|
+
selected_idx = self.table.selectedIndexes()
|
|
123
|
+
if len(selected_idx) > 1:
|
|
124
|
+
msgBox = qt.QMessageBox(parent=self.table)
|
|
125
|
+
msgBox.setText("A single cell must be selected to add a row")
|
|
126
|
+
msgBox.exec()
|
|
127
|
+
return False
|
|
128
|
+
|
|
129
|
+
data_model = self.table.model()
|
|
130
|
+
data = data_model.getData()
|
|
131
|
+
|
|
132
|
+
if len(selected_idx) == 0:
|
|
133
|
+
selected_row = data.shape[0]
|
|
134
|
+
else:
|
|
135
|
+
selected_row = selected_idx[0].row()
|
|
136
|
+
|
|
137
|
+
newdata = np.insert(data, selected_row, np.full(data.shape[-1],self.fill_value) ,0)
|
|
138
|
+
self.arrayTableWidget.updateArrayData(newdata)
|
|
139
|
+
self.arrayTableWidget.sigRowAdded.emit(selected_row)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class ArrayTableHeaderModel(ArrayTableModel.ArrayTableModel):
|
|
143
|
+
def headerData(self, section, orientation, role=qt.Qt.DisplayRole):
|
|
144
|
+
"""QAbstractTableModel method
|
|
145
|
+
Return the 0-based row or column index, for display in the
|
|
146
|
+
horizontal and vertical headers"""
|
|
147
|
+
data = super().headerData(section, orientation, role)
|
|
148
|
+
|
|
149
|
+
if role == qt.Qt.DisplayRole and orientation == qt.Qt.Horizontal and\
|
|
150
|
+
is_number(data):
|
|
151
|
+
if hasattr(self, "header"):
|
|
152
|
+
return self.header[section] if self.header is not None else data
|
|
153
|
+
else:
|
|
154
|
+
return data
|
|
155
|
+
else:
|
|
156
|
+
return data
|
|
157
|
+
|
|
158
|
+
class ArrayEditWidget(ArrayTableWidget.ArrayTableWidget):
|
|
159
|
+
"""Widget to display and edit an numpy array. It currently only supports
|
|
160
|
+
1d and 2d arrays.
|
|
161
|
+
|
|
162
|
+
It allows editong of entries and also the adding and removing of rows in the
|
|
163
|
+
array. I.e. the shape of the numpy array can be changed.
|
|
164
|
+
This however means that the array reference is changed and this widget cannot be used
|
|
165
|
+
like the :class:`ArrayTableWidget`, where the reference can remain unchanged.
|
|
166
|
+
Instead, :meth:`~ArrayEditWidget.getData` must be called every time!
|
|
167
|
+
|
|
168
|
+
A ToolBar will be created above the array view, which includes action buttons for
|
|
169
|
+
saving and loading of the array.
|
|
170
|
+
|
|
171
|
+
"""
|
|
172
|
+
sigRowAdded = qt.pyqtSignal(int)
|
|
173
|
+
sigRowsDeleted = qt.pyqtSignal(np.ndarray)
|
|
174
|
+
sigDataLoaded = qt.pyqtSignal()
|
|
175
|
+
|
|
176
|
+
def __init__(self, saveact: bool = True, openact: int = -1, rowActions=True, parent = None):
|
|
177
|
+
"""Creates a new :class:`ArrayEditWidget`.
|
|
178
|
+
|
|
179
|
+
If ``openact`` is set, only arrays which have the same size
|
|
180
|
+
of this particular axis will be opened by the ToolBar buttons.
|
|
181
|
+
Set it to ``-1`` to diable the filtering.
|
|
182
|
+
|
|
183
|
+
:param saveact: Display the save array buttons.
|
|
184
|
+
:type saveact: bool
|
|
185
|
+
:param openact: Display the load array buttons. Set it to ``-1`` to diable the buttons.
|
|
186
|
+
:type openact: int
|
|
187
|
+
:param parent: parent QWidget
|
|
188
|
+
:param labels: list of labels for each dimension of the array
|
|
189
|
+
"""
|
|
190
|
+
qt.QWidget.__init__(self, parent)
|
|
191
|
+
self.mainLayout = qt.QVBoxLayout(self)
|
|
192
|
+
self.mainLayout.setContentsMargins(0, 0, 0, 0)
|
|
193
|
+
self.mainLayout.setSpacing(0)
|
|
194
|
+
|
|
195
|
+
self.browserContainer = qt.QWidget(self)
|
|
196
|
+
self.browserLayout = qt.QGridLayout(self.browserContainer)
|
|
197
|
+
self.browserLayout.setContentsMargins(0, 0, 0, 0)
|
|
198
|
+
self.browserLayout.setSpacing(0)
|
|
199
|
+
|
|
200
|
+
self._dimensionLabelsText = []
|
|
201
|
+
"""List of text labels sorted in the increasing order of the dimension
|
|
202
|
+
they apply to."""
|
|
203
|
+
self._browserLabels = []
|
|
204
|
+
"""List of QLabel widgets."""
|
|
205
|
+
self._browserWidgets = []
|
|
206
|
+
"""List of HorizontalSliderWithBrowser widgets."""
|
|
207
|
+
|
|
208
|
+
self.axesSelector = ArrayTableWidget.AxesSelector(self)
|
|
209
|
+
self.axesSelector.setVisible(False)
|
|
210
|
+
|
|
211
|
+
self.view = TableView(self)
|
|
212
|
+
|
|
213
|
+
self.toolbar = qt.QToolBar("Array modifier", self)
|
|
214
|
+
self.filedialogdir = os.getcwd()
|
|
215
|
+
if openact >= 0:
|
|
216
|
+
self.enableOpenAction()
|
|
217
|
+
|
|
218
|
+
if saveact:
|
|
219
|
+
self.enableSaveAction()
|
|
220
|
+
|
|
221
|
+
self.mainLayout.addWidget(self.toolbar)
|
|
222
|
+
#self.mainLayout.addWidget(self.browserContainer)
|
|
223
|
+
#self.mainLayout.addWidget(self.axesSelector)
|
|
224
|
+
self.mainLayout.addWidget(self.view)
|
|
225
|
+
|
|
226
|
+
self.model = ArrayTableHeaderModel(self)
|
|
227
|
+
self.view.setModel(self.model)
|
|
228
|
+
if rowActions:
|
|
229
|
+
self.view.deleteRowAction = DeleteRowAction(self.view, self)
|
|
230
|
+
self.view.addAction(self.view.deleteRowAction)
|
|
231
|
+
|
|
232
|
+
self.view.addRowAction = AddRowAction(self.view, self)
|
|
233
|
+
self.view.addAction(self.view.addRowAction)
|
|
234
|
+
|
|
235
|
+
self.retain_axis = openact
|
|
236
|
+
|
|
237
|
+
def getData(self, copy=True):
|
|
238
|
+
return np.atleast_1d(np.squeeze(super().getData(copy)))
|
|
239
|
+
|
|
240
|
+
def enableOpenAction(self):
|
|
241
|
+
if not hasattr(self, 'openAct'):
|
|
242
|
+
self.openAct = self.toolbar.addAction(icons.getQIcon('document-open'), "open ascii file")
|
|
243
|
+
self.openAct.triggered.connect(lambda x: self.openLoadtxt(self.retain_axis))
|
|
244
|
+
if not hasattr(self, 'openNXAct'):
|
|
245
|
+
self.openNXAct = self.toolbar.addAction(resources.getQicon('document-nx-open'), "open NEXUS-like")
|
|
246
|
+
self.openNXAct.triggered.connect(lambda x: self.openNXlike(self.retain_axis))
|
|
247
|
+
|
|
248
|
+
def enableSaveAction(self):
|
|
249
|
+
if not hasattr(self, 'saveAct'):
|
|
250
|
+
self.saveAct = self.toolbar.addAction(icons.getQIcon('document-save'), "save as file")
|
|
251
|
+
self.saveAct.triggered.connect(self.savetxt)
|
|
252
|
+
|
|
253
|
+
def openLoadtxt(self, retain_axis=1):
|
|
254
|
+
"""Displays a dialog to open an array using the `:meth:~numpy.loadtxt` function.
|
|
255
|
+
|
|
256
|
+
If ``retain_axis`` is set, only arrays which have the same size
|
|
257
|
+
of this particular axis will be accepted.
|
|
258
|
+
Set it to ``-1`` to diable the filtering. The default will only accept
|
|
259
|
+
arrays with the same number of columns as the original array.
|
|
260
|
+
|
|
261
|
+
:param retain_axis: Axis size filtering. Set to -1 to disable.
|
|
262
|
+
:type retain_axis: int
|
|
263
|
+
"""
|
|
264
|
+
fileTypeDict = {'dat Files (*.dat)': '.dat', 'txt Files (*.txt)': '.txt', 'All files (*)': '', }
|
|
265
|
+
fileTypeFilter = ""
|
|
266
|
+
for f in fileTypeDict:
|
|
267
|
+
fileTypeFilter += f + ";;"
|
|
268
|
+
#print(retain_axis)
|
|
269
|
+
filename, filetype = qt.QFileDialog.getOpenFileName(self,"Open file",
|
|
270
|
+
self.filedialogdir,
|
|
271
|
+
fileTypeFilter[:-2])
|
|
272
|
+
if filename == '':
|
|
273
|
+
return
|
|
274
|
+
self.filedialogdir = os.path.splitext(filename)[0]
|
|
275
|
+
try:
|
|
276
|
+
array_data = np.squeeze(np.loadtxt(filename))
|
|
277
|
+
if retain_axis >= 0:
|
|
278
|
+
if len(array_data.shape) == 1:
|
|
279
|
+
if len(self.getData().shape) != 1:
|
|
280
|
+
raise ValueError("Array must be a 1d array. Is: %s d" % len(self.getData().shape))
|
|
281
|
+
else:
|
|
282
|
+
self.updateArrayData(array_data)
|
|
283
|
+
self.sigDataLoaded.emit()
|
|
284
|
+
return True
|
|
285
|
+
else:
|
|
286
|
+
if array_data.shape[retain_axis] != self.getData().shape[retain_axis]:
|
|
287
|
+
raise ValueError("The number of data columns must match. Required: %s, Is: %s" % (self.getData().shape[retain_axis], array_data.shape[retain_axis]))
|
|
288
|
+
else:
|
|
289
|
+
self.updateArrayData(array_data)
|
|
290
|
+
self.sigDataLoaded.emit()
|
|
291
|
+
return True
|
|
292
|
+
else:
|
|
293
|
+
self.updateArrayData(array_data, header=None, labels=None)
|
|
294
|
+
self.sigDataLoaded.emit()
|
|
295
|
+
return True
|
|
296
|
+
|
|
297
|
+
except Exception:
|
|
298
|
+
qt.QMessageBox.critical(self,"Error during loading of array","Error during loading of array.\n%s" % traceback.format_exc())
|
|
299
|
+
|
|
300
|
+
def openNXlike(self, retain_axis=1):
|
|
301
|
+
"""Displays a dialog to open an array from any NEXUS like data source.
|
|
302
|
+
|
|
303
|
+
If ``retain_axis`` is set, only arrays which have the same size
|
|
304
|
+
of this particular axis will be accepted.
|
|
305
|
+
Set it to ``-1`` to diable the filtering. The default will only accept
|
|
306
|
+
arrays with the same number of columns as the original array.
|
|
307
|
+
|
|
308
|
+
:param retain_axis: Axis size filtering. Set to -1 to disable.
|
|
309
|
+
:type retain_axis: int
|
|
310
|
+
"""
|
|
311
|
+
dialog = DataFileDialog(self)
|
|
312
|
+
dialog.setFilterMode(DataFileDialog.FilterMode.ExistingDataset)
|
|
313
|
+
|
|
314
|
+
def customFilter(obj):
|
|
315
|
+
if len(obj.shape) == 0:
|
|
316
|
+
return False
|
|
317
|
+
if retain_axis >= 0:
|
|
318
|
+
if len(obj.shape) == 1:
|
|
319
|
+
if len(self.getData().shape) != 1:
|
|
320
|
+
return False
|
|
321
|
+
else:
|
|
322
|
+
return True
|
|
323
|
+
else:
|
|
324
|
+
if obj.shape[retain_axis] != self.getData().shape[retain_axis]:
|
|
325
|
+
return False
|
|
326
|
+
else:
|
|
327
|
+
return True
|
|
328
|
+
else:
|
|
329
|
+
return True
|
|
330
|
+
dialog.setFilterCallback(customFilter)
|
|
331
|
+
result = dialog.exec()
|
|
332
|
+
if result:
|
|
333
|
+
data = dialog.selectedData()
|
|
334
|
+
if retain_axis >= 0:
|
|
335
|
+
self.updateArrayData(data)
|
|
336
|
+
else:
|
|
337
|
+
self.updateArrayData(data, header=None, labels=None)
|
|
338
|
+
self.sigDataLoaded.emit()
|
|
339
|
+
|
|
340
|
+
def savetxt(self):
|
|
341
|
+
fmt = "%.7g"
|
|
342
|
+
csvdelim=";"
|
|
343
|
+
fileTypeDictSave1D = {"Plain ascii file (*.dat)" : "dat", "CSV file (*.csv)" : "csv", "NumPy format (*.npy)" : "ndarray"}
|
|
344
|
+
|
|
345
|
+
fileTypeDictSPEC = {'SPEC file (*.spec)': 'spec'}
|
|
346
|
+
|
|
347
|
+
fileTypeDict = {**fileTypeDictSave1D, **fileTypeDictSPEC}
|
|
348
|
+
|
|
349
|
+
fileTypeFilter = ""
|
|
350
|
+
for f in fileTypeDict:
|
|
351
|
+
fileTypeFilter += f + ";;"
|
|
352
|
+
|
|
353
|
+
filename, filetype = qt.QFileDialog.getSaveFileName(self,"Save array to file",
|
|
354
|
+
self.filedialogdir,
|
|
355
|
+
fileTypeFilter[:-2])
|
|
356
|
+
if filename == '':
|
|
357
|
+
return
|
|
358
|
+
self.filedialogdir = os.path.splitext(filename)[0]
|
|
359
|
+
|
|
360
|
+
if filetype in fileTypeDictSave1D:
|
|
361
|
+
if self.header is not None:
|
|
362
|
+
header = " ".join(self.header)
|
|
363
|
+
elif isinstance(self.header, str):
|
|
364
|
+
header = self.header
|
|
365
|
+
else:
|
|
366
|
+
header = " "
|
|
367
|
+
fileext = fileTypeDictSave1D[filetype]
|
|
368
|
+
data = self.getData()
|
|
369
|
+
if fileext == "dat":
|
|
370
|
+
np.savetxt(filename, data, header=header, fmt=fmt)
|
|
371
|
+
elif fileext == "csv":
|
|
372
|
+
np.savetxt(filename, data, header=header, fmt=fmt, delimiter=csvdelim)
|
|
373
|
+
elif fileext == "ndarray":
|
|
374
|
+
np.save(filename, data)
|
|
375
|
+
else:
|
|
376
|
+
raise Exception("No supported file type %s" % fileext)
|
|
377
|
+
|
|
378
|
+
def updateArrayData(self, data, **kwargs):
|
|
379
|
+
editable = kwargs.get('editable', self.model._editable)
|
|
380
|
+
labels = kwargs.get('labels', self._dimensionLabelsText)
|
|
381
|
+
header = kwargs.get('header', self.header)
|
|
382
|
+
self.setArrayData(data, labels=labels, editable=editable, header=self.header)
|
|
383
|
+
|
|
384
|
+
def setArrayData(self, data, labels=None, copy=True, editable=False, header=None):
|
|
385
|
+
if len(data.shape) == 1:
|
|
386
|
+
data = data[:,np.newaxis]
|
|
387
|
+
elif len(data.shape) > 2:
|
|
388
|
+
raise ValueError("Only supports 1D or 2D arrays")
|
|
389
|
+
if header is not None:
|
|
390
|
+
if len(header) == data.shape[1]:
|
|
391
|
+
self.model.header = header
|
|
392
|
+
self.header = header
|
|
393
|
+
else:
|
|
394
|
+
raise ValueError("Header size does not match data shape.")
|
|
395
|
+
else:
|
|
396
|
+
self.model.header = None
|
|
397
|
+
self.header = None
|
|
398
|
+
super().setArrayData(data, labels, copy, editable)
|
|
399
|
+
self.view.resizeColumnsToContents()
|
|
400
|
+
self.view.resizeRowsToContents()
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
class ArrayTableDialog(qt.QDialog):
|
|
404
|
+
|
|
405
|
+
def __init__(self, saveact: bool = True, openact: int = -1, parent = None):
|
|
406
|
+
qt.QDialog.__init__(self, parent)
|
|
407
|
+
|
|
408
|
+
self.arrayWidget = ArrayEditWidget(saveact, openact, self)
|
|
409
|
+
|
|
410
|
+
self.setArrayData = self.arrayWidget.setArrayData
|
|
411
|
+
self.updateArrayData = self.arrayWidget.updateArrayData
|
|
412
|
+
self.getData = self.arrayWidget.getData
|
|
413
|
+
|
|
414
|
+
layout = qt.QVBoxLayout(self)
|
|
415
|
+
|
|
416
|
+
layout.addWidget(self.arrayWidget)
|
|
417
|
+
|
|
418
|
+
self.setLayout(layout)
|
|
419
|
+
|
|
420
|
+
if __name__ == "__main__":
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
app = qt.QApplication([])
|
|
424
|
+
|
|
425
|
+
diag = ArrayTableDialog(True, 1)
|
|
426
|
+
|
|
427
|
+
array = np.arange(10*1).reshape((10,1))#[:,np.newaxis]
|
|
428
|
+
#array = np.arange(10)
|
|
429
|
+
diag.setArrayData(array,editable=True, header= ['h'])
|
|
430
|
+
|
|
431
|
+
diag.show()
|
|
432
|
+
app.exec()
|
|
433
|
+
|