pymodaq 3.6.13__py3-none-any.whl → 4.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.

Potentially problematic release.


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

Files changed (233) hide show
  1. pymodaq/__init__.py +13 -6
  2. pymodaq/control_modules/__init__.py +0 -7
  3. pymodaq/control_modules/daq_move.py +965 -2
  4. pymodaq/control_modules/daq_move_ui.py +319 -0
  5. pymodaq/control_modules/daq_viewer.py +1573 -3
  6. pymodaq/control_modules/daq_viewer_ui.py +393 -0
  7. pymodaq/control_modules/mocks.py +51 -0
  8. pymodaq/control_modules/move_utility_classes.py +709 -8
  9. pymodaq/control_modules/utils.py +256 -0
  10. pymodaq/control_modules/viewer_utility_classes.py +663 -6
  11. pymodaq/daq_utils.py +89 -0
  12. pymodaq/dashboard.py +91 -72
  13. pymodaq/examples/custom_app.py +12 -11
  14. pymodaq/examples/custom_viewer.py +10 -10
  15. pymodaq/examples/function_plotter.py +16 -13
  16. pymodaq/examples/nonlinearscanner.py +8 -6
  17. pymodaq/examples/parameter_ex.py +7 -7
  18. pymodaq/examples/preset_MockCamera.xml +1 -0
  19. pymodaq/extensions/__init__.py +16 -0
  20. pymodaq/extensions/console.py +76 -0
  21. pymodaq/{daq_logger.py → extensions/daq_logger.py} +115 -65
  22. pymodaq/extensions/daq_scan.py +1339 -0
  23. pymodaq/extensions/daq_scan_ui.py +240 -0
  24. pymodaq/extensions/h5browser.py +23 -0
  25. pymodaq/{pid → extensions/pid}/__init__.py +4 -2
  26. pymodaq/{pid → extensions/pid}/daq_move_PID.py +2 -2
  27. pymodaq/{pid → extensions/pid}/pid_controller.py +48 -36
  28. pymodaq/{pid → extensions/pid}/utils.py +52 -6
  29. pymodaq/extensions/utils.py +40 -0
  30. pymodaq/post_treatment/__init__.py +6 -0
  31. pymodaq/{daq_analysis → post_treatment/daq_analysis}/daq_analysis_main.py +17 -17
  32. pymodaq/{daq_measurement → post_treatment/daq_measurement}/daq_measurement_main.py +8 -14
  33. pymodaq/post_treatment/load_and_plot.py +219 -0
  34. pymodaq/post_treatment/process_to_scalar.py +263 -0
  35. pymodaq/resources/QtDesigner_Ressources/Icon_Library/run_all.png +0 -0
  36. pymodaq/resources/QtDesigner_Ressources/Icon_Library/stop_all.png +0 -0
  37. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources.bat +1 -1
  38. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources.qrc +1 -0
  39. pymodaq/resources/QtDesigner_Ressources/QtDesigner_ressources_rc.py +109784 -109173
  40. pymodaq/resources/QtDesigner_Ressources/icons.svg +142 -0
  41. pymodaq/resources/VERSION +1 -1
  42. pymodaq/resources/config_template.toml +32 -13
  43. pymodaq/resources/preset_default.xml +1 -1
  44. pymodaq/{daq_utils → utils}/Tuto innosetup/script_full_setup.iss +1 -1
  45. pymodaq/utils/__init__.py +0 -29
  46. pymodaq/utils/abstract/__init__.py +48 -0
  47. pymodaq/{daq_utils → utils}/abstract/logger.py +7 -3
  48. pymodaq/utils/array_manipulation.py +379 -8
  49. pymodaq/{daq_utils → utils}/calibration_camera.py +6 -6
  50. pymodaq/{daq_utils → utils}/chrono_timer.py +1 -1
  51. pymodaq/utils/config.py +448 -0
  52. pymodaq/utils/conftests.py +5 -0
  53. pymodaq/utils/daq_utils.py +828 -8
  54. pymodaq/utils/data.py +1873 -7
  55. pymodaq/{daq_utils → utils}/db/db_logger/db_logger.py +86 -47
  56. pymodaq/{daq_utils → utils}/db/db_logger/db_logger_models.py +31 -10
  57. pymodaq/{daq_utils → utils}/enums.py +12 -7
  58. pymodaq/utils/exceptions.py +37 -0
  59. pymodaq/utils/factory.py +82 -0
  60. pymodaq/{daq_utils → utils}/gui_utils/__init__.py +1 -1
  61. pymodaq/utils/gui_utils/custom_app.py +129 -0
  62. pymodaq/utils/gui_utils/file_io.py +66 -0
  63. pymodaq/{daq_utils → utils}/gui_utils/layout.py +2 -2
  64. pymodaq/{daq_utils → utils}/gui_utils/utils.py +13 -3
  65. pymodaq/{daq_utils → utils}/gui_utils/widgets/__init__.py +2 -2
  66. pymodaq/utils/gui_utils/widgets/label.py +24 -0
  67. pymodaq/{daq_utils → utils}/gui_utils/widgets/lcd.py +12 -7
  68. pymodaq/{daq_utils → utils}/gui_utils/widgets/push.py +66 -2
  69. pymodaq/{daq_utils → utils}/gui_utils/widgets/qled.py +6 -4
  70. pymodaq/utils/gui_utils/widgets/spinbox.py +24 -0
  71. pymodaq/{daq_utils → utils}/gui_utils/widgets/table.py +2 -2
  72. pymodaq/utils/h5modules/__init__.py +1 -0
  73. pymodaq/{daq_utils/h5backend.py → utils/h5modules/backends.py} +200 -112
  74. pymodaq/utils/h5modules/browsing.py +683 -0
  75. pymodaq/utils/h5modules/data_saving.py +839 -0
  76. pymodaq/utils/h5modules/h5logging.py +110 -0
  77. pymodaq/utils/h5modules/module_saving.py +350 -0
  78. pymodaq/utils/h5modules/saving.py +914 -0
  79. pymodaq/utils/h5modules/utils.py +85 -0
  80. pymodaq/utils/logger.py +64 -6
  81. pymodaq/utils/managers/action_manager.py +460 -0
  82. pymodaq/{daq_utils → utils}/managers/batchscan_manager.py +144 -112
  83. pymodaq/{daq_utils → utils}/managers/modules_manager.py +188 -114
  84. pymodaq/{daq_utils → utils}/managers/overshoot_manager.py +3 -3
  85. pymodaq/utils/managers/parameter_manager.py +110 -0
  86. pymodaq/{daq_utils → utils}/managers/preset_manager.py +17 -13
  87. pymodaq/{daq_utils → utils}/managers/preset_manager_utils.py +8 -7
  88. pymodaq/{daq_utils → utils}/managers/remote_manager.py +7 -6
  89. pymodaq/{daq_utils → utils}/managers/roi_manager.py +148 -57
  90. pymodaq/utils/math_utils.py +546 -10
  91. pymodaq/{daq_utils → utils}/messenger.py +5 -1
  92. pymodaq/utils/parameter/__init__.py +2 -15
  93. pymodaq/{daq_utils → utils}/parameter/ioxml.py +12 -6
  94. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/__init__.py +1 -3
  95. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/filedir.py +1 -1
  96. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/itemselect.py +3 -0
  97. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/led.py +1 -1
  98. pymodaq/utils/parameter/pymodaq_ptypes/pixmap.py +161 -0
  99. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/slide.py +1 -1
  100. pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/table.py +1 -1
  101. pymodaq/utils/parameter/utils.py +206 -11
  102. pymodaq/utils/plotting/data_viewers/__init__.py +6 -0
  103. pymodaq/utils/plotting/data_viewers/viewer.py +393 -0
  104. pymodaq/utils/plotting/data_viewers/viewer0D.py +251 -0
  105. pymodaq/utils/plotting/data_viewers/viewer1D.py +574 -0
  106. pymodaq/{daq_utils → utils}/plotting/data_viewers/viewer1Dbasic.py +8 -3
  107. pymodaq/{daq_utils → utils}/plotting/data_viewers/viewer2D.py +292 -357
  108. pymodaq/{daq_utils → utils}/plotting/data_viewers/viewer2D_basic.py +58 -75
  109. pymodaq/utils/plotting/data_viewers/viewerND.py +738 -0
  110. pymodaq/{daq_utils → utils}/plotting/gant_chart.py +2 -2
  111. pymodaq/{daq_utils → utils}/plotting/items/axis_scaled.py +4 -2
  112. pymodaq/{daq_utils → utils}/plotting/items/image.py +8 -6
  113. pymodaq/utils/plotting/navigator.py +355 -0
  114. pymodaq/utils/plotting/scan_selector.py +480 -0
  115. pymodaq/utils/plotting/utils/axes_viewer.py +88 -0
  116. pymodaq/utils/plotting/utils/filter.py +538 -0
  117. pymodaq/utils/plotting/utils/lineout.py +224 -0
  118. pymodaq/{daq_utils → utils}/plotting/utils/plot_utils.py +196 -84
  119. pymodaq/{daq_utils → utils}/plotting/utils/signalND.py +21 -13
  120. pymodaq/utils/plotting/widgets.py +76 -0
  121. pymodaq/utils/scanner/__init__.py +10 -0
  122. pymodaq/utils/scanner/scan_factory.py +204 -0
  123. pymodaq/utils/scanner/scanner.py +271 -0
  124. pymodaq/utils/scanner/scanners/_1d_scanners.py +117 -0
  125. pymodaq/utils/scanner/scanners/_2d_scanners.py +293 -0
  126. pymodaq/utils/scanner/scanners/sequential.py +192 -0
  127. pymodaq/utils/scanner/scanners/tabular.py +294 -0
  128. pymodaq/utils/scanner/utils.py +83 -0
  129. pymodaq/utils/slicing.py +47 -0
  130. pymodaq/utils/svg/__init__.py +6 -0
  131. pymodaq/utils/svg/svg_renderer.py +20 -0
  132. pymodaq/utils/svg/svg_view.py +35 -0
  133. pymodaq/utils/svg/svg_viewer2D.py +51 -0
  134. pymodaq/{daq_utils → utils}/tcp_server_client.py +36 -37
  135. pymodaq/{daq_utils → utils}/tree_layout/tree_layout_main.py +50 -35
  136. pymodaq/utils/units.py +216 -0
  137. pymodaq-4.0.1.dist-info/METADATA +159 -0
  138. {pymodaq-3.6.13.dist-info → pymodaq-4.0.1.dist-info}/RECORD +167 -170
  139. {pymodaq-3.6.13.dist-info → pymodaq-4.0.1.dist-info}/WHEEL +1 -2
  140. pymodaq-4.0.1.dist-info/entry_points.txt +8 -0
  141. pymodaq/daq_move/daq_move_gui.py +0 -279
  142. pymodaq/daq_move/daq_move_gui.ui +0 -534
  143. pymodaq/daq_move/daq_move_main.py +0 -1042
  144. pymodaq/daq_move/process_from_QtDesigner_DAQ_Move_GUI.bat +0 -2
  145. pymodaq/daq_move/utility_classes.py +0 -686
  146. pymodaq/daq_scan.py +0 -2160
  147. pymodaq/daq_utils/array_manipulation.py +0 -386
  148. pymodaq/daq_utils/config.py +0 -273
  149. pymodaq/daq_utils/conftests.py +0 -7
  150. pymodaq/daq_utils/custom_parameter_tree.py +0 -9
  151. pymodaq/daq_utils/daq_enums.py +0 -133
  152. pymodaq/daq_utils/daq_utils.py +0 -1402
  153. pymodaq/daq_utils/exceptions.py +0 -71
  154. pymodaq/daq_utils/gui_utils/custom_app.py +0 -103
  155. pymodaq/daq_utils/gui_utils/file_io.py +0 -75
  156. pymodaq/daq_utils/gui_utils/widgets/spinbox.py +0 -9
  157. pymodaq/daq_utils/h5exporter_hyperspy.py +0 -115
  158. pymodaq/daq_utils/h5exporters.py +0 -242
  159. pymodaq/daq_utils/h5modules.py +0 -1559
  160. pymodaq/daq_utils/h5utils.py +0 -241
  161. pymodaq/daq_utils/managers/action_manager.py +0 -236
  162. pymodaq/daq_utils/managers/parameter_manager.py +0 -57
  163. pymodaq/daq_utils/math_utils.py +0 -705
  164. pymodaq/daq_utils/parameter/__init__.py +0 -1
  165. pymodaq/daq_utils/parameter/oldpymodaq_ptypes.py +0 -1626
  166. pymodaq/daq_utils/parameter/pymodaq_ptypes/pixmap.py +0 -85
  167. pymodaq/daq_utils/parameter/utils.py +0 -136
  168. pymodaq/daq_utils/plotting/data_viewers/__init__.py +0 -0
  169. pymodaq/daq_utils/plotting/data_viewers/process_from_QtDesigner_0DViewer_GUI.bat +0 -2
  170. pymodaq/daq_utils/plotting/data_viewers/viewer0D.py +0 -204
  171. pymodaq/daq_utils/plotting/data_viewers/viewer0D_GUI.py +0 -89
  172. pymodaq/daq_utils/plotting/data_viewers/viewer0D_GUI.ui +0 -131
  173. pymodaq/daq_utils/plotting/data_viewers/viewer1D.py +0 -781
  174. pymodaq/daq_utils/plotting/data_viewers/viewerND.py +0 -894
  175. pymodaq/daq_utils/plotting/data_viewers/viewerbase.py +0 -64
  176. pymodaq/daq_utils/plotting/items/__init__.py +0 -0
  177. pymodaq/daq_utils/plotting/navigator.py +0 -500
  178. pymodaq/daq_utils/plotting/scan_selector.py +0 -289
  179. pymodaq/daq_utils/plotting/utils/__init__.py +0 -0
  180. pymodaq/daq_utils/plotting/utils/filter.py +0 -236
  181. pymodaq/daq_utils/plotting/viewer0D/__init__.py +0 -0
  182. pymodaq/daq_utils/plotting/viewer0D/viewer0D_main.py +0 -4
  183. pymodaq/daq_utils/plotting/viewer1D/__init__.py +0 -0
  184. pymodaq/daq_utils/plotting/viewer1D/viewer1D_main.py +0 -4
  185. pymodaq/daq_utils/plotting/viewer1D/viewer1Dbasic.py +0 -4
  186. pymodaq/daq_utils/plotting/viewer2D/viewer_2D_basic.py +0 -4
  187. pymodaq/daq_utils/plotting/viewer2D/viewer_2D_main.py +0 -4
  188. pymodaq/daq_utils/plotting/viewerND/__init__.py +0 -0
  189. pymodaq/daq_utils/plotting/viewerND/viewerND_main.py +0 -4
  190. pymodaq/daq_utils/scanner.py +0 -1289
  191. pymodaq/daq_utils/tree_layout/__init__.py +0 -0
  192. pymodaq/daq_viewer/__init__.py +0 -0
  193. pymodaq/daq_viewer/daq_gui_settings.py +0 -237
  194. pymodaq/daq_viewer/daq_gui_settings.ui +0 -441
  195. pymodaq/daq_viewer/daq_viewer_main.py +0 -2225
  196. pymodaq/daq_viewer/process_from_QtDesigner_DAQ_GUI_settings.bat +0 -2
  197. pymodaq/daq_viewer/utility_classes.py +0 -673
  198. pymodaq/examples/logger_image/__init__.py +0 -0
  199. pymodaq/examples/logger_image/logger_displayer.py +0 -121
  200. pymodaq/examples/logger_image/setup.svg +0 -3119
  201. pymodaq/examples/logger_image/setup_svg.py +0 -114
  202. pymodaq/h5browser.py +0 -39
  203. pymodaq/utils/scanner.py +0 -15
  204. pymodaq-3.6.13.dist-info/METADATA +0 -39
  205. pymodaq-3.6.13.dist-info/entry_points.txt +0 -8
  206. pymodaq-3.6.13.dist-info/top_level.txt +0 -1
  207. /pymodaq/{daq_analysis → post_treatment/daq_analysis}/__init__.py +0 -0
  208. /pymodaq/{daq_measurement → post_treatment/daq_measurement}/__init__.py +0 -0
  209. /pymodaq/{daq_measurement → post_treatment/daq_measurement}/daq_measurement_GUI.py +0 -0
  210. /pymodaq/{daq_measurement → post_treatment/daq_measurement}/daq_measurement_GUI.ui +0 -0
  211. /pymodaq/{daq_measurement → post_treatment/daq_measurement}/process_from_QtDesigner_DAQ_Measurement_GUI.bat +0 -0
  212. /pymodaq/{daq_utils → utils}/Tuto innosetup/Tuto innosetup.odt +0 -0
  213. /pymodaq/{daq_utils → utils}/Tuto innosetup/Tuto innosetup.pdf +0 -0
  214. /pymodaq/{daq_move → utils/db}/__init__.py +0 -0
  215. /pymodaq/{daq_utils → utils/db/db_logger}/__init__.py +0 -0
  216. /pymodaq/{daq_utils → utils}/gui_utils/dock.py +0 -0
  217. /pymodaq/{daq_utils → utils}/gui_utils/list_picker.py +0 -0
  218. /pymodaq/{daq_utils/abstract → utils/managers}/__init__.py +0 -0
  219. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/bool.py +0 -0
  220. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/date.py +0 -0
  221. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/list.py +0 -0
  222. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/numeric.py +0 -0
  223. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/tableview.py +0 -0
  224. /pymodaq/{daq_utils → utils}/parameter/pymodaq_ptypes/text.py +0 -0
  225. /pymodaq/{daq_utils/db → utils/plotting}/__init__.py +0 -0
  226. /pymodaq/{daq_utils → utils}/plotting/image_viewer.py +0 -0
  227. /pymodaq/{daq_utils/db/db_logger → utils/plotting/items}/__init__.py +0 -0
  228. /pymodaq/{daq_utils → utils}/plotting/items/crosshair.py +0 -0
  229. /pymodaq/{daq_utils/managers → utils/plotting/utils}/__init__.py +0 -0
  230. /pymodaq/{daq_utils → utils}/qvariant.py +0 -0
  231. /pymodaq/{daq_utils/plotting/viewer2D → utils/scanner/scanners}/__init__.py +0 -0
  232. /pymodaq/{daq_utils/plotting → utils/tree_layout}/__init__.py +0 -0
  233. {pymodaq-3.6.13.dist-info → pymodaq-4.0.1.dist-info/licenses}/LICENSE +0 -0
