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.
Files changed (83) hide show
  1. orGUI-1.0.1.dist-info/LICENSE +21 -0
  2. orGUI-1.0.1.dist-info/METADATA +147 -0
  3. orGUI-1.0.1.dist-info/RECORD +83 -0
  4. orGUI-1.0.1.dist-info/WHEEL +5 -0
  5. orGUI-1.0.1.dist-info/entry_points.txt +2 -0
  6. orGUI-1.0.1.dist-info/top_level.txt +1 -0
  7. orgui/__init__.py +36 -0
  8. orgui/app/ArrayTableDialog.py +433 -0
  9. orgui/app/QReflectionSelector.py +538 -0
  10. orgui/app/QScanSelector.py +692 -0
  11. orgui/app/QUBCalculator.py +1210 -0
  12. orgui/app/__init__.py +36 -0
  13. orgui/app/database.py +487 -0
  14. orgui/app/orGUI.py +2613 -0
  15. orgui/app/qutils.py +51 -0
  16. orgui/backend/__init__.py +32 -0
  17. orgui/backend/backends.py +157 -0
  18. orgui/backend/beamline/ID31DiffractLinTilt.py +77 -0
  19. orgui/backend/beamline/P212_tools.py +577 -0
  20. orgui/backend/beamline/__init__.py +36 -0
  21. orgui/backend/beamline/fio_reader.py +110 -0
  22. orgui/backend/beamline/id31_tools.py +651 -0
  23. orgui/backend/scans.py +95 -0
  24. orgui/backend/udefaults.py +163 -0
  25. orgui/backend/universalScanLoader.py +105 -0
  26. orgui/datautils/__init__.py +32 -0
  27. orgui/datautils/util.py +705 -0
  28. orgui/datautils/xrayutils/CTRcalc.py +3022 -0
  29. orgui/datautils/xrayutils/CTRopt.py +623 -0
  30. orgui/datautils/xrayutils/CTRplotutil.py +904 -0
  31. orgui/datautils/xrayutils/DetectorCalibration.py +685 -0
  32. orgui/datautils/xrayutils/HKLVlieg.py +1360 -0
  33. orgui/datautils/xrayutils/ReciprocalNavigation.py +401 -0
  34. orgui/datautils/xrayutils/_CTRcalc_accel.py +181 -0
  35. orgui/datautils/xrayutils/__init__.py +46 -0
  36. orgui/datautils/xrayutils/element_data.py +213 -0
  37. orgui/datautils/xrayutils/test/__init__.py +57 -0
  38. orgui/datautils/xrayutils/test/test_CTRcalc.py +152 -0
  39. orgui/datautils/xrayutils/test/test_DetectorCalibration.py +336 -0
  40. orgui/datautils/xrayutils/test/test_HKLcalc.py +88 -0
  41. orgui/datautils/xrayutils/unitcells/Fe3O4(100).bul +59 -0
  42. orgui/datautils/xrayutils/unitcells/Pt100.bul +7 -0
  43. orgui/datautils/xrayutils/unitcells/Pt100_small.bul +5 -0
  44. orgui/datautils/xrayutils/unitcells/Pt110.bul +5 -0
  45. orgui/datautils/xrayutils/unitcells/Pt111.bul +6 -0
  46. orgui/datautils/xrayutils/unitcells/Pt310.bul +13 -0
  47. orgui/datautils/xrayutils/unitcells/Pt3O4(100).bul +19 -0
  48. orgui/datautils/xrayutils/unitcells/PtO(001).bul +9 -0
  49. orgui/datautils/xrayutils/unitcells/PtO(010).bul +9 -0
  50. orgui/datautils/xrayutils/unitcells/PtO(100).bul +9 -0
  51. orgui/datautils/xrayutils/unitcells/__init__.py +67 -0
  52. orgui/datautils/xrayutils/unitcells/a-PtO2(0001).bul +6 -0
  53. orgui/main.py +101 -0
  54. orgui/resources/__init__.py +40 -0
  55. orgui/resources/icons/alpha.png +0 -0
  56. orgui/resources/icons/alpha.svg +67 -0
  57. orgui/resources/icons/diffractometer_v3.png +0 -0
  58. orgui/resources/icons/disable-image.png +0 -0
  59. orgui/resources/icons/disable-image.svg +68 -0
  60. orgui/resources/icons/document-nx-open.png +0 -0
  61. orgui/resources/icons/document-nx-open.svg +152 -0
  62. orgui/resources/icons/document-nx-save.png +0 -0
  63. orgui/resources/icons/document-nx-save.svg +73 -0
  64. orgui/resources/icons/logo.png +0 -0
  65. orgui/resources/icons/logo.svg +808 -0
  66. orgui/resources/icons/max_image.png +0 -0
  67. orgui/resources/icons/max_image.svg +77 -0
  68. orgui/resources/icons/max_image2.png +0 -0
  69. orgui/resources/icons/max_image2.svg +83 -0
  70. orgui/resources/icons/search-image.png +0 -0
  71. orgui/resources/icons/search-image.svg +94 -0
  72. orgui/resources/icons/search-reflection.png +0 -0
  73. orgui/resources/icons/search-reflection.svg +126 -0
  74. orgui/resources/icons/search.png +0 -0
  75. orgui/resources/icons/search.svg +91 -0
  76. orgui/resources/icons/select-image.png +0 -0
  77. orgui/resources/icons/select-image.svg +60 -0
  78. orgui/resources/icons/set-reflection.png +0 -0
  79. orgui/resources/icons/set-reflection.svg +91 -0
  80. orgui/resources/icons/sum_image.png +0 -0
  81. orgui/resources/icons/sum_image.svg +63 -0
  82. orgui/resources/icons/sum_image2.png +0 -0
  83. orgui/resources/icons/sum_image2.svg +75 -0
