PaIRS-UniNa 0.2.4__cp311-cp311-win_amd64.whl → 0.2.6__cp311-cp311-win_amd64.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.

Potentially problematic release.


This version of PaIRS-UniNa might be problematic. Click here for more details.

Files changed (58) hide show
  1. PaIRS_UniNa/Changes.txt +35 -0
  2. PaIRS_UniNa/Custom_Top.py +1 -1
  3. PaIRS_UniNa/Explorer.py +3063 -3049
  4. PaIRS_UniNa/FolderLoop.py +371 -371
  5. PaIRS_UniNa/Input_Tab.py +717 -709
  6. PaIRS_UniNa/Input_Tab_CalVi.py +4 -4
  7. PaIRS_UniNa/Input_Tab_tools.py +3018 -3009
  8. PaIRS_UniNa/Output_Tab.py +2 -2
  9. PaIRS_UniNa/PaIRS.py +17 -17
  10. PaIRS_UniNa/PaIRS_PIV.py +56 -1
  11. PaIRS_UniNa/PaIRS_pypacks.py +323 -60
  12. PaIRS_UniNa/Process_Tab.py +8 -13
  13. PaIRS_UniNa/Process_Tab_Disp.py +9 -4
  14. PaIRS_UniNa/Saving_tools.py +277 -277
  15. PaIRS_UniNa/TabTools.py +63 -21
  16. PaIRS_UniNa/Vis_Tab.py +293 -115
  17. PaIRS_UniNa/Whatsnew.py +13 -0
  18. PaIRS_UniNa/_PaIRS_PIV.pyd +0 -0
  19. PaIRS_UniNa/__init__.py +3 -3
  20. PaIRS_UniNa/gPaIRS.py +3825 -3600
  21. PaIRS_UniNa/icons/flaticon_PaIRS_download_warning.png +0 -0
  22. PaIRS_UniNa/icons/pencil_bw.png +0 -0
  23. PaIRS_UniNa/icons/pylog.png +0 -0
  24. PaIRS_UniNa/icons/python_warning.png +0 -0
  25. PaIRS_UniNa/icons/queue.png +0 -0
  26. PaIRS_UniNa/icons/uninitialized.png +0 -0
  27. PaIRS_UniNa/icons/window.png +0 -0
  28. PaIRS_UniNa/listLib.py +301 -301
  29. PaIRS_UniNa/parForMulti.py +433 -433
  30. PaIRS_UniNa/parForWorkers.py +46 -1
  31. PaIRS_UniNa/pivParFor.py +1 -1
  32. PaIRS_UniNa/procTools.py +17 -7
  33. PaIRS_UniNa/rqrdpckgs.txt +9 -0
  34. PaIRS_UniNa/stereoPivParFor.py +1 -1
  35. PaIRS_UniNa/tabSplitter.py +606 -606
  36. PaIRS_UniNa/ui_Calibration_Tab.py +542 -542
  37. PaIRS_UniNa/ui_Custom_Top.py +294 -294
  38. PaIRS_UniNa/ui_Input_Tab.py +1098 -1098
  39. PaIRS_UniNa/ui_Input_Tab_CalVi.py +1280 -1280
  40. PaIRS_UniNa/ui_Log_Tab.py +261 -261
  41. PaIRS_UniNa/ui_Output_Tab.py +2360 -2360
  42. PaIRS_UniNa/ui_Process_Tab.py +3808 -3808
  43. PaIRS_UniNa/ui_Process_Tab_CalVi.py +1547 -1547
  44. PaIRS_UniNa/ui_Process_Tab_Disp.py +1139 -968
  45. PaIRS_UniNa/ui_Process_Tab_Min.py +435 -435
  46. PaIRS_UniNa/ui_ResizePopup.py +203 -203
  47. PaIRS_UniNa/ui_Vis_Tab.py +1626 -1533
  48. PaIRS_UniNa/ui_Vis_Tab_CalVi.py +1249 -1249
  49. PaIRS_UniNa/ui_Whatsnew.py +131 -131
  50. PaIRS_UniNa/ui_gPairs.py +873 -849
  51. PaIRS_UniNa/ui_infoPaIRS.py +550 -428
  52. PaIRS_UniNa/whatsnew.txt +4 -4
  53. {PaIRS_UniNa-0.2.4.dist-info → pairs_unina-0.2.6.dist-info}/METADATA +47 -30
  54. {PaIRS_UniNa-0.2.4.dist-info → pairs_unina-0.2.6.dist-info}/RECORD +56 -51
  55. {PaIRS_UniNa-0.2.4.dist-info → pairs_unina-0.2.6.dist-info}/WHEEL +1 -1
  56. PaIRS_UniNa/stereo.py +0 -685
  57. PaIRS_UniNa-0.2.4.dist-info/LICENSE +0 -19
  58. {PaIRS_UniNa-0.2.4.dist-info → pairs_unina-0.2.6.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,8 @@ spin_tips={
8
8
  'SemiWidth_Epipolar' : 'Semi-width normal to epipolar line',
9
9
  'Filter_SemiWidth' : 'Semi-width of filter',
10
10
  'Threshold' : 'Threshold for disparity computation',
11
+ 'Nit_OutDet' : 'Number of iterations for outlier detection',
12
+ 'Std_Threshold' : 'S.t.d. threshold for disparity validation',
11
13
  }
12
14
  check_tips={}
13
15
  radio_tips={}
@@ -49,6 +51,8 @@ class PROpar_Disp(TABpar):
49
51
  self.Filter_SemiWidth = 10
50
52
  self.Threshold = 0.5
51
53
 
54
+ self.Nit_OutDet = 5
55
+ self.Std_Threshold = 3.0
52
56
 
53
57
  class Process_Tab_Disp(gPaIRS_Tab):
54
58
  class Process_Tab_Signals(gPaIRS_Tab.Tab_Signals):
@@ -105,7 +109,6 @@ class Process_Tab_Disp(gPaIRS_Tab):
105
109
  if flagInit:
106
110
  self.initialize()
107
111
 
108
-
109
112
  def initialize(self):
110
113
  pri.Info.yellow(f'{"*"*20} PROCESS Disp initialization {"*"*20}')
111
114
  self.setTABpar(FlagAdjustPar=True,FlagBridge=False)
@@ -115,20 +118,22 @@ class Process_Tab_Disp(gPaIRS_Tab):
115
118
  #*************************************************** Adjusting parameters
116
119
  def adjustPROpar(self):
117
120
  minIWSize=min([self.PROpar.Vect[0],self.PROpar.Vect[2]])
121
+ self.PROpar.SemiWidth_Epipolar=min([self.PROpar.SemiWidth_Epipolar, int(minIWSize/4)])
122
+ self.PROpar.Filter_SemiWidth=min([self.PROpar.Filter_SemiWidth, int(minIWSize/4)])
118
123
  self.ui.spin_SemiWidth_Epipolar.setMaximum(int(minIWSize/4))
119
124
  self.ui.spin_Filter_SemiWidth.setMaximum(int(minIWSize/4))
120
125
  return
121
-
122
-
126
+
123
127
  #*************************************************** Layout
124
128
  def setPROlayout(self):
129
+ self.ui.w_Std_Threshold.setVisible(self.PROpar.Nit_OutDet>0)
125
130
  return
126
131
 
127
132
  #*************************************************** Windowing and Correlation
128
133
  #******************** Actions
129
134
  def line_edit_IW_action(self):
130
135
  text=self.ui.line_edit_IW.text()
131
- split_text=re.split('(\d+)', text)[1:-1:2]
136
+ split_text=re.split(r'(\d+)', text)[1:-1:2]
132
137
  split_num=[int(t) for t in split_text]
133
138
  if len(split_num)<4: split_num+=[split_num[-1]]*(4-len(split_num))
134
139
  vect=[int(split_num[i]) for i in (0,2,1,3)]
@@ -1,20 +1,20 @@
1
- FLAG_SERIALIZED=True
2
-
3
- import os, json, pickle, traceback
1
+ FLAG_SERIALIZED=True
2
+
3
+ import os, json, pickle, traceback
4
4
  from .PaIRS_pypacks import pri
5
-
5
+
6
6
  from .TabTools import TABpar
7
7
  from .procTools import dataTreePar, CompMin, MediaPIV
8
8
  from .Explorer import TREpar, ITEpar, currentTimeString
9
9
  from .Input_Tab import INPpar
10
- globals()['ImportPar'] = INPpar.ImportPar
10
+ globals()['ImportPar'] = INPpar.ImportPar
11
11
  from .Input_Tab_tools import ImageSet
12
12
  from .Output_Tab import OUTpar
13
13
  from .Process_Tab import PROpar
14
14
  from .Log_Tab import LOGpar
15
15
  from .Vis_Tab import VISpar, NamesPIV
16
- globals()['OUT'] = VISpar.OUT
17
- globals()['PRO'] = VISpar.PRO
16
+ globals()['OUT'] = VISpar.OUT
17
+ globals()['PRO'] = VISpar.PRO
18
18
  from .Process_Tab_Min import PROpar_Min
19
19
  from .Process_Tab_Disp import PROpar_Disp
20
20
  from .Calibration_Tab import CALpar
@@ -24,273 +24,273 @@ from .Vis_Tab_CalVi import VISpar_CalVi
24
24
  from .tabSplitter import SPLpar
25
25
  from .PaIRS_pypacks import identifierName, fontPixelSize, printTypes
26
26
  from .__init__ import __version__,__subversion__,__year__,__mail__,__website__
27
-
28
- class GPApar(TABpar):
29
- def __init__(self):
30
- self.setup()
31
- super().__init__(self.name,'gPaIRS')
32
- self.unchecked_fields+=[]
33
-
34
- def setup(self):
35
- self.name_work, self.username, self.version = identifierName(typeObject='wksp')
36
- self.outName = ''
37
- self.createdDate = currentTimeString()
38
- self.modifiedDate = self.createdDate
39
- self.savedDate = ''
40
- self.FlagSaved = False
41
- self.FlagQueue = True
42
- self.FlagRunnable = True
43
-
44
- self.name = 'Workspace'
45
- self.date = f'Created: {self.createdDate}'
46
- self.icon = 'workspace.png'
47
-
48
- self.infoFields=[f for f,_ in self.__dict__.items()]
49
-
50
- self.Geometry = None
51
- self.WindowState = None
52
- self.SplitterSizes = {}
53
- self.ScrollAreaValues = {}
54
-
55
- #legacy
56
- self.FloatGeometry = []
57
- self.FloatVisible = []
58
-
59
- self.paletteType = 2 #-1,2=standard, 0=light, 1=dark
60
- self.fontPixelSize = fontPixelSize
61
- self.FlagOutDated = 0
62
- self.currentVersion = __version__
63
- self.latestVersion = ''
64
-
65
- self.printTypes = printTypes
66
- self.NumCores = 0
67
-
68
- self.stateFields=[f for f,_ in self.__dict__.items() if f not in self.infoFields]
69
-
70
- def saveBullet(self):
71
- return '' if self.FlagSaved else '<span style="color: #7A8B8B;"><sup>&#9679;</sup></span>'
72
-
73
- def InfoMessage(self):
74
- InfoMessage=f'{self.name}'
75
- if self.FlagSaved:
76
- InfoMessage+=f'\nFile location: {self.outName}'
77
- else:
78
- if self.savedDate:
79
- InfoMessage+=' (unsaved)'
80
- else:
81
- InfoMessage+=' (never saved)'
82
- InfoMessage+=f'\n\nCreated : {self.createdDate}'
83
- InfoMessage+=f'\nModified: {self.modifiedDate}'
84
- if self.savedDate: InfoMessage+=f'\nSaved : {self.savedDate}'
85
- InfoMessage+=f'\n\nUser: {self.username}'
86
- InfoMessage+=f'\nPaIRS version: {self.version}'
87
- return InfoMessage
88
-
89
- def save_list_to_file_serialized(l, filename, flagJSON=False):
90
- basename = os.path.splitext(filename)[0]
91
- pickle_data = {}
92
- pickle_counter = 0
93
- info_pickle =[]
94
-
95
- def serialize_element(elem:TABpar, idx_path):
96
- nonlocal pickle_counter
97
- if elem is None:
98
- return None
99
- data = {}
100
- for field in elem.fields:
101
- value = getattr(elem, field)
102
- if isinstance(value, TABpar):
103
- data[field] = serialize_element(value, idx_path + [field])
104
- elif isinstance(value, CompMin) or isinstance(value, MediaPIV):
105
- data[field] = {'__file_ref__': value.outName,
106
- 'varClass': value.__class__.__name__}
107
- if isinstance(value, MediaPIV):
108
- data[field]['stepType']=value.stepType
109
- try:
110
- if value.outName:
111
- with open(value.outName, 'wb') as file:
112
- pickle.dump(value, file)
113
- except Exception as e:
114
- print(f'Error while saving the file {filename}!\n{e}\n')
115
- elif is_non_json_serializable(value):
116
- info=f'Element: {elem.__class__.__name__} --> field: {field} --> value type: {type(value)}'
117
- info_pickle.append(info)
118
- key = f"ref_{pickle_counter}"
119
- pickle_data[key] = value
120
- data[field] = {'__file_ref__': key}
121
- pickle_counter += 1
122
- else:
123
- data[field] = value
124
- data['parClass'] = elem.__class__.__name__
125
- return data
126
-
127
- def serialize_list(lst, idx_path=[]):
128
- if isinstance(lst, list):
129
- return [serialize_list(item, idx_path + [i]) for i, item in enumerate(lst)]
130
- else:
131
- return serialize_element(lst, idx_path)
132
-
133
- serialized_list = serialize_list(l)
134
-
135
- try:
136
- if flagJSON:
137
- with open(filename, 'w') as file:
138
- json.dump(serialized_list, file, indent=2)
139
- else:
140
- with open(filename, 'wb') as file:
141
- pickle.dump(serialized_list, file)
142
- except Exception as e:
143
- print(f'Error while saving the file {filename}!\n{e}\n')
144
-
145
- if pickle_counter:
146
- pri.Info.yellow(f'The following non-json serializable items were found in {filename}:\n'+"\n".join(info_pickle))
147
- pickle_filename = basename+'.pairs_data'
148
- try:
149
- with open(pickle_filename, 'wb') as file:
150
- pickle.dump(pickle_data, file)
151
- except Exception as e:
152
- print(f'Error while saving the file {pickle_filename}!\n{e}\n')
153
-
154
-
155
- def load_list_from_file_serialized(filename):
156
- basename = os.path.basename(filename)
157
- pickle_filename = basename+'.pairs_data'
158
-
159
- serialized_list=None
160
- error=''
161
- try:
162
- with open(filename, 'rb') as file:
163
- first_byte = file.read(1)
164
- if first_byte in [b'{', b'[']:
165
- file.seek(0)
166
- try:
167
- serialized_list=json.load(file)
168
- except Exception as e:
169
- error=e
170
- else:
171
- file.seek(0)
172
- try:
173
- import numpy
174
- serialized_list=pickle.load(file)
175
- except Exception as e:
176
- error=e
177
- except Exception as e:
178
- error=e
179
- if error:
180
- print(f'Error while loading the file {filename}!\n{error}\n')
181
- return serialized_list, str(error)
182
-
183
- error=''
184
- pickle_data = None
185
- if os.path.exists(pickle_filename):
186
- try:
187
- with open(pickle_filename, 'rb') as file:
188
- pickle_data = pickle.load(file)
189
- except Exception as e:
190
- print(f'Error while loading the file {pickle_filename}!\n{e}\n')
191
- error+=str(e)
192
-
193
- info_pickle=[]
194
-
195
- def deserialize_element(data):
196
- if data is None:
197
- return None
198
- try:
199
- cls_name = data.pop('parClass')
200
- except:
201
- pass
202
- cls = globals()[cls_name]
203
- if cls_name=='dataTreePar':
204
- pass
205
- instance:TABpar = cls()
206
- fields = {}
207
- for key, value in data.items():
208
- if isinstance(value, dict) and 'parClass' in value:
209
- fields[key] = deserialize_element(value)
210
- elif isinstance(value, dict) and 'varClass' in value:
211
- filename = value['__file_ref__']
212
- field_cls_name = value['varClass']
213
- field_cls = globals()[field_cls_name]
214
- if field_cls==MediaPIV:
215
- new_instance:MediaPIV=field_cls(value['stepType'])
216
- else:
217
- new_instance:CompMin=field_cls()
218
- if filename:
219
- try:
220
- if os.path.exists(filename):
221
- with open(filename, 'rb') as file:
222
- loaded_instance:CompMin=pickle.load(file)
223
- for f in loaded_instance.fields:
224
- v_loaded=getattr(loaded_instance,f)
225
- if isinstance(v_loaded,TABpar):
226
- v_new:TABpar=getattr(new_instance,f)
227
- v_new.copyfrom(v_loaded)
228
- else:
229
- setattr(new_instance,f,v_loaded)
230
- except Exception as e:
231
- pri.Error.red(f'Error while reading the file {filename} (setting "{key}" field of {cls_name} item)\n{traceback.format_exc()}\n')
232
- fields[key] = new_instance
233
- elif isinstance(value, dict) and '__file_ref__' in value:
234
- ref_key = value['__file_ref__']
235
- if pickle_data:
236
- fields[key] = pickle_data[ref_key]
237
- else:
238
- fields[key] = None
239
- info=f'Element: {cls_name} --> field: {key} --> value type: {type(value)}'
240
- info_pickle.append(info)
241
- None
242
- else:
243
- fields[key] = value
244
- for f,v in fields.items():
245
- if f in instance.fields: setattr(instance,f,v)
246
- #instance.copyfromdiz(fields)
247
- return instance
248
-
249
- def deserialize_list(lst):
250
- if isinstance(lst, list):
251
- return [deserialize_list(item) for item in lst]
252
- else:
253
- return deserialize_element(lst)
254
-
255
- if info_pickle:
256
- pri.Info.red(f'The following non-json serializable items were not found in {filename}:\n'+"\n".join(info_pickle))
257
- l=None
258
- try:
259
- l=deserialize_list(serialized_list)
260
- except Exception as e:
261
- print(f'Error while loading the file {filename}!\n{e}\n{traceback.format_exc()}\n')
262
- error+=str(e)
263
- return l, error
264
-
265
- def is_non_json_serializable(value):
266
- try:
267
- json.dumps(value)
268
- return False
269
- except (TypeError, OverflowError):
270
- return True
271
-
272
-
273
- def save_list_to_file(l,filename):
274
- try:
275
- with open(filename, 'wb') as file:
276
- pickle.dump(l, file)
277
- except Exception as e:
278
- print(f'Error while saving the file {filename}!\n{e}\n')
279
-
280
- def load_list_from_file(filename):
281
- l=None
282
- errorMessage=''
283
- try:
284
- with open(filename, 'rb') as file:
285
- l=pickle.load(file)
286
- except Exception as e:
287
- errorMessage=f'Error while loading the file {filename}!\n{e}\n'
288
- print(errorMessage)
289
- return l, errorMessage
290
-
291
- if FLAG_SERIALIZED:
292
- saveList=save_list_to_file_serialized
293
- loadList=load_list_from_file_serialized
294
- else:
295
- saveList=save_list_to_file
296
- loadList=load_list_from_file
27
+
28
+ class GPApar(TABpar):
29
+ def __init__(self):
30
+ self.setup()
31
+ super().__init__(self.name,'gPaIRS')
32
+ self.unchecked_fields+=[]
33
+
34
+ def setup(self):
35
+ self.name_work, self.username, self.version = identifierName(typeObject='wksp')
36
+ self.outName = ''
37
+ self.createdDate = currentTimeString()
38
+ self.modifiedDate = self.createdDate
39
+ self.savedDate = ''
40
+ self.FlagSaved = False
41
+ self.FlagQueue = True
42
+ self.FlagRunnable = True
43
+
44
+ self.name = 'Workspace'
45
+ self.date = f'Created: {self.createdDate}'
46
+ self.icon = 'workspace.png'
47
+
48
+ self.infoFields=[f for f,_ in self.__dict__.items()]
49
+
50
+ self.Geometry = None
51
+ self.WindowState = None
52
+ self.SplitterSizes = {}
53
+ self.ScrollAreaValues = {}
54
+
55
+ #legacy
56
+ self.FloatGeometry = []
57
+ self.FloatVisible = []
58
+
59
+ self.paletteType = 2 #-1,2=standard, 0=light, 1=dark
60
+ self.fontPixelSize = fontPixelSize
61
+ self.FlagOutDated = 0
62
+ self.currentVersion = __version__
63
+ self.latestVersion = ''
64
+
65
+ self.printTypes = printTypes
66
+ self.NumCores = 0
67
+
68
+ self.stateFields=[f for f,_ in self.__dict__.items() if f not in self.infoFields]
69
+
70
+ def saveBullet(self):
71
+ return '' if self.FlagSaved else '<span style="color: #7A8B8B;"><sup>&#9679;</sup></span>'
72
+
73
+ def InfoMessage(self):
74
+ InfoMessage=f'{self.name}'
75
+ if self.FlagSaved:
76
+ InfoMessage+=f'\nFile location: {self.outName}'
77
+ else:
78
+ if self.savedDate:
79
+ InfoMessage+=' (unsaved)'
80
+ else:
81
+ InfoMessage+=' (never saved)'
82
+ InfoMessage+=f'\n\nCreated : {self.createdDate}'
83
+ InfoMessage+=f'\nModified: {self.modifiedDate}'
84
+ if self.savedDate: InfoMessage+=f'\nSaved : {self.savedDate}'
85
+ InfoMessage+=f'\n\nUser: {self.username}'
86
+ InfoMessage+=f'\nPaIRS version: {self.version}'
87
+ return InfoMessage
88
+
89
+ def save_list_to_file_serialized(l, filename, flagJSON=False):
90
+ basename = os.path.splitext(filename)[0]
91
+ pickle_data = {}
92
+ pickle_counter = 0
93
+ info_pickle =[]
94
+
95
+ def serialize_element(elem:TABpar, idx_path):
96
+ nonlocal pickle_counter
97
+ if elem is None:
98
+ return None
99
+ data = {}
100
+ for field in elem.fields:
101
+ value = getattr(elem, field)
102
+ if isinstance(value, TABpar):
103
+ data[field] = serialize_element(value, idx_path + [field])
104
+ elif isinstance(value, CompMin) or isinstance(value, MediaPIV):
105
+ data[field] = {'__file_ref__': value.outName,
106
+ 'varClass': value.__class__.__name__}
107
+ if isinstance(value, MediaPIV):
108
+ data[field]['stepType']=value.stepType
109
+ try:
110
+ if value.outName:
111
+ with open(value.outName, 'wb') as file:
112
+ pickle.dump(value, file)
113
+ except Exception as e:
114
+ print(f'Error while saving the file {filename}!\n{e}\n')
115
+ elif is_non_json_serializable(value):
116
+ info=f'Element: {elem.__class__.__name__} --> field: {field} --> value type: {type(value)}'
117
+ info_pickle.append(info)
118
+ key = f"ref_{pickle_counter}"
119
+ pickle_data[key] = value
120
+ data[field] = {'__file_ref__': key}
121
+ pickle_counter += 1
122
+ else:
123
+ data[field] = value
124
+ data['parClass'] = elem.__class__.__name__
125
+ return data
126
+
127
+ def serialize_list(lst, idx_path=[]):
128
+ if isinstance(lst, list):
129
+ return [serialize_list(item, idx_path + [i]) for i, item in enumerate(lst)]
130
+ else:
131
+ return serialize_element(lst, idx_path)
132
+
133
+ serialized_list = serialize_list(l)
134
+
135
+ try:
136
+ if flagJSON:
137
+ with open(filename, 'w') as file:
138
+ json.dump(serialized_list, file, indent=2)
139
+ else:
140
+ with open(filename, 'wb') as file:
141
+ pickle.dump(serialized_list, file)
142
+ except Exception as e:
143
+ print(f'Error while saving the file {filename}!\n{e}\n')
144
+
145
+ if pickle_counter:
146
+ pri.IOError.yellow(f'The following non-json serializable items were found in {filename}:\n'+"\n".join(info_pickle))
147
+ pickle_filename = basename+'.pairs_data'
148
+ try:
149
+ with open(pickle_filename, 'wb') as file:
150
+ pickle.dump(pickle_data, file)
151
+ except Exception as e:
152
+ print(f'Error while saving the file {pickle_filename}!\n{e}\n')
153
+
154
+
155
+ def load_list_from_file_serialized(filename):
156
+ basename = os.path.basename(filename)
157
+ pickle_filename = basename+'.pairs_data'
158
+
159
+ serialized_list=None
160
+ error=''
161
+ try:
162
+ with open(filename, 'rb') as file:
163
+ first_byte = file.read(1)
164
+ if first_byte in [b'{', b'[']:
165
+ file.seek(0)
166
+ try:
167
+ serialized_list=json.load(file)
168
+ except Exception as e:
169
+ error=e
170
+ else:
171
+ file.seek(0)
172
+ try:
173
+ import numpy
174
+ serialized_list=pickle.load(file)
175
+ except Exception as e:
176
+ error=e
177
+ except Exception as e:
178
+ error=e
179
+ if error:
180
+ pri.IOError.red(f'Error while loading the file {filename}!\n{error}\n')
181
+ return serialized_list, str(error)
182
+
183
+ error=''
184
+ pickle_data = None
185
+ if os.path.exists(pickle_filename):
186
+ try:
187
+ with open(pickle_filename, 'rb') as file:
188
+ pickle_data = pickle.load(file)
189
+ except Exception as e:
190
+ pri.IOError.red(f'Error while loading the file {pickle_filename}!\n{e}\n')
191
+ error+=str(e)
192
+
193
+ info_pickle=[]
194
+
195
+ def deserialize_element(data):
196
+ if data is None:
197
+ return None
198
+ try:
199
+ cls_name = data.pop('parClass')
200
+ except:
201
+ pass
202
+ cls = globals()[cls_name]
203
+ if cls_name=='dataTreePar':
204
+ pass
205
+ instance:TABpar = cls()
206
+ fields = {}
207
+ for key, value in data.items():
208
+ if isinstance(value, dict) and 'parClass' in value:
209
+ fields[key] = deserialize_element(value)
210
+ elif isinstance(value, dict) and 'varClass' in value:
211
+ filename = value['__file_ref__']
212
+ field_cls_name = value['varClass']
213
+ field_cls = globals()[field_cls_name]
214
+ if field_cls==MediaPIV:
215
+ new_instance:MediaPIV=field_cls(value['stepType'])
216
+ else:
217
+ new_instance:CompMin=field_cls()
218
+ if filename:
219
+ try:
220
+ if os.path.exists(filename):
221
+ with open(filename, 'rb') as file:
222
+ loaded_instance:CompMin=pickle.load(file)
223
+ for f in loaded_instance.fields:
224
+ v_loaded=getattr(loaded_instance,f)
225
+ if isinstance(v_loaded,TABpar):
226
+ v_new:TABpar=getattr(new_instance,f)
227
+ v_new.copyfrom(v_loaded)
228
+ else:
229
+ setattr(new_instance,f,v_loaded)
230
+ except Exception as e:
231
+ pri.IOError.red(f'Error while reading the file {filename} (setting "{key}" field of {cls_name} item)\n{traceback.format_exc()}\n')
232
+ fields[key] = new_instance
233
+ elif isinstance(value, dict) and '__file_ref__' in value:
234
+ ref_key = value['__file_ref__']
235
+ if pickle_data:
236
+ fields[key] = pickle_data[ref_key]
237
+ else:
238
+ fields[key] = None
239
+ info=f'Element: {cls_name} --> field: {key} --> value type: {type(value)}'
240
+ info_pickle.append(info)
241
+ None
242
+ else:
243
+ fields[key] = value
244
+ for f,v in fields.items():
245
+ if f in instance.fields: setattr(instance,f,v)
246
+ #instance.copyfromdiz(fields)
247
+ return instance
248
+
249
+ def deserialize_list(lst):
250
+ if isinstance(lst, list):
251
+ return [deserialize_list(item) for item in lst]
252
+ else:
253
+ return deserialize_element(lst)
254
+
255
+ if info_pickle:
256
+ pri.IOError.red(f'The following non-json serializable items were not found in {filename}:\n'+"\n".join(info_pickle))
257
+ l=None
258
+ try:
259
+ l=deserialize_list(serialized_list)
260
+ except Exception as e:
261
+ pri.IOError.red(f'Error while loading the file {filename}!\n{e}\n{traceback.format_exc()}\n')
262
+ error+=str(e)
263
+ return l, error
264
+
265
+ def is_non_json_serializable(value):
266
+ try:
267
+ json.dumps(value)
268
+ return False
269
+ except (TypeError, OverflowError):
270
+ return True
271
+
272
+
273
+ def save_list_to_file(l,filename):
274
+ try:
275
+ with open(filename, 'wb') as file:
276
+ pickle.dump(l, file)
277
+ except Exception as e:
278
+ print(f'Error while saving the file {filename}!\n{e}\n')
279
+
280
+ def load_list_from_file(filename):
281
+ l=None
282
+ errorMessage=''
283
+ try:
284
+ with open(filename, 'rb') as file:
285
+ l=pickle.load(file)
286
+ except Exception as e:
287
+ errorMessage=f'Error while loading the file {filename}!\n{e}\n'
288
+ pri.IOError.red(errorMessage)
289
+ return l, errorMessage
290
+
291
+ if FLAG_SERIALIZED:
292
+ saveList=save_list_to_file_serialized
293
+ loadList=load_list_from_file_serialized
294
+ else:
295
+ saveList=save_list_to_file
296
+ loadList=load_list_from_file