@@ -1,15 +1,386 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """
3
- Created the 27/10/2022
4
-
5
- @author: Sebastien Weber
3
+ Created on Mon March 03 2021
4
+ author: Sebastien Weber
6
5
  """
6
+ import numpy as np
7
+
8
+
9
+ def random_step(start, stop, step):
10
+ tmp = start
11
+ out = np.array([tmp])
12
+ sign = stop - start
13
+ if step == 0:
14
+ raise ValueError('step must be strictly positive or negative')
15
+ if step > 0 and sign > 0:
16
+ while tmp <= stop:
17
+ tmp = tmp + (np.random.random() + 0.5) * step
18
+ out = np.append(out, tmp)
19
+ elif step < 0 and sign < 0:
20
+ while tmp >= stop:
21
+ tmp = tmp + (np.random.random() + 0.5) * step
22
+ out = np.append(out, tmp)
23
+ else:
24
+ raise ValueError(f'the step value {step} is not of the same sign as stop - start : {sign}')
25
+ return out[0:-1]
26
+
7
27
 
8
- from pymodaq.daq_utils import array_manipulation
28
+ def linspace_this_vect(x, y=None, Npts=None):
29
+ """
30
+ Given a vector x, it returns a vector xlin where xlin is a
31
+ linearised version of x on the same interval and with the same size.
32
+ if args is provided it is a y vector and the function returns both xlin
33
+ and ylin where ylin is a linear interpolation of y on this new xlin axis
34
+
35
+ Parameters
36
+ ----------
37
+ x : (ndarray)
38
+ y : (ndarray) optional
39
+ Npts: (int) size of the linear vector (optional)
9
40
 
41
+ Returns
42
+ -------
43
+ xlin : vector
44
+ (ylin : vector) optional if args is provided
10
45
 
11
- def __getattr__(name):
12
- if hasattr(array_manipulation, name):
13
- return getattr(array_manipulation, name)
46
+ """
47
+ if not Npts:
48
+ Npts = np.size(x)
49
+ xlin = np.linspace(np.min(x), np.max(x), Npts)
50
+ if y is not None:
51
+ ylin = np.interp(xlin, x, y)
52
+ return xlin, ylin
14
53
  else:
15
- raise AttributeError
54
+ return xlin
55
+
56
+
57
+ def find_index(x, threshold):
58
+ """
59
+ find_index finds the index ix such that x(ix) is the closest from threshold
60
+
61
+ Parameters
62
+ ----------
63
+ x : vector
64
+ threshold : list of scalar
65
+
66
+ Returns
67
+ -------
68
+ out : list of 2-tuple containing ix,x[ix]
69
+ out=[(ix0,xval0),(ix1,xval1),...]
70
+ """
71
+
72
+ if np.isscalar(threshold):
73
+ threshold = [threshold]
74
+ out = []
75
+ for value in threshold:
76
+ ix = int(np.argmin(np.abs(x - value)))
77
+ out.append((ix, x[ix]))
78
+ return out
79
+
80
+
81
+ def find_rising_edges(x, threshold):
82
+ """find_rising_edges finds the index ix such that x(ix) is the closest from threshold and values are increasing
83
+
84
+ Parameters
85
+ ----------
86
+ x : vector
87
+ threshold : list of scalar
88
+
89
+ Returns
90
+ -------
91
+ out : list of 2-tuple containing ix,x[ix]
92
+ out=[(ix0,xval0),(ix1,xval1),...]
93
+
94
+ """
95
+ x_shifted = np.concatenate((x[1:], np.array((np.NaN,))))
96
+ if np.isscalar(threshold):
97
+ threshold = [threshold]
98
+ out = []
99
+ for value in threshold:
100
+ dat = np.bitwise_and(x < value, x_shifted > value)
101
+ ix = [ind for ind, flag in enumerate(dat) if flag]
102
+ out.append((ix, x[ix]))
103
+ return out
104
+
105
+
106
+ def crop_vector_to_axis(x, V, xlim):
107
+ """crops a vector V with given x axis vector to a given xlim tuple
108
+
109
+ Parameters
110
+ ----------
111
+ x : vector
112
+ V : vector
113
+ xlim: tuple containing (xmin,xmax)
114
+
115
+ Returns
116
+ -------
117
+ x_c : vector
118
+ V_c : vector
119
+ """
120
+ x1 = find_index(x, xlim[0])[0][0]
121
+ x2 = find_index(x, xlim[1])[0][0]
122
+ if x2 > x1:
123
+ ixx = np.linspace(x1, x2, x2 - x1 + 1, dtype=int);
124
+ else:
125
+ ixx = np.linspace(x2, x1, x1 - x2 + 1, dtype=int);
126
+
127
+ x_c = x[ixx]
128
+ V_c = V[ixx]
129
+ return x_c, V_c
130
+
131
+ def rescale(x, window=[0.0, 1.0]):
132
+ """ Rescales a numpy array to the range specified by ``window``.
133
+
134
+ Default is [0, 1].
135
+ """
136
+ maxx = np.max(x)
137
+ minx = np.min(x)
138
+ return (x - minx) / (maxx - minx) * (window[1] - window[0]) + window[0]
139
+
140
+
141
+ def marginals(data, normalize=False, axes=None):
142
+ """ Calculates the marginals of the data array.
143
+
144
+ axes specifies the axes of the marginals, e.g., the axes on which the
145
+ sum is projected.
146
+
147
+ If axis is None a list of all marginals is returned.
148
+ """
149
+ if axes is None:
150
+ axes = range(data.ndim)
151
+ axes = list(axes)
152
+ full_axes = list(range(data.ndim))
153
+ m = []
154
+ for i in axes:
155
+ # for the marginal sum over all axes except the specified one
156
+ margin_axes = tuple(j for j in full_axes if j != i)
157
+ m.append(np.sum(data, axis=margin_axes))
158
+ if normalize:
159
+ m = [rescale(mx) for mx in m]
160
+ return tuple(m) if len(m) != 1 else m[0]
161
+
162
+
163
+ def find(x, condition, n=1):
164
+ """ Return the index of the nth element that fulfills the condition.
165
+ """
166
+ search_n = 1
167
+ for i in range(len(x)):
168
+ if condition(x[i]):
169
+ if search_n == n:
170
+ return i
171
+ search_n += 1
172
+ return -1
173
+
174
+
175
+ def arglimit(y, threshold=1e-3, padding=0.0, normalize=True):
176
+ """ Returns the first and last index where `y >= threshold * max(abs(y))`.
177
+ """
178
+ t = np.abs(y)
179
+ if normalize:
180
+ t = t / np.max(t)
181
+
182
+ idx1 = find(t, lambda x: x >= threshold)
183
+ if idx1 == -1:
184
+ idx1 = 0
185
+ idx2 = find(t[::-1], lambda x: x >= threshold)
186
+ if idx2 == -1:
187
+ idx2 = t.shape[0] - 1
188
+ else:
189
+ idx2 = t.shape[0] - 1 - idx2
190
+
191
+ return (idx1, idx2)
192
+
193
+
194
+ def limit(x, y=None, threshold=1e-3, padding=0.25, extend=True):
195
+ """ Returns the maximum x-range where the y-values are sufficiently large.
196
+
197
+ Parameters
198
+ ----------
199
+ x : array_like
200
+ The x values of the graph.
201
+ y : array_like, optional
202
+ The y values of the graph. If `None` the maximum range of `x` is
203
+ used. That is only useful if `padding > 0`.
204
+ threshold : float
205
+ The threshold relative to the maximum of `y` of values that should be
206
+ included in the bracket.
207
+ padding : float
208
+ The relative padding on each side in fractions of the bracket size.
209
+ extend : bool, optional
210
+ Signals if the returned range can be larger than the values in ``x``.
211
+ Default is `True`.
212
+
213
+ Returns
214
+ -------
215
+ xl, xr : float
216
+ Lowest and biggest value of the range.
217
+
218
+ """
219
+ if y is None:
220
+ x1, x2 = np.min(x), np.max(x)
221
+ if not extend:
222
+ return (x1, x2)
223
+ else:
224
+ idx1, idx2 = arglimit(y, threshold=threshold)
225
+ x1, x2 = sorted([x[idx1], x[idx2]])
226
+
227
+ # calculate the padding
228
+ if padding != 0.0:
229
+ pad = (x2 - x1) * padding
230
+ x1 -= pad
231
+ x2 += pad
232
+
233
+ if not extend:
234
+ x1 = max(x1, np.min(x))
235
+ x2 = min(x2, np.max(x))
236
+
237
+ return (x1, x2)
238
+
239
+
240
+ def crop_array_to_axis(x, y, M, cropbox):
241
+ """crops an array M with given cropbox as a tuple (xmin,xmax,ymin,ymax).
242
+
243
+ Parameters
244
+ ----------
245
+ x : vector
246
+ y : vector
247
+ M : 2D array
248
+ cropbox: 4 elements tuple containing (xmin,xmax,ymin,ymax)
249
+
250
+ Returns
251
+ -------
252
+ x_c : croped x vector
253
+ y_c : croped y vector
254
+ M_c : croped 2D M array
255
+
256
+ """
257
+ x1 = find_index(x, cropbox[0])[0][0]
258
+ x2 = find_index(x, cropbox[1])[0][0]
259
+ if x2 > x1:
260
+ ixx = np.linspace(x1, x2, x2 - x1 + 1, dtype=int)
261
+ else:
262
+ ixx = np.linspace(x2, x1, x1 - x2 + 1, dtype=int)
263
+
264
+ y1 = find_index(y, cropbox[2])[0][0]
265
+ y2 = find_index(y, cropbox[3])[0][0]
266
+ if y2 > y1:
267
+ iyy = np.linspace(y1, y2, y2 - y1 + 1, dtype=int)
268
+ else:
269
+ iyy = np.linspace(y2, y1, y1 - y2 + 1, dtype=int)
270
+
271
+ x_c = x[ixx]
272
+ y_c = y[iyy]
273
+
274
+ M_c = M[iyy[0]:iyy[-1] + 1, ixx[0]:ixx[-1] + 1]
275
+ return x_c, y_c, M_c
276
+
277
+
278
+ def interp1D(x, M, xlin, axis=1):
279
+ """
280
+ same as numpy interp function but works on 2D array
281
+ you have to specify the axis over which to do the interpolation
282
+ kwargs refers to the numpy interp kwargs
283
+ returns both xlin and the new 2D array Minterp
284
+ """
285
+ if axis == 0:
286
+ Minterp = np.zeros((np.size(xlin), np.size(M, axis=1)))
287
+ indexes = np.arange(0, np.size(M, axis=1))
288
+ for ind in indexes:
289
+ # print(ind)
290
+ Minterp[:, ind] = np.interp(xlin, x, M[:, ind])
291
+ else:
292
+ Minterp = np.zeros((np.size(M, axis=0), np.size(xlin)))
293
+ indexes = np.arange(0, np.size(M, axis=0))
294
+ for ind in indexes:
295
+ Minterp[ind, :] = np.interp(xlin, x, M[ind, :])
296
+ return Minterp
297
+
298
+
299
+ def linspace_this_image(x, M, axis=1, Npts=None):
300
+ """
301
+ Given a vector x and a 2D array M, it returns an array vector xlin where xlin is a
302
+ linearised version of x on the same interval and with the same size. it returns as well
303
+ a 2D array Minterp interpolated on the new xlin vector along the specified axis.
304
+
305
+ Parameters
306
+ ----------
307
+ x : (vector)
308
+ M : (2D array)
309
+ axis : (int)
310
+ Npts: (int) size of the linear vector (optional)
311
+
312
+ Returns
313
+ -------
314
+ xlin : vector
315
+ Minterp : 2D array
316
+ """
317
+ xlin = linspace_this_vect(x, Npts=Npts)
318
+ Minterp = interp1D(x, M, xlin, axis=axis)
319
+
320
+ return xlin, Minterp
321
+
322
+
323
+ def max_ind(x, axis=None):
324
+ """returns the max value in a vector or array and its index (in a tuple)
325
+
326
+ Parameters
327
+ ----------
328
+ x : vector
329
+
330
+ axis : optional dimension aginst which to normalise
331
+
332
+ Returns
333
+ -------
334
+ ind_max : index of the maximum value
335
+
336
+ max_val : maximum value
337
+ """
338
+ ind_max = np.argmax(x, axis=axis)
339
+ max_val = np.max(x, axis=axis)
340
+ return ind_max, max_val
341
+
342
+
343
+ def min_ind(x, axis=None):
344
+ """returns the min value in a vector or array and its index (in flattened array)
345
+
346
+ Parameters
347
+ ----------
348
+ x : vector
349
+ axis : optional dimension to check the function
350
+
351
+ Returns
352
+ -------
353
+ ind_min : index of the minimum value
354
+ min_val : minimum value
355
+ """
356
+ ind_min = np.argmin(x, axis=axis)
357
+ min_val = np.min(x, axis=axis)
358
+ return ind_min, min_val
359
+
360
+
361
+ if __name__ == '__main__': # pragma: no cover
362
+ from pymodaq.utils import daq_utils as utils
363
+ import matplotlib.pyplot as plt
364
+
365
+ x = random_step(00, 100, 5)
366
+ y = random_step(00, 100, 5)
367
+ g2 = utils.gauss2D(x, 35, 15, y, 55, 20, 1)
368
+ (xlin, g2_interp) = linspace_this_image(x, g2, axis=1, Npts=100)
369
+ (ylin, g2_interp_both) = linspace_this_image(y, g2_interp, axis=0, Npts=100)
370
+ plt.figure('gauss2D')
371
+ plt.subplot(221)
372
+ plt.pcolormesh(x, y, g2)
373
+ plt.subplot(222)
374
+ plt.pcolormesh(xlin, y, g2_interp)
375
+ plt.subplot(223)
376
+ plt.pcolormesh(xlin, ylin, g2_interp_both)
377
+
378
+ plt.show()
379
+
380
+ x_c, y_c, M_c = crop_array_to_axis(x, y, g2, [20, 60, 40, 80])
381
+ plt.figure('cropped')
382
+ plt.subplot(121)
383
+ plt.pcolormesh(x, y, g2)
384
+ plt.subplot(122)
385
+ plt.pcolormesh(x_c, y_c, M_c)
386
+ plt.show()
@@ -1,15 +1,15 @@
1
1
  from qtpy import QtWidgets
