pymodaq 4.2.3__py3-none-any.whl → 5.0.0__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.

Potentially problematic release.


This version of pymodaq might be problematic. Click here for more details.

Files changed (399) hide show
  1. pymodaq/__init__.py +30 -23
  2. pymodaq/control_modules/daq_move.py +27 -14
  3. pymodaq/control_modules/daq_move_ui.py +33 -16
  4. pymodaq/control_modules/daq_viewer.py +38 -28
  5. pymodaq/control_modules/daq_viewer_ui.py +6 -6
  6. pymodaq/control_modules/mocks.py +1 -1
  7. pymodaq/control_modules/move_utility_classes.py +19 -10
  8. pymodaq/control_modules/utils.py +18 -12
  9. pymodaq/control_modules/viewer_utility_classes.py +13 -4
  10. pymodaq/dashboard.py +166 -118
  11. pymodaq/examples/custom_app.py +13 -16
  12. pymodaq/examples/custom_viewer.py +7 -7
  13. pymodaq/examples/function_plotter.py +13 -12
  14. pymodaq/examples/parameter_ex.py +50 -25
  15. pymodaq/examples/tcp_client.py +1 -1
  16. pymodaq/extensions/__init__.py +1 -1
  17. pymodaq/extensions/bayesian/bayesian_optimisation.py +15 -12
  18. pymodaq/extensions/bayesian/utils.py +10 -10
  19. pymodaq/extensions/console.py +10 -13
  20. pymodaq/extensions/{daq_logger.py → daq_logger/daq_logger.py} +36 -56
  21. pymodaq/{utils/db/db_logger → extensions/daq_logger/db}/db_logger.py +16 -15
  22. pymodaq/{utils/db/db_logger → extensions/daq_logger/db}/db_logger_models.py +2 -0
  23. pymodaq/{utils/h5modules → extensions/daq_logger}/h5logging.py +7 -8
  24. pymodaq/extensions/daq_scan.py +153 -247
  25. pymodaq/extensions/daq_scan_ui.py +11 -9
  26. pymodaq/extensions/h5browser.py +8 -8
  27. pymodaq/extensions/pid/__init__.py +6 -3
  28. pymodaq/extensions/pid/daq_move_PID.py +4 -2
  29. pymodaq/extensions/pid/pid_controller.py +15 -12
  30. pymodaq/extensions/pid/utils.py +10 -5
  31. pymodaq/extensions/utils.py +5 -3
  32. pymodaq/post_treatment/load_and_plot.py +10 -7
  33. pymodaq/resources/preset_default.xml +1 -1
  34. pymodaq/utils/array_manipulation.py +4 -384
  35. pymodaq/utils/calibration_camera.py +12 -9
  36. pymodaq/utils/chrono_timer.py +7 -5
  37. pymodaq/utils/config.py +3 -450
  38. pymodaq/utils/daq_utils.py +6 -664
  39. pymodaq/utils/data.py +9 -2774
  40. pymodaq/utils/exceptions.py +0 -4
  41. pymodaq/utils/gui_utils/__init__.py +8 -8
  42. pymodaq/utils/gui_utils/loader_utils.py +38 -0
  43. pymodaq/utils/gui_utils/utils.py +6 -138
  44. pymodaq/utils/h5modules/__init__.py +0 -4
  45. pymodaq/utils/h5modules/module_saving.py +15 -8
  46. pymodaq/utils/leco/__init__.py +2 -2
  47. pymodaq/utils/leco/daq_move_LECODirector.py +2 -2
  48. pymodaq/utils/leco/daq_xDviewer_LECODirector.py +2 -2
  49. pymodaq/utils/leco/director_utils.py +2 -2
  50. pymodaq/utils/leco/leco_director.py +3 -3
  51. pymodaq/utils/leco/pymodaq_listener.py +2 -2
  52. pymodaq/utils/leco/utils.py +1 -1
  53. pymodaq/utils/logger.py +4 -76
  54. pymodaq/utils/managers/batchscan_manager.py +16 -19
  55. pymodaq/utils/managers/modules_manager.py +10 -7
  56. pymodaq/utils/managers/overshoot_manager.py +3 -5
  57. pymodaq/utils/managers/preset_manager.py +37 -15
  58. pymodaq/utils/managers/preset_manager_utils.py +11 -9
  59. pymodaq/utils/managers/remote_manager.py +12 -10
  60. pymodaq/utils/math_utils.py +4 -572
  61. pymodaq/utils/parameter/__init__.py +4 -11
  62. pymodaq/utils/parameter/utils.py +4 -299
  63. pymodaq/utils/scanner/scan_config.py +1 -1
  64. pymodaq/utils/scanner/scan_factory.py +16 -12
  65. pymodaq/utils/{plotting → scanner}/scan_selector.py +19 -20
  66. pymodaq/utils/scanner/scanner.py +10 -8
  67. pymodaq/utils/scanner/scanners/_1d_scanners.py +8 -5
  68. pymodaq/utils/scanner/scanners/_2d_scanners.py +5 -5
  69. pymodaq/utils/scanner/scanners/sequential.py +8 -8
  70. pymodaq/utils/scanner/scanners/tabular.py +9 -9
  71. pymodaq/utils/scanner/utils.py +6 -4
  72. pymodaq/utils/svg/svg_viewer2D.py +3 -4
  73. pymodaq/utils/tcp_ip/serializer.py +64 -16
  74. pymodaq/utils/tcp_ip/tcp_server_client.py +10 -8
  75. {pymodaq-4.2.3.dist-info → pymodaq-5.0.0.dist-info}/METADATA +5 -3
  76. pymodaq-5.0.0.dist-info/RECORD +123 -0
  77. {pymodaq-4.2.3.dist-info → pymodaq-5.0.0.dist-info}/WHEEL +1 -1
  78. pymodaq/post_treatment/process_to_scalar.py +0 -263
  79. pymodaq/resources/QtDesigner_Ressources/Icon_Library/1d.png +0 -0
  80. pymodaq/resources/QtDesigner_Ressources/Icon_Library/2d.png +0 -0
  81. pymodaq/resources/QtDesigner_Ressources/Icon_Library/3d.png +0 -0
  82. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Add2.png +0 -0
  83. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Add_Step.png +0 -0
  84. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Approve.png +0 -0
  85. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Approve_All.png +0 -0
  86. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Browse_Dir_Path.png +0 -0
  87. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Calculator.png +0 -0
  88. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ChnGroup.png +0 -0
  89. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ChnNum.png +0 -0
  90. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ChnText.png +0 -0
  91. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ChnTime.png +0 -0
  92. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ChnWave.png +0 -0
  93. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Close3.png +0 -0
  94. pymodaq/resources/QtDesigner_Ressources/Icon_Library/CollapseAll.png +0 -0
  95. pymodaq/resources/QtDesigner_Ressources/Icon_Library/CollapseAll_32.png +0 -0
  96. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ColorPicker.png +0 -0
  97. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Contract.png +0 -0
  98. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Create.png +0 -0
  99. pymodaq/resources/QtDesigner_Ressources/Icon_Library/DeleteLayer.png +0 -0
  100. pymodaq/resources/QtDesigner_Ressources/Icon_Library/EditOpen.png +0 -0
  101. pymodaq/resources/QtDesigner_Ressources/Icon_Library/EditRedo.png +0 -0
  102. pymodaq/resources/QtDesigner_Ressources/Icon_Library/EditUndo.png +0 -0
  103. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Ellipse.png +0 -0
  104. pymodaq/resources/QtDesigner_Ressources/Icon_Library/EllipseFilled.png +0 -0
  105. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Error.png +0 -0
  106. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ErrorMessage.png +0 -0
  107. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Error_16.png +0 -0
  108. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Exit.png +0 -0
  109. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Expand.png +0 -0
  110. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ExpandAll.png +0 -0
  111. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ExpandAll_32.png +0 -0
  112. pymodaq/resources/QtDesigner_Ressources/Icon_Library/FFT.png +0 -0
  113. pymodaq/resources/QtDesigner_Ressources/Icon_Library/HLM.ico +0 -0
  114. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Help.png +0 -0
  115. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Help_32.png +0 -0
  116. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Histogram.png +0 -0
  117. pymodaq/resources/QtDesigner_Ressources/Icon_Library/LUT_LookUpTable.png +0 -0
  118. pymodaq/resources/QtDesigner_Ressources/Icon_Library/MagnifyingGlass.png +0 -0
  119. pymodaq/resources/QtDesigner_Ressources/Icon_Library/MagnifyingGlass_24.png +0 -0
  120. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Marker.png +0 -0
  121. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Math.png +0 -0
  122. pymodaq/resources/QtDesigner_Ressources/Icon_Library/MeasurementStudio_32.png +0 -0
  123. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Move.png +0 -0
  124. pymodaq/resources/QtDesigner_Ressources/Icon_Library/MoveDown.png +0 -0
  125. pymodaq/resources/QtDesigner_Ressources/Icon_Library/MoveUp.png +0 -0
  126. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Multiply.png +0 -0
  127. pymodaq/resources/QtDesigner_Ressources/Icon_Library/NewFile.png +0 -0
  128. pymodaq/resources/QtDesigner_Ressources/Icon_Library/NewLayer.png +0 -0
  129. pymodaq/resources/QtDesigner_Ressources/Icon_Library/New_File.png +0 -0
  130. pymodaq/resources/QtDesigner_Ressources/Icon_Library/New_Folder.png +0 -0
  131. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open.png +0 -0
  132. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open_1D.png +0 -0
  133. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open_2D.png +0 -0
  134. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open_File.png +0 -0
  135. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open_File_32.png +0 -0
  136. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Open_sim.png +0 -0
  137. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Options.png +0 -0
  138. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Oscilloscope.png +0 -0
  139. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Oscilloscope_16.png +0 -0
  140. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Pass.png +0 -0
  141. pymodaq/resources/QtDesigner_Ressources/Icon_Library/RGB.png +0 -0
  142. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Rectangle.png +0 -0
  143. pymodaq/resources/QtDesigner_Ressources/Icon_Library/RectangleFilled.png +0 -0
  144. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Redo.png +0 -0
  145. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Refresh.png +0 -0
  146. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Refresh2.png +0 -0
  147. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Refresh_32.png +0 -0
  148. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Region.png +0 -0
  149. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Rendezvous.png +0 -0
  150. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SELECT.png +0 -0
  151. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Save.png +0 -0
  152. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SaveAll.png +0 -0
  153. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SaveAll_32.png +0 -0
  154. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SaveAs.png +0 -0
  155. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SaveAs_32.png +0 -0
  156. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Save_24.png +0 -0
  157. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Save_32.png +0 -0
  158. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Search.png +0 -0
  159. pymodaq/resources/QtDesigner_Ressources/Icon_Library/SelectPolygon.png +0 -0
  160. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Select_24.png +0 -0
  161. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Settings.png +0 -0
  162. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Snap&Save.png +0 -0
  163. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Snapshot.png +0 -0
  164. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Snapshot2.png +0 -0
  165. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Snapshot2_16.png +0 -0
  166. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Snapshot2_32.png +0 -0
  167. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Spreadsheet.png +0 -0
  168. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Statistics.png +0 -0
  169. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Statistics2.png +0 -0
  170. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Status.png +0 -0
  171. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Subtract.png +0 -0
  172. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Vision.png +0 -0
  173. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Volts.png +0 -0
  174. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Wait2.png +0 -0
  175. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Zoom_1_1.png +0 -0
  176. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Zoom_in.png +0 -0
  177. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Zoom_out.png +0 -0
  178. pymodaq/resources/QtDesigner_Ressources/Icon_Library/Zoom_to_Selection.png +0 -0
  179. pymodaq/resources/QtDesigner_Ressources/Icon_Library/abort.png +0 -0
  180. pymodaq/resources/QtDesigner_Ressources/Icon_Library/advanced2.png +0 -0
  181. pymodaq/resources/QtDesigner_Ressources/Icon_Library/autoscale.png +0 -0
  182. pymodaq/resources/QtDesigner_Ressources/Icon_Library/b_icon.png +0 -0
  183. pymodaq/resources/QtDesigner_Ressources/Icon_Library/back.png +0 -0
  184. pymodaq/resources/QtDesigner_Ressources/Icon_Library/bg_icon.png +0 -0
  185. pymodaq/resources/QtDesigner_Ressources/Icon_Library/camera.png +0 -0
  186. pymodaq/resources/QtDesigner_Ressources/Icon_Library/camera_snap.png +0 -0
  187. pymodaq/resources/QtDesigner_Ressources/Icon_Library/cartesian.png +0 -0
  188. pymodaq/resources/QtDesigner_Ressources/Icon_Library/clear2.png +0 -0
  189. pymodaq/resources/QtDesigner_Ressources/Icon_Library/clear_ROI.png +0 -0
  190. pymodaq/resources/QtDesigner_Ressources/Icon_Library/close2.png +0 -0
  191. pymodaq/resources/QtDesigner_Ressources/Icon_Library/cluster2.png +0 -0
  192. pymodaq/resources/QtDesigner_Ressources/Icon_Library/color.png +0 -0
  193. pymodaq/resources/QtDesigner_Ressources/Icon_Library/color2.png +0 -0
  194. pymodaq/resources/QtDesigner_Ressources/Icon_Library/continuous.png +0 -0
  195. pymodaq/resources/QtDesigner_Ressources/Icon_Library/data.png +0 -0
  196. pymodaq/resources/QtDesigner_Ressources/Icon_Library/delay.png +0 -0
  197. pymodaq/resources/QtDesigner_Ressources/Icon_Library/download.png +0 -0
  198. pymodaq/resources/QtDesigner_Ressources/Icon_Library/download2.png +0 -0
  199. pymodaq/resources/QtDesigner_Ressources/Icon_Library/error2.png +0 -0
  200. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ethernet.png +0 -0
  201. pymodaq/resources/QtDesigner_Ressources/Icon_Library/exit2.png +0 -0
  202. pymodaq/resources/QtDesigner_Ressources/Icon_Library/fan.png +0 -0
  203. pymodaq/resources/QtDesigner_Ressources/Icon_Library/filter2.png +0 -0
  204. pymodaq/resources/QtDesigner_Ressources/Icon_Library/g_icon.png +0 -0
  205. pymodaq/resources/QtDesigner_Ressources/Icon_Library/gear2.png +0 -0
  206. pymodaq/resources/QtDesigner_Ressources/Icon_Library/go_to.png +0 -0
  207. pymodaq/resources/QtDesigner_Ressources/Icon_Library/go_to_1.png +0 -0
  208. pymodaq/resources/QtDesigner_Ressources/Icon_Library/go_to_2.png +0 -0
  209. pymodaq/resources/QtDesigner_Ressources/Icon_Library/grab.png +0 -0
  210. pymodaq/resources/QtDesigner_Ressources/Icon_Library/graph.png +0 -0
  211. pymodaq/resources/QtDesigner_Ressources/Icon_Library/greenLight2.png +0 -0
  212. pymodaq/resources/QtDesigner_Ressources/Icon_Library/greenLight2_32.png +0 -0
  213. pymodaq/resources/QtDesigner_Ressources/Icon_Library/green_light.png +0 -0
  214. pymodaq/resources/QtDesigner_Ressources/Icon_Library/grey_icon.png +0 -0
  215. pymodaq/resources/QtDesigner_Ressources/Icon_Library/greyscale.png +0 -0
  216. pymodaq/resources/QtDesigner_Ressources/Icon_Library/help1.png +0 -0
  217. pymodaq/resources/QtDesigner_Ressources/Icon_Library/help1_32.png +0 -0
  218. pymodaq/resources/QtDesigner_Ressources/Icon_Library/home2.png +0 -0
  219. pymodaq/resources/QtDesigner_Ressources/Icon_Library/information2.png +0 -0
  220. pymodaq/resources/QtDesigner_Ressources/Icon_Library/ini.png +0 -0
  221. pymodaq/resources/QtDesigner_Ressources/Icon_Library/integrator.png +0 -0
  222. pymodaq/resources/QtDesigner_Ressources/Icon_Library/joystick.png +0 -0
  223. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_green.png +0 -0
  224. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_green_16.png +0 -0
  225. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_red.png +0 -0
  226. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_red_16.png +0 -0
  227. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_yellow.png +0 -0
  228. pymodaq/resources/QtDesigner_Ressources/Icon_Library/light_yellow_16.png +0 -0
  229. pymodaq/resources/QtDesigner_Ressources/Icon_Library/limiter.png +0 -0
  230. pymodaq/resources/QtDesigner_Ressources/Icon_Library/load_ROI.png +0 -0
  231. pymodaq/resources/QtDesigner_Ressources/Icon_Library/meshPlot.png +0 -0
  232. pymodaq/resources/QtDesigner_Ressources/Icon_Library/meter.png +0 -0
  233. pymodaq/resources/QtDesigner_Ressources/Icon_Library/meter2.png +0 -0
  234. pymodaq/resources/QtDesigner_Ressources/Icon_Library/meter_32.png +0 -0
  235. pymodaq/resources/QtDesigner_Ressources/Icon_Library/move_contour.png +0 -0
  236. pymodaq/resources/QtDesigner_Ressources/Icon_Library/move_straight_line.png +0 -0
  237. pymodaq/resources/QtDesigner_Ressources/Icon_Library/movie.png +0 -0
  238. pymodaq/resources/QtDesigner_Ressources/Icon_Library/multi_point.png +0 -0
  239. pymodaq/resources/QtDesigner_Ressources/Icon_Library/multiplexer.png +0 -0
  240. pymodaq/resources/QtDesigner_Ressources/Icon_Library/new.png +0 -0
  241. pymodaq/resources/QtDesigner_Ressources/Icon_Library/openArrow.png +0 -0
  242. pymodaq/resources/QtDesigner_Ressources/Icon_Library/openTree.png +0 -0
  243. pymodaq/resources/QtDesigner_Ressources/Icon_Library/oscilloscope2.png +0 -0
  244. pymodaq/resources/QtDesigner_Ressources/Icon_Library/oscilloscope3.png +0 -0
  245. pymodaq/resources/QtDesigner_Ressources/Icon_Library/overlay.png +0 -0
  246. pymodaq/resources/QtDesigner_Ressources/Icon_Library/pass2.png +0 -0
  247. pymodaq/resources/QtDesigner_Ressources/Icon_Library/pass2_16.png +0 -0
  248. pymodaq/resources/QtDesigner_Ressources/Icon_Library/pass_32.png +0 -0
  249. pymodaq/resources/QtDesigner_Ressources/Icon_Library/pause.png +0 -0
  250. pymodaq/resources/QtDesigner_Ressources/Icon_Library/permute.png +0 -0
  251. pymodaq/resources/QtDesigner_Ressources/Icon_Library/phase.png +0 -0
  252. pymodaq/resources/QtDesigner_Ressources/Icon_Library/play.png +0 -0
  253. pymodaq/resources/QtDesigner_Ressources/Icon_Library/polar.png +0 -0
  254. pymodaq/resources/QtDesigner_Ressources/Icon_Library/pole_zero.png +0 -0
  255. pymodaq/resources/QtDesigner_Ressources/Icon_Library/powerMeter.png +0 -0
  256. pymodaq/resources/QtDesigner_Ressources/Icon_Library/powerSwitch.png +0 -0
  257. pymodaq/resources/QtDesigner_Ressources/Icon_Library/powerSwitch_16.png +0 -0
  258. pymodaq/resources/QtDesigner_Ressources/Icon_Library/print2.png +0 -0
  259. pymodaq/resources/QtDesigner_Ressources/Icon_Library/print2_32.png +0 -0
  260. pymodaq/resources/QtDesigner_Ressources/Icon_Library/properties.png +0 -0
  261. pymodaq/resources/QtDesigner_Ressources/Icon_Library/r_icon.png +0 -0
  262. pymodaq/resources/QtDesigner_Ressources/Icon_Library/radiocontrolbutton.png +0 -0
  263. pymodaq/resources/QtDesigner_Ressources/Icon_Library/read2.png +0 -0
  264. pymodaq/resources/QtDesigner_Ressources/Icon_Library/red_light.png +0 -0
  265. pymodaq/resources/QtDesigner_Ressources/Icon_Library/remove.png +0 -0
  266. pymodaq/resources/QtDesigner_Ressources/Icon_Library/reset.png +0 -0
  267. pymodaq/resources/QtDesigner_Ressources/Icon_Library/rgb_icon.png +0 -0
  268. pymodaq/resources/QtDesigner_Ressources/Icon_Library/robot.png +0 -0
  269. pymodaq/resources/QtDesigner_Ressources/Icon_Library/rotation2.png +0 -0
  270. pymodaq/resources/QtDesigner_Ressources/Icon_Library/run2.png +0 -0
  271. pymodaq/resources/QtDesigner_Ressources/Icon_Library/run_all.png +0 -0
  272. pymodaq/resources/QtDesigner_Ressources/Icon_Library/saturation.png +0 -0
  273. pymodaq/resources/QtDesigner_Ressources/Icon_Library/saveTree.png +0 -0
  274. pymodaq/resources/QtDesigner_Ressources/Icon_Library/save_ROI.png +0 -0
  275. pymodaq/resources/QtDesigner_Ressources/Icon_Library/scale_horizontally.png +0 -0
  276. pymodaq/resources/QtDesigner_Ressources/Icon_Library/scale_vertically.png +0 -0
  277. pymodaq/resources/QtDesigner_Ressources/Icon_Library/search2.png +0 -0
  278. pymodaq/resources/QtDesigner_Ressources/Icon_Library/select2.png +0 -0
  279. pymodaq/resources/QtDesigner_Ressources/Icon_Library/select_all.png +0 -0
  280. pymodaq/resources/QtDesigner_Ressources/Icon_Library/select_all2.png +0 -0
  281. pymodaq/resources/QtDesigner_Ressources/Icon_Library/select_none.png +0 -0
  282. pymodaq/resources/QtDesigner_Ressources/Icon_Library/sequence.png +0 -0
  283. pymodaq/resources/QtDesigner_Ressources/Icon_Library/sequence2.png +0 -0
  284. pymodaq/resources/QtDesigner_Ressources/Icon_Library/snap.png +0 -0
  285. pymodaq/resources/QtDesigner_Ressources/Icon_Library/sort_ascend.png +0 -0
  286. pymodaq/resources/QtDesigner_Ressources/Icon_Library/spectrumAnalyzer.png +0 -0
  287. pymodaq/resources/QtDesigner_Ressources/Icon_Library/start.png +0 -0
  288. pymodaq/resources/QtDesigner_Ressources/Icon_Library/status_cancelled.png +0 -0
  289. pymodaq/resources/QtDesigner_Ressources/Icon_Library/stop.png +0 -0
  290. pymodaq/resources/QtDesigner_Ressources/Icon_Library/stop2.png +0 -0
  291. pymodaq/resources/QtDesigner_Ressources/Icon_Library/stop3.png +0 -0
  292. pymodaq/resources/QtDesigner_Ressources/Icon_Library/stop_all.png +0 -0
  293. pymodaq/resources/QtDesigner_Ressources/Icon_Library/sum.png +0 -0
  294. pymodaq/resources/QtDesigner_Ressources/Icon_Library/surfacePlot.png +0 -0
  295. pymodaq/resources/QtDesigner_Ressources/Icon_Library/tree.png +0 -0
  296. pymodaq/resources/QtDesigner_Ressources/Icon_Library/updateTree.png +0 -0
  297. pymodaq/resources/QtDesigner_Ressources/Icon_Library/utility2.png +0 -0
  298. pymodaq/resources/QtDesigner_Ressources/Icon_Library/utility_small.png +0 -0
  299. pymodaq/resources/QtDesigner_Ressources/Icon_Library/vector.png +0 -0
  300. pymodaq/resources/QtDesigner_Ressources/Icon_Library/verify.png +0 -0
  301. pymodaq/resources/QtDesigner_Ressources/Icon_Library/video.png +0 -0
  302. pymodaq/resources/QtDesigner_Ressources/Icon_Library/wait.png +0 -0
  303. pymodaq/resources/QtDesigner_Ressources/Icon_Library/waterfallPlot.png +0 -0
  304. pymodaq/resources/QtDesigner_Ressources/Icon_Library/watershed.png +0 -0
  305. pymodaq/resources/QtDesigner_Ressources/Icon_Library/yellow_light.png +0 -0
  306. pymodaq/resources/QtDesigner_Ressources/Icon_Library/zip_file.png +0 -0
  307. pymodaq/resources/QtDesigner_Ressources/Icon_Library/zoomAuto.png +0 -0
  308. pymodaq/resources/QtDesigner_Ressources/Icon_Library/zoomReset.png +0 -0
  309. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources.bat +0 -2
  310. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources.qrc +0 -234
  311. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources_rc.py +0 -127150
  312. pymodaq/resources/QtDesigner_Ressources/icons.svg +0 -142
  313. pymodaq/resources/VERSION +0 -1
  314. pymodaq/resources/config_template.toml +0 -90
  315. pymodaq/resources/triangulation_data.npy +0 -0
  316. pymodaq/utils/abstract/__init__.py +0 -48
  317. pymodaq/utils/db/__init__.py +0 -0
  318. pymodaq/utils/db/db_logger/__init__.py +0 -0
  319. pymodaq/utils/enums.py +0 -76
  320. pymodaq/utils/factory.py +0 -82
  321. pymodaq/utils/gui_utils/custom_app.py +0 -133
  322. pymodaq/utils/gui_utils/dock.py +0 -107
  323. pymodaq/utils/gui_utils/file_io.py +0 -93
  324. pymodaq/utils/gui_utils/layout.py +0 -34
  325. pymodaq/utils/gui_utils/list_picker.py +0 -38
  326. pymodaq/utils/gui_utils/widgets/__init__.py +0 -5
  327. pymodaq/utils/gui_utils/widgets/label.py +0 -24
  328. pymodaq/utils/gui_utils/widgets/lcd.py +0 -111
  329. pymodaq/utils/gui_utils/widgets/push.py +0 -149
  330. pymodaq/utils/gui_utils/widgets/qled.py +0 -62
  331. pymodaq/utils/gui_utils/widgets/spinbox.py +0 -24
  332. pymodaq/utils/gui_utils/widgets/table.py +0 -263
  333. pymodaq/utils/gui_utils/widgets/tree_layout.py +0 -188
  334. pymodaq/utils/gui_utils/widgets/tree_toml.py +0 -102
  335. pymodaq/utils/h5modules/backends.py +0 -1022
  336. pymodaq/utils/h5modules/browsing.py +0 -625
  337. pymodaq/utils/h5modules/data_saving.py +0 -1101
  338. pymodaq/utils/h5modules/exporter.py +0 -119
  339. pymodaq/utils/h5modules/exporters/__init__.py +0 -0
  340. pymodaq/utils/h5modules/exporters/base.py +0 -111
  341. pymodaq/utils/h5modules/exporters/flimj.py +0 -63
  342. pymodaq/utils/h5modules/exporters/hyperspy.py +0 -143
  343. pymodaq/utils/h5modules/saving.py +0 -866
  344. pymodaq/utils/h5modules/utils.py +0 -115
  345. pymodaq/utils/managers/action_manager.py +0 -489
  346. pymodaq/utils/managers/parameter_manager.py +0 -282
  347. pymodaq/utils/managers/roi_manager.py +0 -726
  348. pymodaq/utils/messenger.py +0 -66
  349. pymodaq/utils/parameter/ioxml.py +0 -542
  350. pymodaq/utils/parameter/pymodaq_ptypes/__init__.py +0 -38
  351. pymodaq/utils/parameter/pymodaq_ptypes/bool.py +0 -31
  352. pymodaq/utils/parameter/pymodaq_ptypes/date.py +0 -126
  353. pymodaq/utils/parameter/pymodaq_ptypes/filedir.py +0 -143
  354. pymodaq/utils/parameter/pymodaq_ptypes/itemselect.py +0 -265
  355. pymodaq/utils/parameter/pymodaq_ptypes/led.py +0 -44
  356. pymodaq/utils/parameter/pymodaq_ptypes/list.py +0 -150
  357. pymodaq/utils/parameter/pymodaq_ptypes/numeric.py +0 -18
  358. pymodaq/utils/parameter/pymodaq_ptypes/pixmap.py +0 -175
  359. pymodaq/utils/parameter/pymodaq_ptypes/slide.py +0 -145
  360. pymodaq/utils/parameter/pymodaq_ptypes/table.py +0 -135
  361. pymodaq/utils/parameter/pymodaq_ptypes/tableview.py +0 -149
  362. pymodaq/utils/parameter/pymodaq_ptypes/text.py +0 -142
  363. pymodaq/utils/plotting/__init__.py +0 -0
  364. pymodaq/utils/plotting/data_viewers/__init__.py +0 -10
  365. pymodaq/utils/plotting/data_viewers/base.py +0 -286
  366. pymodaq/utils/plotting/data_viewers/viewer.py +0 -274
  367. pymodaq/utils/plotting/data_viewers/viewer0D.py +0 -298
  368. pymodaq/utils/plotting/data_viewers/viewer1D.py +0 -820
  369. pymodaq/utils/plotting/data_viewers/viewer1Dbasic.py +0 -231
  370. pymodaq/utils/plotting/data_viewers/viewer2D.py +0 -1118
  371. pymodaq/utils/plotting/data_viewers/viewer2D_basic.py +0 -146
  372. pymodaq/utils/plotting/data_viewers/viewerND.py +0 -800
  373. pymodaq/utils/plotting/gant_chart.py +0 -123
  374. pymodaq/utils/plotting/image_viewer.py +0 -97
  375. pymodaq/utils/plotting/items/__init__.py +0 -0
  376. pymodaq/utils/plotting/items/axis_scaled.py +0 -93
  377. pymodaq/utils/plotting/items/crosshair.py +0 -94
  378. pymodaq/utils/plotting/items/image.py +0 -388
  379. pymodaq/utils/plotting/navigator.py +0 -353
  380. pymodaq/utils/plotting/plotter/plotter.py +0 -94
  381. pymodaq/utils/plotting/plotter/plotters/__init__.py +0 -0
  382. pymodaq/utils/plotting/plotter/plotters/matplotlib_plotters.py +0 -134
  383. pymodaq/utils/plotting/plotter/plotters/qt_plotters.py +0 -78
  384. pymodaq/utils/plotting/utils/__init__.py +0 -0
  385. pymodaq/utils/plotting/utils/axes_viewer.py +0 -88
  386. pymodaq/utils/plotting/utils/filter.py +0 -585
  387. pymodaq/utils/plotting/utils/lineout.py +0 -226
  388. pymodaq/utils/plotting/utils/plot_utils.py +0 -579
  389. pymodaq/utils/plotting/utils/signalND.py +0 -1347
  390. pymodaq/utils/plotting/widgets.py +0 -76
  391. pymodaq/utils/qvariant.py +0 -12
  392. pymodaq/utils/slicing.py +0 -63
  393. pymodaq/utils/units.py +0 -216
  394. pymodaq-4.2.3.dist-info/RECORD +0 -438
  395. /pymodaq/{post_treatment/daq_analysis → extensions/daq_logger}/__init__.py +0 -0
  396. /pymodaq/{utils/abstract/logger.py → extensions/daq_logger/abstract.py} +0 -0
  397. /pymodaq/{resources/QtDesigner_Ressources → extensions/daq_logger/db}/__init__.py +0 -0
  398. {pymodaq-4.2.3.dist-info → pymodaq-5.0.0.dist-info}/entry_points.txt +0 -0
  399. {pymodaq-4.2.3.dist-info → pymodaq-5.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,1101 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Created the 21/11/2022
4
-
5
- @author: Sebastien Weber
6
- """
7
- from time import time
8
- from typing import Union, List, Tuple, Iterable
9
- from pathlib import Path
10
-
11
- import numpy as np
12
-
13
- from pymodaq.utils.abstract import ABCMeta, abstract_attribute
14
- from pymodaq.utils.enums import enum_checker
15
- from pymodaq.utils.data import (Axis, DataDim, DataWithAxes, DataToExport, DataDistribution,
16
- DataDimError, squeeze)
17
- from .saving import DataType, H5Saver
18
- from .backends import GROUP, CARRAY, Node, EARRAY, NodeError
19
- from pymodaq.utils.daq_utils import capitalize
20
- from pymodaq.utils.scanner.utils import ScanType
21
-
22
- SPECIAL_GROUP_NAMES = dict(nav_axes='NavAxes')
23
-
24
-
25
- class AxisError(Exception):
26
- pass
27
-
28
-
29
- class DataManagement(metaclass=ABCMeta):
30
- """Base abstract class to be used for all specialized object saving and loading data to/from a h5file
31
-
32
- Attributes
33
- ----------
34
- data_type: DataType
35
- The enum for this type of data, here abstract and should be redefined
36
- """
37
- data_type: DataType = abstract_attribute()
38
- _h5saver: H5Saver = abstract_attribute()
39
-
40
- @classmethod
41
- def _format_node_name(cls, ind: int) -> str:
42
- """ Format the saved node following the data_type attribute and an integer index
43
-
44
- Parameters
45
- ----------
46
- ind: int
47
-
48
- Returns
49
- -------
50
- str: the future name of the node
51
- """
52
- return f'{capitalize(cls.data_type.value)}{ind:02d}'
53
-
54
- def __enter__(self):
55
- return self
56
-
57
- def __exit__(self, exc_type, exc_val, exc_tb):
58
- self.close_file()
59
-
60
- def close_file(self):
61
- self._h5saver.close_file()
62
-
63
- def _get_next_node_name(self, where: Union[str, Node]) -> str:
64
- """Get the formatted next node name given the ones already saved
65
-
66
- Parameters
67
- ----------
68
- where: Union[Node, str]
69
- the path of a given node or the node itself
70
-
71
- Returns
72
- -------
73
- str: the future name of the node
74
- """
75
- return self._format_node_name(self._get_next_data_type_index_in_group(where))
76
-
77
- def get_last_node_name(self, where: Union[str, Node]) -> Union[str, None]:
78
- """Get the last node name among the ones already saved
79
-
80
- Parameters
81
- ----------
82
- where: Union[Node, str]
83
- the path of a given node or the node itself
84
-
85
- Returns
86
- -------
87
- str: the name of the last saved node or None if none saved
88
- """
89
- index = self._get_next_data_type_index_in_group(where) - 1
90
- if index == -1:
91
- return None
92
- else:
93
- return self._format_node_name(index)
94
-
95
- def get_node_from_index(self, where: Union[str, Node], index: int) -> Node:
96
- return self._h5saver.get_node(where, self._format_node_name(index))
97
-
98
- def get_index_from_node_name(self, where: Union[str, Node]):
99
- node = self._h5saver.get_node(where)
100
- try:
101
- index = int(node.name.split(self.data_type.value)[1])
102
- except IndexError:
103
- return None
104
- return index
105
-
106
- def _get_next_data_type_index_in_group(self, where: Union[Node, str]) -> int:
107
- """Check how much node with a given data_type are already present within the GROUP where
108
- Parameters
109
- ----------
110
- where: Union[Node, str]
111
- the path of a given node or the node itself
112
-
113
- Returns
114
- -------
115
- int: the next available integer to index the node name
116
- """
117
- ind = 0
118
- for node in self._h5saver.walk_nodes(where):
119
- if 'data_type' in node.attrs:
120
- if node.attrs['data_type'] == self.data_type.name:
121
- ind += 1
122
- return ind
123
-
124
- def _is_node_of_data_type(self, where: Union[str, Node]) -> bool:
125
- """Check if a given node is of the data_type of the real class implementation
126
-
127
- eg 'axis' for the AxisSaverLoader
128
-
129
- Parameters
130
- ----------
131
- where: Union[Node, str]
132
- the path of a given node or the node itself
133
-
134
- Returns
135
- -------
136
- bool
137
- """
138
- node = self._get_node(where)
139
- return 'data_type' in node.attrs and node.attrs['data_type'] == self.data_type
140
-
141
- def _get_node(self, where: Union[str, Node]) -> Node:
142
- """Utility method to get a node from a node or a string"""
143
- return self._h5saver.get_node(where)
144
-
145
- def _get_nodes(self, where: Union[str, Node]) -> List[Node]:
146
- """Get Nodes hanging from where including where
147
-
148
- Parameters
149
- ----------
150
- where: Union[Node, str]
151
- the path of a given node or the node itself
152
-
153
- Returns
154
- -------
155
- List[Node]
156
- """
157
- node = self._get_node(where)
158
- if isinstance(node, GROUP):
159
- return [child_node for child_node in self._h5saver.walk_nodes(node)]
160
- else:
161
- return [node]
162
-
163
- def _get_nodes_from_data_type(self, where: Union[str, Node]) -> List[Node]:
164
- """Get the node list hanging from a parent and having the same data type as self
165
-
166
- Parameters
167
- ----------
168
- where: Union[Node, str]
169
- the path of a given node
170
-
171
- Returns
172
- -------
173
- list of Nodes
174
- """
175
- node = self._get_node(where)
176
- if isinstance(node, GROUP):
177
- parent_node = node
178
- else:
179
- parent_node = node.parent_node
180
-
181
- nodes = []
182
- for child_node in self._h5saver.walk_nodes(parent_node):
183
- if self._is_node_of_data_type(child_node):
184
- nodes.append(child_node)
185
- return nodes
186
-
187
-
188
- class AxisSaverLoader(DataManagement):
189
- """Specialized Object to save and load Axis object to and from a h5file
190
-
191
- Parameters
192
- ----------
193
- h5saver: H5Saver
194
-
195
- Attributes
196
- ----------
197
- data_type: DataType
198
- The enum for this type of data, here 'axis'
199
- """
200
- data_type = DataType['axis']
201
-
202
- def __init__(self, h5saver: H5Saver):
203
- self._h5saver = h5saver
204
- self.data_type = enum_checker(DataType, self.data_type)
205
-
206
- def add_axis(self, where: Union[Node, str], axis: Axis, enlargeable=False):
207
- """Write Axis info at a given position within a h5 file
208
-
209
- Parameters
210
- ----------
211
- where: Union[Node, str]
212
- the path of a given node or the node itself
213
- axis: Axis
214
- the Axis object to add as a node in the h5file
215
- enlargeable: bool
216
- Specify if the underlying array will be enlargebale
217
- """
218
- array = self._h5saver.add_array(where, self._get_next_node_name(where), self.data_type, title=axis.label,
219
- array_to_save=axis.get_data(), data_dimension=DataDim['Data1D'],
220
- enlargeable=enlargeable,
221
- metadata=dict(size=axis.size, label=axis.label, units=axis.units,
222
- index=axis.index, offset=axis.offset, scaling=axis.scaling,
223
- distribution='uniform' if axis.is_axis_linear() else 'spread',
224
- spread_order=axis.spread_order))
225
- return array
226
-
227
- def load_axis(self, where: Union[Node, str]) -> Axis:
228
- """create an Axis object from the data and metadata at a given node if of data_type: 'axis
229
-
230
- Parameters
231
- ----------
232
- where: Union[Node, str]
233
- the path of a given node or the node itself
234
-
235
- Returns
236
- -------
237
- Axis
238
- """
239
- axis_node = self._get_node(where)
240
- if not self._is_node_of_data_type(axis_node):
241
- raise AxisError(f'Could not create an Axis object from this node: {axis_node}')
242
- return Axis(label=axis_node.attrs['label'], units=axis_node.attrs['units'],
243
- data=squeeze(axis_node.read()), index=axis_node.attrs['index'],
244
- spread_order=axis_node.attrs['spread_order'])
245
-
246
- def get_axes(self, where: Union[Node, str]) -> List[Axis]:
247
- """Return a list of Axis objects from the Axis Nodes hanging from (or among) a given Node
248
-
249
- Parameters
250
- ----------
251
- where: Union[Node, str]
252
- the path of a given node or the node itself
253
-
254
- Returns
255
- -------
256
- List[Axis]: the list of all Axis object
257
- """
258
- axes = []
259
- for node in self._get_nodes_from_data_type(where):
260
- axis = self.load_axis(node)
261
- # if axis.size > 1:
262
- # axes.append(axis)
263
- axes.append(axis)
264
- return axes
265
-
266
-
267
- class DataSaverLoader(DataManagement):
268
- """Specialized Object to save and load DataWithAxes object to and from a h5file
269
-
270
- Parameters
271
- ----------
272
- h5saver: H5Saver or Path or str
273
-
274
- Attributes
275
- ----------
276
- data_type: DataType
277
- The enum for this type of data, here 'data'
278
- """
279
- data_type = DataType['data']
280
-
281
- def __init__(self, h5saver: Union[H5Saver, Path]):
282
- self.data_type = enum_checker(DataType, self.data_type)
283
-
284
- if isinstance(h5saver, Path) or isinstance(h5saver, str):
285
- h5saver_tmp = H5Saver()
286
- h5saver_tmp.init_file(addhoc_file_path=Path(h5saver))
287
- h5saver = h5saver_tmp
288
-
289
- self._h5saver = h5saver
290
- self._axis_saver = AxisSaverLoader(h5saver)
291
- if not isinstance(self, ErrorSaverLoader):
292
- self._error_saver = ErrorSaverLoader(h5saver)
293
-
294
- def isopen(self) -> bool:
295
- """ Get the opened status of the underlying hdf5 file"""
296
- return self._h5saver.isopen()
297
-
298
- def add_data(self, where: Union[Node, str], data: DataWithAxes, save_axes=True, **kwargs):
299
- """Adds Array nodes to a given location adding eventually axes as others nodes and metadata
300
-
301
- Parameters
302
- ----------
303
- where: Union[Node, str]
304
- the path of a given node or the node itself
305
- data: DataWithAxes
306
- save_axes: bool
307
- """
308
-
309
- for ind_data in range(len(data)):
310
- metadata = dict(timestamp=data.timestamp, label=data.labels[ind_data],
311
- source=data.source.name, distribution=data.distribution.name,
312
- origin=data.origin,
313
- nav_indexes=tuple(data.nav_indexes)
314
- if data.nav_indexes is not None else None,)
315
- for name in data.extra_attributes:
316
- metadata[name] = getattr(data, name)
317
- self._h5saver.add_array(where, self._get_next_node_name(where), self.data_type,
318
- title=data.name, array_to_save=data[ind_data],
319
- data_dimension=data.dim.name, metadata=metadata)
320
-
321
- if save_axes:
322
- for axis in data.axes:
323
- self._axis_saver.add_axis(where, axis)
324
-
325
- if data.errors is not None:
326
- self._error_saver.add_data(where, data.errors_as_dwa(), save_axes=False)
327
-
328
- def get_axes(self, where: Union[Node, str]) -> List[Axis]:
329
- """
330
-
331
- Parameters
332
- ----------
333
- where: Union[Node, str]
334
- the path of a given node or the node itself
335
-
336
- Returns
337
- -------
338
-
339
- """
340
- return self._axis_saver.get_axes(where)
341
-
342
- def get_bkg_nodes(self, where: Union[Node, str]):
343
- bkg_nodes = []
344
- for node in self._h5saver.walk_nodes(where):
345
- if 'data_type' in node.attrs and node.attrs['data_type'] == 'bkg':
346
- bkg_nodes.append(node)
347
- return bkg_nodes
348
-
349
- def get_data_arrays(self, where: Union[Node, str], with_bkg=False,
350
- load_all=False) -> List[np.ndarray]:
351
- """
352
-
353
- Parameters
354
- ----------
355
- where: Union[Node, str]
356
- the path of a given node or the node itself
357
- with_bkg: bool
358
- If True try to load background node and return the array with background subtraction
359
- load_all: bool
360
- If True load all similar nodes hanging from a parent
361
-
362
- Returns
363
- -------
364
- list of ndarray
365
- """
366
- where = self._get_node(where)
367
- if with_bkg:
368
- bkg_nodes = []
369
- if with_bkg:
370
- bkg_nodes = self.get_bkg_nodes(where.parent_node)
371
- if len(bkg_nodes) == 0:
372
- with_bkg = False
373
-
374
- if load_all:
375
- getter = self._get_nodes_from_data_type
376
- else:
377
- getter = self._get_nodes
378
-
379
- if with_bkg:
380
- return [squeeze(array.read()-bkg.read(),
381
- squeeze_indexes=self._get_signal_indexes_to_squeeze(array))
382
- for array, bkg in zip(getter(where), bkg_nodes)]
383
- else:
384
- return [squeeze(array.read(),
385
- squeeze_indexes=self._get_signal_indexes_to_squeeze(array))
386
- for array in getter(where)]
387
-
388
- def _get_signal_indexes_to_squeeze(self, array: Union[CARRAY, EARRAY]):
389
- """ Get the tuple of indexes in the array shape that are not navigation and should be
390
- squeezed"""
391
- sig_indexes = []
392
- for ind in range(len(array.attrs['shape'])):
393
- if ind not in array.attrs['nav_indexes'] and array.attrs['shape'][ind] == 1:
394
- sig_indexes.append(ind)
395
- return tuple(sig_indexes)
396
-
397
- def load_data(self, where, with_bkg=False, load_all=False) -> DataWithAxes:
398
- """Return a DataWithAxes object from the Data and Axis Nodes hanging from (or among) a
399
- given Node
400
-
401
- Does not include navigation axes stored elsewhere in the h5file. The node path is stored in
402
- the DatWithAxis using the attribute path
403
-
404
- Parameters
405
- ----------
406
- where: Union[Node, str]
407
- the path of a given node or the node itself
408
- with_bkg: bool
409
- If True try to load background node and return the data with background subtraction
410
- load_all: bool
411
- If True, will load all data hanging from the same parent node
412
-
413
- See Also
414
- --------
415
- load_data
416
- """
417
-
418
- data_node = self._get_node(where)
419
-
420
- if load_all:
421
- parent_node = data_node.parent_node
422
- data_nodes = self._get_nodes_from_data_type(parent_node)
423
- data_node = data_nodes[0]
424
- error_node = data_node
425
- else:
426
- parent_node = data_node.parent_node
427
- if not isinstance(data_node, CARRAY):
428
- return
429
- data_nodes = [data_node]
430
- try:
431
- error_node_index = self.get_index_from_node_name(data_node)
432
- error_node = self._error_saver.get_node_from_index(parent_node, error_node_index)
433
- except NodeError as e:
434
- error_node = None
435
-
436
- if 'axis' in self.data_type.name:
437
- ndarrays = [squeeze(data_node.read()) for data_node in data_nodes]
438
- axes = [Axis(label=data_node.attrs['label'], units=data_node.attrs['units'],
439
- data=np.linspace(0, ndarrays[0].size-1, ndarrays[0].size-1))]
440
- else:
441
- ndarrays = self.get_data_arrays(data_node, with_bkg=with_bkg, load_all=load_all)
442
- axes = self.get_axes(parent_node)
443
- if error_node is not None:
444
- error_arrays = self._error_saver.get_data_arrays(error_node, load_all=load_all)
445
- if len(error_arrays) == 0:
446
- error_arrays = None
447
- else:
448
- error_arrays = None
449
-
450
- extra_attributes = data_node.attrs.to_dict()
451
- for name in ['TITLE', 'CLASS', 'VERSION', 'backend', 'source', 'data_dimension',
452
- 'distribution', 'label', 'origin', 'nav_indexes', 'dtype', 'data_type',
453
- 'subdtype', 'shape', 'size', 'EXTDIM', 'path', 'timestamp']:
454
- extra_attributes.pop(name, None)
455
-
456
- data = DataWithAxes(data_node.attrs['TITLE'],
457
- source=data_node.attrs['source'] if 'source' in data_node.attrs
458
- else 'raw',
459
- dim=data_node.attrs['data_dimension'],
460
- distribution=data_node.attrs['distribution'],
461
- data=ndarrays,
462
- labels=[node.attrs['label'] for node in data_nodes],
463
- origin=data_node.attrs['origin'] if 'origin' in data_node.attrs else '',
464
- nav_indexes=data_node.attrs['nav_indexes'] if 'nav_indexes' in
465
- data_node.attrs else (),
466
- axes=axes,
467
- errors=error_arrays,
468
- path=data_node.path,
469
- **extra_attributes)
470
- data.timestamp = data_node.attrs['timestamp']
471
- return data
472
-
473
-
474
- class BkgSaver(DataSaverLoader):
475
- """Specialized Object to save and load DataWithAxes background object to and from a h5file
476
-
477
- Parameters
478
- ----------
479
- hsaver: H5Saver
480
-
481
- Attributes
482
- ----------
483
- data_type: DataType
484
- The enum for this type of data, here 'bkg'
485
- """
486
- data_type = DataType['bkg']
487
-
488
- def __init__(self, h5saver: H5Saver):
489
- super().__init__(h5saver)
490
-
491
-
492
- class ErrorSaverLoader(DataSaverLoader):
493
- """Specialized Object to save and load DataWithAxes errors bars to and from a h5file
494
-
495
- Parameters
496
- ----------
497
- hsaver: H5Saver
498
-
499
- Attributes
500
- ----------
501
- data_type: DataType
502
- The enum for this type of data, here 'error'
503
- """
504
- data_type = DataType['error']
505
-
506
- def __init__(self, h5saver: H5Saver):
507
- super().__init__(h5saver)
508
-
509
-
510
- class DataEnlargeableSaver(DataSaverLoader):
511
- """ Specialized Object to save and load enlargeable DataWithAxes saved object to and from a
512
- h5file
513
-
514
- Particular case of DataND with a single *nav_indexes* parameter will be appended as chunks
515
- of signal data
516
-
517
- Parameters
518
- ----------
519
- h5saver: H5Saver
520
-
521
- Attributes
522
- ----------
523
- data_type: DataType
524
- The enum for this type of data, here 'data_enlargeable'
525
-
526
- Notes
527
- -----
528
- To be used to save data from a timed logger (DAQViewer continuous saving or DAQLogger extension) or from an
529
- adaptive scan where the final shape is unknown or other module that need this feature
530
- """
531
- data_type = DataType['data_enlargeable']
532
-
533
- def __init__(self, h5saver: Union[H5Saver, Path],
534
- enl_axis_names: Iterable[str] = ('nav axis',),
535
- enl_axis_units: Iterable[str] = ('',)):
536
- super().__init__(h5saver)
537
-
538
- self._n_enl_axes = len(enl_axis_names)
539
- self._enl_axis_names = enl_axis_names
540
- self._enl_axis_units = enl_axis_units
541
-
542
- def _create_data_arrays(self, where: Union[Node, str], data: DataWithAxes, save_axes=True,
543
- add_enl_axes=True):
544
- """ Create enlargeable array to store data
545
-
546
- Parameters
547
- ----------
548
- where: Union[Node, str]
549
- the path of a given node or the node itself
550
- data: DataWithAxes
551
- save_axes: bool
552
- if True, will save signal axes as data nodes
553
- add_enl_axes: bool
554
- if True, will save enlargeable axes as data nodes (depending on the self._enl_axis_names
555
- field)
556
-
557
- Notes
558
- -----
559
- Because data will be saved at a given index in the enlargeable array, related signal axes
560
- will have their index increased by 1)
561
- """
562
-
563
- if self.get_last_node_name(where) is None:
564
- for ind_data in range(len(data)):
565
- nav_indexes = list(data.nav_indexes)
566
- nav_indexes = ([0] +
567
- list(np.array(nav_indexes, dtype=int) + 1))
568
-
569
- self._h5saver.add_array(where, self._get_next_node_name(where), self.data_type,
570
- title=data.name,
571
- array_to_save=data[ind_data],
572
- data_shape=data[ind_data].shape,
573
- array_type=data[ind_data].dtype,
574
- enlargeable=True,
575
- data_dimension=data.dim.name,
576
- metadata=dict(timestamp=data.timestamp,
577
- label=data.labels[ind_data],
578
- source=data.source.name,
579
- distribution='spread',
580
- origin=data.origin,
581
- nav_indexes=tuple(nav_indexes)))
582
- if add_enl_axes:
583
- for ind_enl_axis in range(self._n_enl_axes):
584
- self._axis_saver.add_axis(where,
585
- Axis(self._enl_axis_names[ind_enl_axis],
586
- self._enl_axis_units[ind_enl_axis],
587
- data=np.array([0., 1.]),
588
- index=0, spread_order=ind_enl_axis),
589
- enlargeable=True)
590
- if save_axes:
591
- for axis in data.axes:
592
- axis = axis.copy()
593
- axis.index += 1 # because of enlargeable data will have an extra shape
594
- self._axis_saver.add_axis(where, axis)
595
-
596
- def add_data(self, where: Union[Node, str], data: DataWithAxes,
597
- axis_values: Iterable[float] = None):
598
- """ Append data to an enlargeable array node
599
-
600
- Data of dim (0, 1 or 2) will be just appended to the enlargeable array.
601
-
602
- Uniform DataND with one navigation axis of length (Lnav) will be considered as a collection
603
- of Lnav signal data of dim (0, 1 or 2) and will therefore be appended as Lnav signal data
604
-
605
- Parameters
606
- ----------
607
- where: Union[Node, str]
608
- the path of a given node or the node itself
609
- data: DataWithAxes
610
- axis_values: optional, list of floats
611
- the new spread axis values added to the data
612
- if None the axes are not added to the h5 file
613
-
614
-
615
- """
616
- add_enl_axes = axis_values is not None
617
-
618
- if self.get_last_node_name(where) is None:
619
- if len(data.nav_indexes) == 0:
620
- data_init = data
621
- else:
622
- raise DataDimError('It is not possible to append DataND')
623
- self._create_data_arrays(where, data_init, save_axes=True, add_enl_axes=add_enl_axes)
624
-
625
- for ind_data in range(len(data)):
626
- array: EARRAY = self.get_node_from_index(where, ind_data)
627
- array.append(data[ind_data])
628
- if add_enl_axes and axis_values is not None:
629
- for ind_axis in range(self._n_enl_axes):
630
- axis_array: EARRAY = self._axis_saver.get_node_from_index(where, ind_axis)
631
- axis_array.append(np.array([axis_values[ind_axis]]))
632
- axis_array.attrs['size'] += 1
633
-
634
-
635
- class DataExtendedSaver(DataSaverLoader):
636
- """Specialized Object to save and load DataWithAxes saved object to and from a h5file in extended arrays
637
-
638
- Parameters
639
- ----------
640
- h5saver: H5Saver
641
- extended_shape: Tuple[int]
642
- the extra shape compared to the data the h5array will have
643
-
644
- Attributes
645
- ----------
646
- data_type: DataType
647
- The enum for this type of data, here 'data'
648
- """
649
- data_type = DataType['data']
650
-
651
- def __init__(self, h5saver: H5Saver, extended_shape: Tuple[int]):
652
- super().__init__(h5saver)
653
- self.extended_shape = extended_shape
654
-
655
- def _create_data_arrays(self, where: Union[Node, str], data: DataWithAxes, save_axes=True,
656
- distribution=DataDistribution['uniform']):
657
- """ Create array with extra dimensions (from scan) to store data
658
-
659
- Parameters
660
- ----------
661
- where: Union[Node, str]
662
- the path of a given node or the node itself
663
- data: DataWithAxes
664
- save_axes: bool
665
-
666
- Notes
667
- -----
668
- Because data will be saved at a given index in the "scan" array, related axes will have their index
669
- increased by the length of the scan dim (1 for scan1D, 2 for scan2D, ...)
670
- """
671
- if self.get_last_node_name(where) is None:
672
- for ind_data in range(len(data)):
673
- nav_indexes = list(data.nav_indexes)
674
- nav_indexes = [ind for ind in range(len(self.extended_shape))] +\
675
- list(np.array(nav_indexes, dtype=int) + len(self.extended_shape))
676
-
677
- self._h5saver.add_array(where, self._get_next_node_name(where), self.data_type, title=data.name,
678
- data_shape=data[ind_data].shape,
679
- array_type=data[ind_data].dtype,
680
- scan_shape=self.extended_shape,
681
- add_scan_dim=True,
682
- data_dimension=data.dim.name,
683
- metadata=dict(timestamp=data.timestamp, label=data.labels[ind_data],
684
- source=data.source.name, distribution=distribution.name,
685
- origin=data.origin,
686
- nav_indexes=tuple(nav_indexes)))
687
-
688
- if save_axes:
689
- for axis in data.axes:
690
- axis.index += len(self.extended_shape)
691
- # because there will be len(self.extended_shape) extra navigation axes
692
- self._axis_saver.add_axis(where, axis)
693
-
694
- def add_data(self, where: Union[Node, str], data: DataWithAxes, indexes: List[int],
695
- distribution=DataDistribution['uniform']):
696
- """Adds given DataWithAxes at a location within the initialized h5 array
697
-
698
- Parameters
699
- ----------
700
- where: Union[Node, str]
701
- the path of a given node or the node itself
702
- data: DataWithAxes
703
- indexes: Iterable[int]
704
- indexes where to save data in the init h5array (should have the same length as extended_shape and with values
705
- coherent with this shape
706
- """
707
- if len(indexes) != len(self.extended_shape):
708
- raise IndexError(f'Cannot put data into the h5array with extended indexes {indexes}')
709
- for ind in range(len(indexes)):
710
- if indexes[ind] > self.extended_shape[ind]:
711
- raise IndexError(f'Indexes cannot be higher than the array shape')
712
-
713
- if self.get_last_node_name(where) is None:
714
- self._create_data_arrays(where, data, save_axes=True, distribution=distribution)
715
-
716
- for ind_data in range(len(data)):
717
- #todo check that getting with index is safe...
718
- array: CARRAY = self.get_node_from_index(where, ind_data)
719
- array[tuple(indexes)] = data[ind_data]
720
- # maybe use array.__setitem__(indexes, data[ind_data]) if it's not working
721
-
722
-
723
- class DataToExportSaver:
724
- """Object used to save DataToExport object into a h5file following the PyMoDAQ convention
725
-
726
- Parameters
727
- ----------
728
- h5saver: H5Saver
729
-
730
- """
731
- def __init__(self, h5saver: Union[H5Saver, Path, str]):
732
- if isinstance(h5saver, Path) or isinstance(h5saver, str):
733
- h5saver_tmp = H5Saver()
734
- h5saver_tmp.init_file(addhoc_file_path=Path(h5saver))
735
- h5saver = h5saver_tmp
736
-
737
- self._h5saver = h5saver
738
- self._data_saver = DataSaverLoader(h5saver)
739
- self._bkg_saver = BkgSaver(h5saver)
740
-
741
- def _get_node(self, where: Union[Node, str]) -> Node:
742
- return self._h5saver.get_node(where)
743
-
744
- def close(self):
745
- self._h5saver.close()
746
-
747
- def close_file(self):
748
- self._h5saver.close_file()
749
-
750
- def __enter__(self):
751
- return self
752
-
753
- def __exit__(self, exc_type, exc_val, exc_tb):
754
- self.close_file()
755
-
756
- def isopen(self) -> bool:
757
- """ Get the opened status of the underlying hdf5 file"""
758
- return self._h5saver.isopen()
759
-
760
- @staticmethod
761
- def channel_formatter(ind: int):
762
- """All DataWithAxes included in the DataToExport will be saved into a channel group indexed
763
- and formatted as below"""
764
- return f'CH{ind:02d}'
765
-
766
- def add_data(self, where: Union[Node, str], data: DataToExport, settings_as_xml='',
767
- metadata=None, **kwargs):
768
- """
769
-
770
- Parameters
771
- ----------
772
- where: Union[Node, str]
773
- the path of a given node or the node itself
774
- data: DataToExport
775
- settings_as_xml: str
776
- The settings parameter as an XML string
777
- metadata: dict
778
- all extra metadata to be saved in the group node where data will be saved
779
-
780
- """
781
- if metadata is None:
782
- metadata = {}
783
- dims = data.get_dim_presents()
784
- for dim in dims:
785
- dim_group = self._h5saver.get_set_group(where, dim)
786
- for ind, dwa in enumerate(data.get_data_from_dim(dim)):
787
- # dwa: DataWithAxes filtered by dim
788
- dwa_group = self._h5saver.get_set_group(dim_group, self.channel_formatter(ind),
789
- dwa.name)
790
- # dwa_group = self._h5saver.add_ch_group(dim_group, dwa.name)
791
- self._data_saver.add_data(dwa_group, dwa, **kwargs)
792
-
793
- def add_bkg(self, where: Union[Node, str], data: DataToExport):
794
- dims = data.get_dim_presents()
795
- for dim in dims:
796
- dim_group = self._h5saver.get_set_group(where, dim)
797
- for ind, dwa in enumerate(data.get_data_from_dim(dim)):
798
- # dwa: DataWithAxes filtered by dim
799
- dwa_group = self._h5saver.get_set_group(dim_group,
800
- self.channel_formatter(ind), dwa.name)
801
- # dwa_group = self._get_node_from_title(dim_group, dwa.name)
802
- if dwa_group is not None:
803
- self._bkg_saver.add_data(dwa_group, dwa, save_axes=False)
804
-
805
- def add_error(self, where: Union[Node, str], data: DataToExport):
806
- dims = data.get_dim_presents()
807
- for dim in dims:
808
- dim_group = self._h5saver.get_set_group(where, dim)
809
- for ind, dwa in enumerate(data.get_data_from_dim(dim)):
810
- # dwa: DataWithAxes filtered by dim
811
- dwa_group = self._h5saver.get_set_group(dim_group,
812
- self.channel_formatter(ind), dwa.name)
813
- # dwa_group = self._get_node_from_title(dim_group, dwa.name)
814
- if dwa_group is not None:
815
- self._bkg_saver.add_data(dwa_group, dwa, save_axes=False)
816
-
817
-
818
- class DataToExportEnlargeableSaver(DataToExportSaver):
819
- """Generic object to save DataToExport objects in an enlargeable h5 array
820
-
821
- The next enlarged value should be specified in the add_data method
822
-
823
- Parameters
824
- ----------
825
- h5saver: H5Saver
826
- enl_axis_names: Iterable[str]
827
- The names of the enlargeable axis, default ['nav_axis']
828
- enl_axis_units: Iterable[str]
829
- The names of the enlargeable axis, default ['']
830
- axis_name: str, deprecated use enl_axis_names
831
- the name of the enlarged axis array
832
- axis_units: str, deprecated use enl_axis_units
833
- the units of the enlarged axis array
834
- """
835
- def __init__(self, h5saver: H5Saver,
836
- enl_axis_names: Iterable[str] = None,
837
- enl_axis_units: Iterable[str] = None,
838
- axis_name: str = 'nav axis', axis_units: str = ''):
839
-
840
- super().__init__(h5saver)
841
- if enl_axis_names is None: # for backcompatibility
842
- enl_axis_names = (axis_name,)
843
- if enl_axis_units is None: # for backcompatibilitu
844
- enl_axis_units = (axis_units,)
845
-
846
- if len(enl_axis_names) != len(enl_axis_units):
847
- raise ValueError('Both enl_axis_names and enl_axis_units should have the same length')
848
-
849
- self._enl_axis_names = enl_axis_names
850
- self._enl_axis_units = enl_axis_units
851
- self._n_enl = len(enl_axis_names)
852
-
853
- self._data_saver = DataEnlargeableSaver(h5saver)
854
- self._nav_axis_saver = AxisSaverLoader(h5saver)
855
-
856
- def add_data(self, where: Union[Node, str], data: DataToExport,
857
- axis_values: List[Union[float, np.ndarray]] = None,
858
- axis_value: Union[float, np.ndarray] = None,
859
- settings_as_xml='', metadata=None,
860
- ):
861
- """
862
-
863
- Parameters
864
- ----------
865
- where: Union[Node, str]
866
- the path of a given node or the node itself
867
- data: DataToExport
868
- The data to be saved into an enlargeable array
869
- axis_values: iterable float or np.ndarray
870
- The next value (or values) of the enlarged axis
871
- axis_value: float or np.ndarray #deprecated in 4.2.0, use axis_values
872
- The next value (or values) of the enlarged axis
873
- settings_as_xml: str
874
- The settings parameter as an XML string
875
- metadata: dict
876
- all extra metadata to be saved in the group node where data will be saved
877
- """
878
-
879
- if axis_values is None and axis_value is not None:
880
- axis_values = [axis_value]
881
-
882
- super().add_data(where, data, settings_as_xml, metadata)
883
- # a parent navigation group (same for all data nodes)
884
-
885
- where = self._get_node(where)
886
- nav_group = self._h5saver.get_set_group(where, SPECIAL_GROUP_NAMES['nav_axes'])
887
- if self._nav_axis_saver.get_last_node_name(nav_group) is None:
888
- for ind in range(self._n_enl):
889
- axis = Axis(label=self._enl_axis_names[ind],
890
- units=self._enl_axis_units[ind], data=np.array([0., 1.]),
891
- index=0, spread_order=ind)
892
- axis_array = self._nav_axis_saver.add_axis(nav_group, axis, enlargeable=True)
893
- axis_array.attrs['size'] = 0
894
-
895
- for ind in range(self._n_enl):
896
- axis_array: EARRAY = self._nav_axis_saver.get_node_from_index(nav_group, ind)
897
- axis_array.append(squeeze(np.array([axis_values[ind]])),
898
- expand=False)
899
- axis_array.attrs['size'] += 1
900
-
901
-
902
- class DataToExportTimedSaver(DataToExportEnlargeableSaver):
903
- """Specialized DataToExportEnlargeableSaver to save data as a function of a time axis
904
-
905
- Only one element ca be added at a time, the time axis value are enlarged using the data to be
906
- added timestamp
907
-
908
- Notes
909
- -----
910
- This object is made for continuous saving mode of DAQViewer and logging to h5file for DAQLogger
911
- """
912
- def __init__(self, h5saver: H5Saver):
913
- super().__init__(h5saver, enl_axis_names=('time',), enl_axis_units=('s',))
914
-
915
- def add_data(self, where: Union[Node, str], data: DataToExport, settings_as_xml='',
916
- metadata=None, **kwargs):
917
- super().add_data(where, data, axis_values=[data.timestamp], settings_as_xml=settings_as_xml,
918
- metadata=metadata)
919
-
920
-
921
- class DataToExportExtendedSaver(DataToExportSaver):
922
- """Object to save DataToExport at given indexes within arrays including extended shape
923
-
924
- Mostly used for data generated from the DAQScan
925
-
926
- Parameters
927
- ----------
928
- h5saver: H5Saver
929
- extended_shape: Tuple[int]
930
- the extra shape compared to the data the h5array will have
931
- """
932
-
933
- def __init__(self, h5saver: H5Saver, extended_shape: Tuple[int]):
934
- super().__init__(h5saver)
935
- self._data_saver = DataExtendedSaver(h5saver, extended_shape)
936
- self._nav_axis_saver = AxisSaverLoader(h5saver)
937
-
938
- def add_nav_axes(self, where: Union[Node, str], axes: List[Axis]):
939
- """Used to add navigation axes related to the extended array
940
-
941
- Notes
942
- -----
943
- For instance the scan axes in the DAQScan
944
- """
945
- where = self._get_node(where)
946
- nav_group = self._h5saver.get_set_group(where, SPECIAL_GROUP_NAMES['nav_axes'])
947
- if self._nav_axis_saver.get_last_node_name(nav_group) is None:
948
- for axis in axes:
949
- self._nav_axis_saver.add_axis(nav_group, axis)
950
-
951
- def add_data(self, where: Union[Node, str], data: DataToExport, indexes: Iterable[int],
952
- distribution=DataDistribution['uniform'],
953
- settings_as_xml='', metadata={}):
954
- """
955
-
956
- Parameters
957
- ----------
958
- where: Union[Node, str]
959
- the path of a given node or the node itself
960
- data: DataToExport
961
- indexes: List[int]
962
- indexes where to save data in the init h5array (should have the same length as
963
- extended_shape and with values coherent with this shape
964
- settings_as_xml: str
965
- The settings parameter as an XML string
966
- metadata: dict
967
- all extra metadata to be saved in the group node where data will be saved
968
-
969
- """
970
- dims = data.get_dim_presents()
971
- for dim in dims:
972
- dim_group = self._h5saver.get_set_group(where, dim)
973
- for ind, dwa in enumerate(data.get_data_from_dim(dim)):
974
- # dwa: DataWithAxes filtered by dim
975
- dwa_group = self._h5saver.get_set_group(dim_group,
976
- self.channel_formatter(ind), dwa.name)
977
- self._data_saver.add_data(dwa_group, dwa, indexes=indexes,
978
- distribution=distribution)
979
-
980
-
981
- class DataLoader:
982
- """Specialized Object to load DataWithAxes object from a h5file
983
-
984
- On the contrary to DataSaverLoader, does include navigation axes stored elsewhere in the h5file
985
- (for instance if saved from the DAQ_Scan)
986
-
987
- Parameters
988
- ----------
989
- h5saver: H5Saver
990
- """
991
-
992
- def __init__(self, h5saver: Union[H5Saver, Path]):
993
- self._axis_loader: AxisSaverLoader = None
994
- self._data_loader: DataSaverLoader = None
995
-
996
- if isinstance(h5saver, Path) or isinstance(h5saver, str):
997
- h5saver_tmp = H5Saver()
998
- h5saver_tmp.init_file(addhoc_file_path=Path(h5saver))
999
- h5saver = h5saver_tmp
1000
-
1001
- self.h5saver = h5saver
1002
-
1003
- @property
1004
- def h5saver(self):
1005
- return self._h5saver
1006
-
1007
- def __enter__(self):
1008
- return self
1009
-
1010
- def __exit__(self, exc_type, exc_val, exc_tb):
1011
- self.close_file()
1012
-
1013
- def close_file(self):
1014
- self._h5saver.close_file()
1015
-
1016
- def walk_nodes(self, where: Union[str, Node] = '/'):
1017
- """Return a Node generator iterating over the h5file content"""
1018
- return self.h5saver.walk_nodes(where)
1019
-
1020
- @h5saver.setter
1021
- def h5saver(self, h5saver: H5Saver):
1022
- self._h5saver = h5saver
1023
- self._axis_loader = AxisSaverLoader(h5saver)
1024
- self._data_loader = DataSaverLoader(h5saver)
1025
-
1026
- def get_node(self, where: Union[Node, str], name: str = None) -> Node:
1027
- """ Convenience method to get node"""
1028
- return self.h5saver.get_node(where, name)
1029
-
1030
- def get_nav_group(self, where: Union[Node, str]) -> Union[Node, None]:
1031
- """
1032
-
1033
- Parameters
1034
- ----------
1035
- where: Union[Node, str]
1036
- the path of a given node or the node itself
1037
-
1038
- Returns
1039
- -------
1040
- GROUP: returns the group named SPECIAL_GROUP_NAMES['nav_axes'] holding all NavAxis for
1041
- those data
1042
-
1043
- See Also
1044
- --------
1045
- SPECIAL_GROUP_NAMES
1046
- """
1047
- node = self._h5saver.get_node(where)
1048
- while node is not None: # means we reached the root level
1049
- if isinstance(node, GROUP):
1050
- if self._h5saver.is_node_in_group(node, SPECIAL_GROUP_NAMES['nav_axes']):
1051
- return self._h5saver.get_node(node, SPECIAL_GROUP_NAMES['nav_axes'])
1052
- node = node.parent_node
1053
-
1054
- def load_data(self, where: Union[Node, str], with_bkg=False, load_all=False) -> DataWithAxes:
1055
- """Load data from a node (or channel node)
1056
-
1057
- Loaded data contains also nav_axes if any and with optional background subtraction
1058
-
1059
- Parameters
1060
- ----------
1061
- where: Union[Node, str]
1062
- the path of a given node or the node itself
1063
- with_bkg: bool
1064
- If True will attempt to substract a background data node before loading
1065
- load_all: bool
1066
- If True, will load all data hanging from the same parent node
1067
-
1068
- Returns
1069
- -------
1070
-
1071
- """
1072
- node_data_type = DataType[self._h5saver.get_node(where).attrs['data_type']]
1073
- self._data_loader.data_type = node_data_type
1074
- data = self._data_loader.load_data(where, with_bkg=with_bkg, load_all=load_all)
1075
- if 'axis' not in node_data_type.name:
1076
- nav_group = self.get_nav_group(where)
1077
- if nav_group is not None:
1078
- nav_axes = self._axis_loader.get_axes(nav_group)
1079
- axes = data.axes[:]
1080
- axes.extend(nav_axes)
1081
- data.axes = axes
1082
- data.get_dim_from_data_axes()
1083
- data.create_missing_axes()
1084
- return data
1085
-
1086
- def load_all(self, where: GROUP, data: DataToExport, with_bkg=False) -> DataToExport:
1087
-
1088
- where = self._h5saver.get_node(where)
1089
- children_dict = where.children()
1090
- data_list = []
1091
- for child in children_dict:
1092
- if isinstance(children_dict[child], GROUP):
1093
- self.load_all(children_dict[child], data, with_bkg=with_bkg)
1094
- elif ('data_type' in children_dict[child].attrs and 'data' in
1095
- children_dict[child].attrs['data_type']):
1096
-
1097
- data_list.append(self.load_data(children_dict[child].path,
1098
- with_bkg=with_bkg, load_all=True))
1099
- break
1100
- data_tmp = DataToExport(name=where.name, data=data_list)
1101
- data.append(data_tmp)