@@ -0,0 +1,577 @@
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
+
33
+ import numpy as np
34
+ import scipy.ndimage
35
+ import scipy.interpolate
36
+ import scipy.optimize
37
+ from matplotlib.colors import LinearSegmentedColormap
38
+ import datetime
39
+ import re
40
+ sqrt3 = np.sqrt(3)
41
+ import warnings
42
+ import fabio
43
+ import h5py
44
+ import os
45
+ import re
46
+ from datetime import datetime
47
+ from .fio_reader import FioFile
48
+ #from fio_reader import FioFile
49
+ import silx.io
50
+ from silx.io import dictdump
51
+
52
+ # not in use!!!
53
+ class P3_Image:
54
+ def __init__(self, filename,edf=False):
55
+ if edf:
56
+ image = fabio.open(filename)
57
+ #edf = EdfFile.EdfFile(filename, 'r')
58
+ #self.header = edf.GetHeader(0)
59
+ self.header = image.header
60
+ #self.header = edf.GetHeader(0)
61
+ self.motors = dict()
62
+ motor_mne = self.header['motor_mne'].split()
63
+ motor_pos = self.header['motor_pos'].split()
64
+ for i in range(len(motor_mne)):
65
+ self.motors[motor_mne[i]] = float(motor_pos[i])
66
+ self.counters = dict()
67
+ counter_mne = self.header['counter_mne'].split()
68
+ counter_pos = self.header['counter_pos'].split()
69
+ for i in range(len(counter_mne)):
70
+ self.counters[counter_mne[i]] = float(counter_pos[i])
71
+ self.img = image.data.astype(np.float64)
72
+ #self.img = np.array(edf.GetData(0), dtype=float)
73
+ else:
74
+ try:
75
+ image = fabio.open(filename)
76
+ self.header = image.header
77
+ self.img = image.data.astype(np.float64)
78
+ except Exception as e:
79
+ warnings.warn("Cannot open image, ok only during test run!!! %s" % e)
80
+ self.header = ""
81
+ #self.img = np.zeros((2880, 2880))
82
+
83
+
84
+
85
+
86
+ self.motors = dict() # not available in cbf
87
+ self.counters = dict() # not available in cbf
88
+
89
+
90
+
91
+
92
+ class PE_Image:
93
+ def __init__(self, filename, dark=None):
94
+
95
+ with fabio.open(filename) as img:
96
+ self.img = img.data.astype(np.float64)
97
+ self.header = img.header
98
+ self.motors = dict() # not jet available
99
+ self.counters = dict() # not jet available
100
+ if dark is not None:
101
+ self.img -= dark
102
+ # crude repair of images
103
+ #if np.mean(self.img) < 0:
104
+ # self.img += 72.2
105
+ self.img = np.fliplr(self.img.T)
106
+
107
+ class H5Fastsweep(object):
108
+ def __init__(self, hdffilepath_orNode=None, scanno=None):
109
+
110
+
111
+ #self.scanname = scanname
112
+ self.cameras = []
113
+ data = None
114
+
115
+ if hdffilepath_orNode is None:
116
+ return
117
+ self.hdffilepath_orNode=hdffilepath_orNode
118
+
119
+ if isinstance(hdffilepath_orNode, str):
120
+ self.hdffilepath_orNode = os.path.abspath(hdffilepath_orNode)
121
+ filepath,filename = os.path.split(self.hdffilepath_orNode)
122
+ filename_noext,_ = os.path.splitext(filepath)
123
+ #filename_noext = filename.split('.')[0]
124
+ self.filename_base = filename_noext #filename_noext[:filename_noext.rfind('_')]
125
+ with silx.io.open(self.hdffilepath_orNode) as f:
126
+ #print([d for d in f])
127
+ for d in f:
128
+ scanno_s, subscanno = d.split('.')
129
+ if int(scanno_s) == scanno:
130
+ break
131
+ else:
132
+ raise IOError("Scan number %s not found in file" % scanno)
133
+ self.scanname = '.'.join((scanno_s,subscanno))
134
+
135
+ data = dictdump.h5todict(f,self.scanname)
136
+
137
+
138
+ else:
139
+ hdffilepath = hdffilepath_orNode.local_filename
140
+ filepath,filename = os.path.split(hdffilepath)
141
+ filename_noext,_ = os.path.splitext(filepath)
142
+ self.filename_base = filename_noext
143
+
144
+ f = hdffilepath_orNode.file
145
+ for d in f:
146
+ scanno_s, subscanno = d.split('.')
147
+ if int(scanno_s) == scanno:
148
+ break
149
+ else:
150
+ raise IOError("Scan number %s not found in file" % scanno)
151
+ self.scanname = '.'.join((scanno_s,subscanno))
152
+
153
+ data = dictdump.h5todict(f,self.scanname)
154
+
155
+ self.th = data['measurement']['idrz1(encoder)']
156
+ dth = np.mean(np.diff(self.th))
157
+ self.th += dth
158
+ self.th = self.th[1:-1] #last image is missing, first image is dark file
159
+
160
+ self.th -= 180.
161
+
162
+ #meandt = np.mean(np.diff(datafile.data['time']))
163
+ self.exposure_time = np.full_like(self.th,1.) #np.diff(datafile.data['time'],append=(datafile.data['time'][-1] + meandt))
164
+ self.time = data['measurement']['time'][1:-1]
165
+ #self.th = -1*self.th # orientation of th is inversed
166
+ self.omega = -1*self.th
167
+
168
+
169
+
170
+ #self.exposure_time = np.full_like(self.th,self.exposure_time)
171
+ self.directFolder = True
172
+ self.imagenames = data['measurement']['filename']
173
+ #from IPython import embed; embed()
174
+ parsedscanname = re.compile('=\"([^\"]*)\"').findall(str(data['title']))
175
+
176
+ directory = parsedscanname[1]
177
+ _,folder = os.path.split(directory)
178
+ imagefolder = os.path.join(os.path.split(filepath)[0],folder)
179
+
180
+ self.filenames = [os.path.join(imagefolder,imgname) for imgname in self.imagenames ]
181
+ with fabio.open(self.filenames[0]) as fiof:
182
+ self.dark = fiof.data
183
+
184
+ self.filenames = self.filenames[1:-1]
185
+ #self.set_image_folder(self.path+ "/" + detector )
186
+ self.nopoints = self.th.size
187
+ self.axisname = 'th'
188
+ self.axis = getattr(self,self.axisname)
189
+
190
+
191
+
192
+ def set_th_offset(self,offset):
193
+ self.th += offset
194
+ self.omega = -1*self.th
195
+
196
+ """
197
+ def set_image_folder(self,path_to_folder):
198
+ #self.filenames = [None]*len(self.th)
199
+ self.filenames = []
200
+ basefolder = path_to_folder.split('/')[-1]
201
+ self.imageprefix = basefolder.split('_')[0]
202
+ if self.directFolder:
203
+ for i in range(self.th.size):
204
+ self.filenames.append("%s/%s_%05i.%s" % (path_to_folder,\
205
+ self.imageprefix,i+self.first_imageno,self.imagesuffix))
206
+ else:
207
+ for i in range(self.th.size):
208
+ self.filenames.append("%s/%s/%s_%05.cbf" % (path_to_folder,\
209
+ self.filename_base,self.filename_base,self.first_imageno+i))
210
+ """
211
+ def get_raw_P3_img(self,img):
212
+ return PE_Image(self.filenames[img],self.dark)
213
+
214
+ # returns single default image!
215
+ def get_raw_img(self,img):
216
+ return PE_Image(self.filenames[img],self.dark)
217
+
218
+ def get_P3_img(self,img):
219
+ imgdata = PE_Image(self.filenames[img],self.dark)
220
+ imgdata.counters['Time'] = self.time[img]
221
+ imgdata.counters['TrigTime'] = self.exposure_time[img]
222
+ imgdata.counters['th'] = self.th[img]
223
+ imgdata.counters['om'] = self.omega[img]
224
+ if self.current is not None:
225
+ imgdata.counters['srcur'] = self.current[img]
226
+ return imgdata
227
+
228
+ def __getitem__(self,key):
229
+ return self.get_P3_img(key)
230
+
231
+ def __len__(self):
232
+ return self.nopoints
233
+
234
+
235
+ # only log file existing
236
+ class XRRScan(object):
237
+ def __init__(self,logfilepath,img_prefix="xx",scanno=None):
238
+ self.path,fname = os.path.split(logfilepath)
239
+ #fnamewotsuff, suffix = fname.split('.')
240
+ #prefix, nostr = fnamewotsuff.split('_')
241
+ #if scanno is None:
242
+ # scanno = int(nostr)
243
+ #fiofilecorrectedscanno = "%s/%s_%05i.%s" % (self.path,prefix,scanno,suffix)
244
+ #self.dtime = []
245
+ #self.current = [] # sr current or some other monitor is missing!
246
+ with open(logfilepath,'r') as logfile:
247
+ line = logfile.readline()
248
+ self.header = []
249
+ while line.startswith('#'): # in header
250
+ self.header.append(line.strip('#').strip())
251
+ lineno = logfile.tell()
252
+ line = logfile.readline()
253
+ logfile.seek(lineno)
254
+ data = np.genfromtxt(logfile)
255
+ self.mu = -1*data[:,1]
256
+ self.th = np.full_like( self.mu,float( self.header[4].split()[-1] ))
257
+
258
+
259
+ #datafile = FioFile(fiofilecorrectedscanno)
260
+ #self.th = datafile.data['idrz1']
261
+ # ********** temporary fix *************************************
262
+ self.th -= 80.0
263
+ # **************************************************************
264
+ #imgfilepath, img_foldername = os.path.split(img_prefix)
265
+ #imagefoldernumber = int(img_foldername.split('_')[0])
266
+ #voltagelog = np.genfromtxt("%s/%i_voltage.log" % (imgfilepath,imagefoldernumber))
267
+ # file not saved !!! shit!
268
+
269
+ #meandt = np.mean(np.diff(datafile.data['time']))
270
+
271
+ self.exposure_time = np.full_like( self.mu,0.5) # for all XRRs in Dec 2019 beamtime
272
+
273
+ self.time = data[:,0]
274
+ #self.th = -1*self.th # orientation of th is inversed
275
+ self.omega = -1*self.th
276
+ self.current = data[:,2]
277
+
278
+
279
+ #self.exposure_time = np.full_like(self.th,self.exposure_time)
280
+ self.directFolder = True
281
+ #self.imagenames = datafile.data['filename']
282
+
283
+ self.imageprefix,fmiddle = img_prefix, "00001.tif"
284
+ self.imagesuffix = fmiddle.split('.')[-1]
285
+ self.first_imageno = 1
286
+
287
+ #self.set_image_folder(self.path+ "/" + detector )
288
+ self.nopoints = self.th.size
289
+
290
+ self.set_image_folder(img_prefix)
291
+
292
+ def set_th_offset(self,offset):
293
+ self.th += offset
294
+ self.omega = -1*self.th
295
+
296
+ def set_image_folder(self,path_to_folder):
297
+ #self.filenames = [None]*len(self.th)
298
+ self.filenames = []
299
+ basefolder = path_to_folder.split('/')[-1]
300
+ self.imageprefix = basefolder.split('_')[0]
301
+ if self.directFolder:
302
+ for i in range(self.th.size):
303
+ self.filenames.append("%s/%s_%05i.%s" % (path_to_folder,\
304
+ self.imageprefix,i+self.first_imageno,self.imagesuffix))
305
+ else:
306
+ for i in range(self.th.size):
307
+ self.filenames.append("%s/%s/%s_%05.cbf" % (path_to_folder,\
308
+ self.filename_base,self.filename_base,self.first_imageno+i))
309
+
310
+ def get_raw_P3_img(self,img):
311
+ return P3_Image(self.filenames[img])
312
+
313
+ # returns single default image!
314
+ def get_raw_img(self,img):
315
+ return P3_Image(self.filenames[img])
316
+
317
+ def get_P3_img(self,img):
318
+ imgdata = P3_Image(self.filenames[img])
319
+ imgdata.counters['Time'] = self.time[img]
320
+ imgdata.counters['TrigTime'] = self.exposure_time[img]
321
+ imgdata.counters['th'] = self.th[img]
322
+ imgdata.counters['om'] = self.omega[img]
323
+ if self.current is not None:
324
+ imgdata.counters['srcur'] = self.current[img]
325
+ if self.mu is not None:
326
+ imgdata.counters['mu'] = self.mu[img]
327
+ return imgdata
328
+
329
+ def __getitem__(self,key):
330
+ return self.get_P3_img(key)
331
+
332
+ def __len__(self):
333
+ return self.nopoints
334
+
335
+
336
+ class FioFastsweep(object):
337
+ def __init__(self,fiofilepath,img_prefix="xx",scanno=None):
338
+ self.path,fname = os.path.split(fiofilepath)
339
+ fnamewotsuff, suffix = fname.split('.')
340
+ prefix, nostr = fnamewotsuff.split('_')
341
+ if scanno is None:
342
+ scanno = int(nostr)
343
+ fiofilecorrectedscanno = "%s/%s_%05i.%s" % (self.path,prefix,scanno,suffix)
344
+ #self.dtime = []
345
+ #self.current = [] # sr current or some other monitor is missing!
346
+ datafile = FioFile(fiofilecorrectedscanno)
347
+ self.th = datafile.data['idrz1']
348
+ # ********** temporary fix *************************************
349
+ self.th -= 80.0
350
+ # **************************************************************
351
+ #imgfilepath, img_foldername = os.path.split(img_prefix)
352
+ #imagefoldernumber = int(img_foldername.split('_')[0])
353
+ #voltagelog = np.genfromtxt("%s/%i_voltage.log" % (imgfilepath,imagefoldernumber))
354
+ # file not saved !!! shit!
355
+
356
+ meandt = np.mean(np.diff(datafile.data['time']))
357
+ self.exposure_time = np.diff(datafile.data['time'],append=(datafile.data['time'][-1] + meandt))
358
+ self.time = datafile.data['time']
359
+ #self.th = -1*self.th # orientation of th is inversed
360
+ self.omega = -1*self.th
361
+
362
+
363
+
364
+ #self.exposure_time = np.full_like(self.th,self.exposure_time)
365
+ self.directFolder = True
366
+ self.imagenames = datafile.data['filename']
367
+ try:
368
+ self.imageprefix,fmiddle = self.imagenames[0].split('_')
369
+ self.imagesuffix = fmiddle.split('.')[-1]
370
+ print(self.imageprefix)
371
+ except:
372
+ self.imageprefix,fmiddle = img_prefix, "00001.tif"
373
+ self.imagesuffix = fmiddle.split('.')[-1]
374
+ self.first_imageno = 1
375
+ self.current = None
376
+ #self.set_image_folder(self.path+ "/" + detector )
377
+ self.nopoints = self.th.size
378
+
379
+
380
+
381
+
382
+
383
+ def set_th_offset(self,offset):
384
+ self.th += offset
385
+ self.omega = -1*self.th
386
+
387
+
388
+ def set_image_folder(self,path_to_folder):
389
+ #self.filenames = [None]*len(self.th)
390
+ self.filenames = []
391
+ basefolder = path_to_folder.split('/')[-1]
392
+ self.imageprefix = basefolder.split('_')[0]
393
+ if self.directFolder:
394
+ for i in range(self.th.size):
395
+ self.filenames.append("%s/%s_%05i.%s" % (path_to_folder,\
396
+ self.imageprefix,i+self.first_imageno,self.imagesuffix))
397
+ else:
398
+ for i in range(self.th.size):
399
+ self.filenames.append("%s/%s/%s_%05.cbf" % (path_to_folder,\
400
+ self.filename_base,self.filename_base,self.first_imageno+i))
401
+
402
+ def get_raw_P3_img(self,img):
403
+ return P3_Image(self.filenames[img])
404
+
405
+ # returns single default image!
406
+ def get_raw_img(self,img):
407
+ return P3_Image(self.filenames[img])
408
+
409
+ def get_P3_img(self,img):
410
+ imgdata = P3_Image(self.filenames[img])
411
+ imgdata.counters['Time'] = self.time[img]
412
+ imgdata.counters['TrigTime'] = self.exposure_time[img]
413
+ imgdata.counters['th'] = self.th[img]
414
+ imgdata.counters['om'] = self.omega[img]
415
+ if self.current is not None:
416
+ imgdata.counters['srcur'] = self.current[img]
417
+ return imgdata
418
+
419
+ def __getitem__(self,key):
420
+ return self.get_P3_img(key)
421
+
422
+ def __len__(self):
423
+ return self.nopoints
424
+
425
+ class FioFastsweep_original(object):
426
+ def __init__(self,fiofilepath,scanno=None):
427
+ self.path,fname = os.path.split(fiofilepath)
428
+ fnamewotsuff, suffix = fname.split('.')
429
+ prefix, nostr = fnamewotsuff.split('_')
430
+ if scanno is None:
431
+ scanno = int(nostr)
432
+ fiofilecorrectedscanno = "%s/%s_%05i.%s" % (self.path,prefix,scanno,suffix)
433
+ #self.dtime = []
434
+ #self.current = [] # sr current or some other monitor is missing!
435
+ datafile = FioFile(fiofilecorrectedscanno)
436
+ self.th = datafile.data['idrz1']
437
+ meandt = np.mean(np.diff(datafile.data['time']))
438
+ self.exposure_time = np.diff(datafile.data['time'],append=(datafile.data['time'][-1] + meandt))
439
+ self.time = datafile.data['time']
440
+ #self.th = -1*self.th # orientation of th is inversed
441
+ self.omega = -1*self.th
442
+ #self.exposure_time = np.full_like(self.th,self.exposure_time)
443
+ self.directFolder = True
444
+ self.imagenames = datafile.data['filename']
445
+ print(self.imagenames)
446
+ self.imageprefix,fmiddle = self.imagenames[0].split('_')
447
+ self.imagesuffix = fmiddle.split('.')[-1]
448
+ self.first_imageno = 1
449
+ self.current = None
450
+ #self.set_image_folder(self.path+ "/" + detector )
451
+ self.nopoints = self.th.size
452
+
453
+
454
+
455
+ def set_th_offset(self,offset):
456
+ self.th += offset
457
+ self.omega = -1*self.th
458
+
459
+
460
+ def set_image_folder(self,path_to_folder):
461
+ #self.filenames = [None]*len(self.th)
462
+ self.filenames = []
463
+ if self.directFolder:
464
+ for i in range(self.th.size):
465
+ self.filenames.append("%s/%s_%05i.%s" % (path_to_folder,\
466
+ self.imageprefix,i+self.first_imageno,self.imagesuffix))
467
+ else:
468
+ for i in range(self.th.size):
469
+ self.filenames.append("%s/%s/%s_%05.cbf" % (path_to_folder,\
470
+ self.filename_base,self.filename_base,self.first_imageno+i))
471
+
472
+ def get_raw_P3_img(self,img):
473
+ return P3_Image(self.filenames[img])
474
+
475
+ # returns single default image!
476
+ def get_raw_img(self,img):
477
+ return P3_Image(self.filenames[img])
478
+
479
+ def get_P3_img(self,img):
480
+ imgdata = P3_Image(self.filenames[img])
481
+ imgdata.counters['Time'] = self.time[img]
482
+ imgdata.counters['TrigTime'] = self.exposure_time[img]
483
+ imgdata.counters['th'] = self.th[img]
484
+ imgdata.counters['om'] = self.omega[img]
485
+ if self.current is not None:
486
+ imgdata.counters['srcur'] = self.current[img]
487
+ return imgdata
488
+
489
+ def __getitem__(self,key):
490
+ return self.get_P3_img(key)
491
+
492
+ def __len__(self):
493
+ return self.nopoints
494
+
495
+
496
+
497
+
498
+ class CrudeThScan(object):
499
+ def __init__(self,logfilepath,detector='PE1',darkfile=None):
500
+ self.path,_ = os.path.split(logfilepath)
501
+ self.th = []
502
+ self.dtime = []
503
+ self.current = []
504
+ self.dark = None
505
+ with open(logfilepath,'r') as f:
506
+ for l in f:
507
+ if l.startswith('#'):
508
+ if 'Exposure time' in l:
509
+ lsp = l.split()
510
+ self.exposure_time = float(lsp[2][:-1])
511
+ continue
512
+ lspl = l.split()
513
+ self.th.append(float(lspl[0]))
514
+ self.current.append(float(lspl[2]))
515
+ self.dtime.append(datetime.strptime(lspl[3] + ' ' + lspl[4],"%Y-%m-%d %H:%M:%S.%f"))
516
+ self.th = np.array(self.th)
517
+ self.current = np.array(self.current)
518
+ self.time = []
519
+ for t in self.dtime:
520
+ self.time.append(t.day*24*3600 + t.hour*3600 + t.minute*60 + t.second + t.microsecond*1e-6)
521
+ self.time = np.array(self.time)
522
+ #self.th = -1*self.th # orientation of th is inversed
523
+ self.omega = -1*self.th
524
+ self.exposure_time = np.full_like(self.th,self.exposure_time)
525
+ self.directFolder = True
526
+ self.filename_base = 'pe'
527
+ self.first_imageno = 1
528
+ self.set_image_folder(self.path+ "/" + detector )
529
+ self.nopoints = self.th.size
530
+
531
+ if darkfile is not None:
532
+ with fabio.open(darkfile) as img:
533
+ self.dark = img.data.astype(np.float64)
534
+
535
+
536
+
537
+ def set_th_offset(self,offset):
538
+ self.th += offset
539
+ self.omega = -1*self.th
540
+
541
+
542
+ def set_image_folder(self,path_to_folder):
543
+ #self.filenames = [None]*len(self.th)
544
+ self.filenames = []
545
+ if self.directFolder:
546
+ for i in range(self.th.size):
547
+ self.filenames.append("%s/%s%05i.tif.gz" % (path_to_folder,\
548
+ self.filename_base,self.first_imageno+i))
549
+ else:
550
+ for i in range(self.th.size):
551
+ self.filenames.append("%s/%s/%s_%05.cbf" % (path_to_folder,\
552
+ self.filename_base,self.filename_base,self.first_imageno+i))
553
+
554
+ def get_raw_PE_img(self,img):
555
+ return PE_Image(self.filenames[img],self.dark)
556
+
557
+ # returns single default image!
558
+ def get_raw_img(self,img):
559
+ return PE_Image(self.filenames[img],self.dark)
560
+
561
+ def get_PE_img(self,img):
562
+ imgdata = PE_Image(self.filenames[img],self.dark)
563
+ imgdata.counters['Time'] = self.time[img]
564
+ imgdata.counters['TrigTime'] = self.exposure_time[img]
565
+ imgdata.counters['th'] = self.th[img]
566
+ imgdata.counters['om'] = self.omega[img]
567
+ if self.current is not None:
568
+ imgdata.counters['srcur'] = self.current[img]
569
+ return imgdata
570
+
571
+ def __getitem__(self,key):
572
+ return self.get_PE_img(key)
573
+
574
+ def __len__(self):
575
+ return self.nopoints
576
+
577
+
@@ -0,0 +1,36 @@
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
+ """Module descripiton
33
+
34
+ """
35
+
36
+ __all__ = ['id31_tools', 'P212_tools']