2
2
  from qtpy.QtCore import Qt, QObject
3
3
 
4
- import pymodaq.daq_utils.parameter.ioxml
4
+ import pymodaq.utils.parameter.ioxml
5
5
  from pyqtgraph.parametertree import Parameter, ParameterTree
6
6
 
7
7
  import sys
8
- from pymodaq.daq_utils.plotting.data_viewers.viewer2D import Viewer2D
9
- from pymodaq.daq_measurement.daq_measurement_main import DAQ_Measurement
10
- from pymodaq.daq_utils.h5modules import browse_data
8
+ from pymodaq.utils.plotting.data_viewers.viewer2D import Viewer2D
9
+ from pymodaq.post_treatment.daq_measurement.daq_measurement_main import DAQ_Measurement
10
+ from pymodaq.utils.h5modules.browsing import browse_data
11
11
  import os
12
- from pymodaq.daq_utils.config import get_set_local_dir
12
+ from pymodaq.utils.config import get_set_local_dir
13
13
 
14
14
  local_path = get_set_local_dir()
15
15
  calib_path = os.path.join(local_path, 'camera_calibrations')
@@ -135,7 +135,7 @@ class CalibrationCamera(QtWidgets.QWidget, QObject):
135
135
  ]},
136
136
  ]}, ]
137
137
  param_obj = Parameter.create(name='Axes_Settings', type='group', children=params)
138
- pymodaq.daq_utils.parameter.ioxml.parameter_to_xml_file(param_obj,
138
+ pymodaq.utils.parameter.ioxml.parameter_to_xml_file(param_obj,
139
139
  os.path.join(calib_path, os.path.split(self.fname)[1]))
140
140
  self.settings.child(('data_saved')).setValue(True)
141
141
  self.settings.child(('filepath')).setValue(os.path.join(calib_path, os.path.split(self.fname)[1]))
@@ -1,7 +1,7 @@
1
1
  from qtpy import QtGui, QtWidgets
2
2
  from qtpy.QtCore import Qt, QObject, QTimer
3
3
  from pyqtgraph.dockarea import Dock
4
- from pymodaq.daq_utils.gui_utils import DockArea
4
+ from pymodaq.utils.gui_utils import DockArea
5
5
  import time
6
6
  from datetime import timedelta
7
7
  import sys