sigima 0.0.1.dev0__py3-none-any.whl → 1.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.
Files changed (264) hide show
  1. sigima/__init__.py +142 -2
  2. sigima/client/__init__.py +105 -0
  3. sigima/client/base.py +780 -0
  4. sigima/client/remote.py +469 -0
  5. sigima/client/stub.py +814 -0
  6. sigima/client/utils.py +90 -0
  7. sigima/config.py +444 -0
  8. sigima/data/logo/Sigima.svg +135 -0
  9. sigima/data/tests/annotations.json +798 -0
  10. sigima/data/tests/curve_fitting/exponential_fit.txt +511 -0
  11. sigima/data/tests/curve_fitting/gaussian_fit.txt +100 -0
  12. sigima/data/tests/curve_fitting/piecewiseexponential_fit.txt +1022 -0
  13. sigima/data/tests/curve_fitting/polynomial_fit.txt +100 -0
  14. sigima/data/tests/curve_fitting/twohalfgaussian_fit.txt +1000 -0
  15. sigima/data/tests/curve_formats/bandwidth.txt +201 -0
  16. sigima/data/tests/curve_formats/boxcar.npy +0 -0
  17. sigima/data/tests/curve_formats/datetime.txt +1001 -0
  18. sigima/data/tests/curve_formats/dynamic_parameters.txt +4000 -0
  19. sigima/data/tests/curve_formats/fw1e2.txt +301 -0
  20. sigima/data/tests/curve_formats/fwhm.txt +319 -0
  21. sigima/data/tests/curve_formats/multiple_curves.csv +29 -0
  22. sigima/data/tests/curve_formats/noised_saw.mat +0 -0
  23. sigima/data/tests/curve_formats/oscilloscope.csv +111 -0
  24. sigima/data/tests/curve_formats/other/other2/recursive2.txt +5 -0
  25. sigima/data/tests/curve_formats/other/recursive1.txt +5 -0
  26. sigima/data/tests/curve_formats/paracetamol.npy +0 -0
  27. sigima/data/tests/curve_formats/paracetamol.txt +1010 -0
  28. sigima/data/tests/curve_formats/paracetamol_dx_dy.csv +1000 -0
  29. sigima/data/tests/curve_formats/paracetamol_dy.csv +1001 -0
  30. sigima/data/tests/curve_formats/pulse1.npy +0 -0
  31. sigima/data/tests/curve_formats/pulse2.npy +0 -0
  32. sigima/data/tests/curve_formats/simple.txt +5 -0
  33. sigima/data/tests/curve_formats/spectrum.mca +2139 -0
  34. sigima/data/tests/curve_formats/square2.npy +0 -0
  35. sigima/data/tests/curve_formats/step.npy +0 -0
  36. sigima/data/tests/fabry-perot1.jpg +0 -0
  37. sigima/data/tests/fabry-perot2.jpg +0 -0
  38. sigima/data/tests/flower.npy +0 -0
  39. sigima/data/tests/image_formats/NF 180338201.scor-data +11003 -0
  40. sigima/data/tests/image_formats/binary_image.npy +0 -0
  41. sigima/data/tests/image_formats/binary_image.png +0 -0
  42. sigima/data/tests/image_formats/centroid_test.npy +0 -0
  43. sigima/data/tests/image_formats/coordinated_text/complex_image.txt +10011 -0
  44. sigima/data/tests/image_formats/coordinated_text/complex_ref_image.txt +10010 -0
  45. sigima/data/tests/image_formats/coordinated_text/image.txt +15 -0
  46. sigima/data/tests/image_formats/coordinated_text/image2.txt +14 -0
  47. sigima/data/tests/image_formats/coordinated_text/image_no_unit_no_label.txt +14 -0
  48. sigima/data/tests/image_formats/coordinated_text/image_with_nan.txt +15 -0
  49. sigima/data/tests/image_formats/coordinated_text/image_with_unit.txt +14 -0
  50. sigima/data/tests/image_formats/fiber.csv +480 -0
  51. sigima/data/tests/image_formats/fiber.jpg +0 -0
  52. sigima/data/tests/image_formats/fiber.png +0 -0
  53. sigima/data/tests/image_formats/fiber.txt +480 -0
  54. sigima/data/tests/image_formats/gaussian_spot_with_noise.npy +0 -0
  55. sigima/data/tests/image_formats/mr-brain.dcm +0 -0
  56. sigima/data/tests/image_formats/noised_gaussian.mat +0 -0
  57. sigima/data/tests/image_formats/sif_reader/nd_lum_image_no_glue.sif +0 -0
  58. sigima/data/tests/image_formats/sif_reader/raman1.sif +0 -0
  59. sigima/data/tests/image_formats/tiling.txt +10 -0
  60. sigima/data/tests/image_formats/uint16.tiff +0 -0
  61. sigima/data/tests/image_formats/uint8.tiff +0 -0
  62. sigima/data/tests/laser_beam/TEM00_z_13.jpg +0 -0
  63. sigima/data/tests/laser_beam/TEM00_z_18.jpg +0 -0
  64. sigima/data/tests/laser_beam/TEM00_z_23.jpg +0 -0
  65. sigima/data/tests/laser_beam/TEM00_z_30.jpg +0 -0
  66. sigima/data/tests/laser_beam/TEM00_z_35.jpg +0 -0
  67. sigima/data/tests/laser_beam/TEM00_z_40.jpg +0 -0
  68. sigima/data/tests/laser_beam/TEM00_z_45.jpg +0 -0
  69. sigima/data/tests/laser_beam/TEM00_z_50.jpg +0 -0
  70. sigima/data/tests/laser_beam/TEM00_z_55.jpg +0 -0
  71. sigima/data/tests/laser_beam/TEM00_z_60.jpg +0 -0
  72. sigima/data/tests/laser_beam/TEM00_z_65.jpg +0 -0
  73. sigima/data/tests/laser_beam/TEM00_z_70.jpg +0 -0
  74. sigima/data/tests/laser_beam/TEM00_z_75.jpg +0 -0
  75. sigima/data/tests/laser_beam/TEM00_z_80.jpg +0 -0
  76. sigima/enums.py +195 -0
  77. sigima/io/__init__.py +123 -0
  78. sigima/io/base.py +311 -0
  79. sigima/io/common/__init__.py +5 -0
  80. sigima/io/common/basename.py +164 -0
  81. sigima/io/common/converters.py +189 -0
  82. sigima/io/common/objmeta.py +181 -0
  83. sigima/io/common/textreader.py +58 -0
  84. sigima/io/convenience.py +157 -0
  85. sigima/io/enums.py +17 -0
  86. sigima/io/ftlab.py +395 -0
  87. sigima/io/image/__init__.py +9 -0
  88. sigima/io/image/base.py +177 -0
  89. sigima/io/image/formats.py +1016 -0
  90. sigima/io/image/funcs.py +414 -0
  91. sigima/io/signal/__init__.py +9 -0
  92. sigima/io/signal/base.py +129 -0
  93. sigima/io/signal/formats.py +290 -0
  94. sigima/io/signal/funcs.py +723 -0
  95. sigima/objects/__init__.py +260 -0
  96. sigima/objects/base.py +937 -0
  97. sigima/objects/image/__init__.py +88 -0
  98. sigima/objects/image/creation.py +556 -0
  99. sigima/objects/image/object.py +524 -0
  100. sigima/objects/image/roi.py +904 -0
  101. sigima/objects/scalar/__init__.py +57 -0
  102. sigima/objects/scalar/common.py +215 -0
  103. sigima/objects/scalar/geometry.py +502 -0
  104. sigima/objects/scalar/table.py +784 -0
  105. sigima/objects/shape.py +290 -0
  106. sigima/objects/signal/__init__.py +133 -0
  107. sigima/objects/signal/constants.py +27 -0
  108. sigima/objects/signal/creation.py +1428 -0
  109. sigima/objects/signal/object.py +444 -0
  110. sigima/objects/signal/roi.py +274 -0
  111. sigima/params.py +405 -0
  112. sigima/proc/__init__.py +96 -0
  113. sigima/proc/base.py +381 -0
  114. sigima/proc/decorator.py +330 -0
  115. sigima/proc/image/__init__.py +513 -0
  116. sigima/proc/image/arithmetic.py +335 -0
  117. sigima/proc/image/base.py +260 -0
  118. sigima/proc/image/detection.py +519 -0
  119. sigima/proc/image/edges.py +329 -0
  120. sigima/proc/image/exposure.py +406 -0
  121. sigima/proc/image/extraction.py +458 -0
  122. sigima/proc/image/filtering.py +219 -0
  123. sigima/proc/image/fourier.py +147 -0
  124. sigima/proc/image/geometry.py +661 -0
  125. sigima/proc/image/mathops.py +340 -0
  126. sigima/proc/image/measurement.py +195 -0
  127. sigima/proc/image/morphology.py +155 -0
  128. sigima/proc/image/noise.py +107 -0
  129. sigima/proc/image/preprocessing.py +182 -0
  130. sigima/proc/image/restoration.py +235 -0
  131. sigima/proc/image/threshold.py +217 -0
  132. sigima/proc/image/transformations.py +393 -0
  133. sigima/proc/signal/__init__.py +376 -0
  134. sigima/proc/signal/analysis.py +206 -0
  135. sigima/proc/signal/arithmetic.py +551 -0
  136. sigima/proc/signal/base.py +262 -0
  137. sigima/proc/signal/extraction.py +60 -0
  138. sigima/proc/signal/features.py +310 -0
  139. sigima/proc/signal/filtering.py +484 -0
  140. sigima/proc/signal/fitting.py +276 -0
  141. sigima/proc/signal/fourier.py +259 -0
  142. sigima/proc/signal/mathops.py +420 -0
  143. sigima/proc/signal/processing.py +580 -0
  144. sigima/proc/signal/stability.py +175 -0
  145. sigima/proc/title_formatting.py +227 -0
  146. sigima/proc/validation.py +272 -0
  147. sigima/tests/__init__.py +7 -0
  148. sigima/tests/common/__init__.py +0 -0
  149. sigima/tests/common/arithmeticparam_unit_test.py +26 -0
  150. sigima/tests/common/basename_unit_test.py +126 -0
  151. sigima/tests/common/client_unit_test.py +412 -0
  152. sigima/tests/common/converters_unit_test.py +77 -0
  153. sigima/tests/common/decorator_unit_test.py +176 -0
  154. sigima/tests/common/examples_unit_test.py +104 -0
  155. sigima/tests/common/kernel_normalization_unit_test.py +242 -0
  156. sigima/tests/common/roi_basic_unit_test.py +73 -0
  157. sigima/tests/common/roi_geometry_unit_test.py +171 -0
  158. sigima/tests/common/scalar_builder_unit_test.py +142 -0
  159. sigima/tests/common/scalar_unit_test.py +991 -0
  160. sigima/tests/common/shape_unit_test.py +183 -0
  161. sigima/tests/common/stat_unit_test.py +138 -0
  162. sigima/tests/common/title_formatting_unit_test.py +338 -0
  163. sigima/tests/common/tools_coordinates_unit_test.py +60 -0
  164. sigima/tests/common/transformations_unit_test.py +178 -0
  165. sigima/tests/common/validation_unit_test.py +205 -0
  166. sigima/tests/conftest.py +129 -0
  167. sigima/tests/data.py +998 -0
  168. sigima/tests/env.py +280 -0
  169. sigima/tests/guiutils.py +163 -0
  170. sigima/tests/helpers.py +532 -0
  171. sigima/tests/image/__init__.py +28 -0
  172. sigima/tests/image/binning_unit_test.py +128 -0
  173. sigima/tests/image/blob_detection_unit_test.py +312 -0
  174. sigima/tests/image/centroid_unit_test.py +170 -0
  175. sigima/tests/image/check_2d_array_unit_test.py +63 -0
  176. sigima/tests/image/contour_unit_test.py +172 -0
  177. sigima/tests/image/convolution_unit_test.py +178 -0
  178. sigima/tests/image/datatype_unit_test.py +67 -0
  179. sigima/tests/image/edges_unit_test.py +155 -0
  180. sigima/tests/image/enclosingcircle_unit_test.py +88 -0
  181. sigima/tests/image/exposure_unit_test.py +223 -0
  182. sigima/tests/image/fft2d_unit_test.py +189 -0
  183. sigima/tests/image/filtering_unit_test.py +166 -0
  184. sigima/tests/image/geometry_unit_test.py +654 -0
  185. sigima/tests/image/hough_circle_unit_test.py +147 -0
  186. sigima/tests/image/imageobj_unit_test.py +737 -0
  187. sigima/tests/image/morphology_unit_test.py +71 -0
  188. sigima/tests/image/noise_unit_test.py +57 -0
  189. sigima/tests/image/offset_correction_unit_test.py +72 -0
  190. sigima/tests/image/operation_unit_test.py +518 -0
  191. sigima/tests/image/peak2d_limits_unit_test.py +41 -0
  192. sigima/tests/image/peak2d_unit_test.py +133 -0
  193. sigima/tests/image/profile_unit_test.py +159 -0
  194. sigima/tests/image/projections_unit_test.py +121 -0
  195. sigima/tests/image/restoration_unit_test.py +141 -0
  196. sigima/tests/image/roi2dparam_unit_test.py +53 -0
  197. sigima/tests/image/roi_advanced_unit_test.py +588 -0
  198. sigima/tests/image/roi_grid_unit_test.py +279 -0
  199. sigima/tests/image/spectrum2d_unit_test.py +40 -0
  200. sigima/tests/image/threshold_unit_test.py +91 -0
  201. sigima/tests/io/__init__.py +0 -0
  202. sigima/tests/io/addnewformat_unit_test.py +125 -0
  203. sigima/tests/io/convenience_funcs_unit_test.py +470 -0
  204. sigima/tests/io/coordinated_text_format_unit_test.py +495 -0
  205. sigima/tests/io/datetime_csv_unit_test.py +198 -0
  206. sigima/tests/io/imageio_formats_test.py +41 -0
  207. sigima/tests/io/ioregistry_unit_test.py +69 -0
  208. sigima/tests/io/objmeta_unit_test.py +87 -0
  209. sigima/tests/io/readobj_unit_test.py +130 -0
  210. sigima/tests/io/readwriteobj_unit_test.py +67 -0
  211. sigima/tests/signal/__init__.py +0 -0
  212. sigima/tests/signal/analysis_unit_test.py +135 -0
  213. sigima/tests/signal/check_1d_arrays_unit_test.py +169 -0
  214. sigima/tests/signal/convolution_unit_test.py +404 -0
  215. sigima/tests/signal/datetime_unit_test.py +176 -0
  216. sigima/tests/signal/fft1d_unit_test.py +303 -0
  217. sigima/tests/signal/filters_unit_test.py +403 -0
  218. sigima/tests/signal/fitting_unit_test.py +929 -0
  219. sigima/tests/signal/fwhm_unit_test.py +111 -0
  220. sigima/tests/signal/noise_unit_test.py +128 -0
  221. sigima/tests/signal/offset_correction_unit_test.py +34 -0
  222. sigima/tests/signal/operation_unit_test.py +489 -0
  223. sigima/tests/signal/peakdetection_unit_test.py +145 -0
  224. sigima/tests/signal/processing_unit_test.py +657 -0
  225. sigima/tests/signal/pulse/__init__.py +112 -0
  226. sigima/tests/signal/pulse/crossing_times_unit_test.py +123 -0
  227. sigima/tests/signal/pulse/plateau_detection_unit_test.py +102 -0
  228. sigima/tests/signal/pulse/pulse_unit_test.py +1824 -0
  229. sigima/tests/signal/roi_advanced_unit_test.py +392 -0
  230. sigima/tests/signal/signalobj_unit_test.py +603 -0
  231. sigima/tests/signal/stability_unit_test.py +431 -0
  232. sigima/tests/signal/uncertainty_unit_test.py +611 -0
  233. sigima/tests/vistools.py +1030 -0
  234. sigima/tools/__init__.py +59 -0
  235. sigima/tools/checks.py +290 -0
  236. sigima/tools/coordinates.py +308 -0
  237. sigima/tools/datatypes.py +26 -0
  238. sigima/tools/image/__init__.py +97 -0
  239. sigima/tools/image/detection.py +451 -0
  240. sigima/tools/image/exposure.py +77 -0
  241. sigima/tools/image/extraction.py +48 -0
  242. sigima/tools/image/fourier.py +260 -0
  243. sigima/tools/image/geometry.py +190 -0
  244. sigima/tools/image/preprocessing.py +165 -0
  245. sigima/tools/signal/__init__.py +86 -0
  246. sigima/tools/signal/dynamic.py +254 -0
  247. sigima/tools/signal/features.py +135 -0
  248. sigima/tools/signal/filtering.py +171 -0
  249. sigima/tools/signal/fitting.py +1171 -0
  250. sigima/tools/signal/fourier.py +466 -0
  251. sigima/tools/signal/interpolation.py +70 -0
  252. sigima/tools/signal/peakdetection.py +126 -0
  253. sigima/tools/signal/pulse.py +1626 -0
  254. sigima/tools/signal/scaling.py +50 -0
  255. sigima/tools/signal/stability.py +258 -0
  256. sigima/tools/signal/windowing.py +90 -0
  257. sigima/worker.py +79 -0
  258. sigima-1.0.0.dist-info/METADATA +233 -0
  259. sigima-1.0.0.dist-info/RECORD +262 -0
  260. {sigima-0.0.1.dev0.dist-info → sigima-1.0.0.dist-info}/licenses/LICENSE +29 -29
  261. sigima-0.0.1.dev0.dist-info/METADATA +0 -60
  262. sigima-0.0.1.dev0.dist-info/RECORD +0 -6
  263. {sigima-0.0.1.dev0.dist-info → sigima-1.0.0.dist-info}/WHEEL +0 -0
  264. {sigima-0.0.1.dev0.dist-info → sigima-1.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,657 @@
1
+ # Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.
2
+
3
+ """
4
+ Unit tests for signal processing functions
5
+ ------------------------------------------
6
+
7
+ Features from the "Processing" menu are covered by this test.
8
+ The "Processing" menu contains functions to process signals, such as
9
+ calibration, smoothing, and baseline correction.
10
+
11
+ Some of the functions are tested here, such as the signal calibration.
12
+ Other functions may be tested in different files, depending on the
13
+ complexity of the function.
14
+ """
15
+
16
+ # pylint: disable=invalid-name # Allows short reference names like x, y, ...
17
+ # pylint: disable=duplicate-code
18
+
19
+ from __future__ import annotations
20
+
21
+ import numpy as np
22
+ import pytest
23
+ import scipy
24
+ import scipy.ndimage as spi
25
+ import scipy.signal as sps
26
+ from packaging.version import Version
27
+
28
+ import sigima.enums
29
+ import sigima.objects
30
+ import sigima.params
31
+ import sigima.proc.signal
32
+ import sigima.tests.data
33
+ import sigima.tools.coordinates
34
+ from sigima.tests.data import get_test_signal
35
+ from sigima.tests.helpers import check_array_result, check_scalar_result
36
+
37
+
38
+ @pytest.mark.validation
39
+ def test_signal_calibration() -> None:
40
+ """Validation test for the signal calibration processing."""
41
+ src = get_test_signal("paracetamol.txt")
42
+ p = sigima.params.XYCalibrateParam()
43
+
44
+ # Test with a = 1 and b = 0: should do nothing
45
+ p.a, p.b = 1.0, 0.0
46
+ for axis, _taxis in p.axes:
47
+ p.axis = axis
48
+ dst = sigima.proc.signal.calibration(src, p)
49
+ exp = src.xydata
50
+ check_array_result("Calibration[identity]", dst.xydata, exp)
51
+
52
+ # Testing with random values of a and b
53
+ p.a, p.b = 0.5, 0.1
54
+ for axis, _taxis in p.axes:
55
+ p.axis = axis
56
+ exp_x1, exp_y1 = src.xydata.copy()
57
+ if axis == "x":
58
+ exp_x1 = p.a * exp_x1 + p.b
59
+ else:
60
+ exp_y1 = p.a * exp_y1 + p.b
61
+ dst = sigima.proc.signal.calibration(src, p)
62
+ res_x1, res_y1 = dst.xydata
63
+ title = f"Calibration[{axis},a={p.a},b={p.b}]"
64
+ check_array_result(f"{title}.x", res_x1, exp_x1)
65
+ check_array_result(f"{title}.y", res_y1, exp_y1)
66
+
67
+
68
+ @pytest.mark.validation
69
+ def test_signal_transpose() -> None:
70
+ """Validation test for the signal transpose processing."""
71
+ src = get_test_signal("paracetamol.txt")
72
+ dst = sigima.proc.signal.transpose(src)
73
+ exp_y, exp_x = src.xydata
74
+ check_array_result("Transpose|x", dst.x, exp_x)
75
+ check_array_result("Transpose|y", dst.y, exp_y)
76
+
77
+
78
+ @pytest.mark.validation
79
+ def test_signal_reverse_x() -> None:
80
+ """Validation test for the signal reverse x processing."""
81
+ src = get_test_signal("paracetamol.txt")
82
+ dst = sigima.proc.signal.reverse_x(src)
83
+ exp = src.data[::-1]
84
+ check_array_result("ReverseX", dst.data, exp)
85
+
86
+
87
+ def test_to_polar() -> None:
88
+ """Unit test for the Cartesian to polar conversion."""
89
+ title = "Cartesian2Polar"
90
+ x = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
91
+ y = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
92
+
93
+ r, theta = sigima.tools.coordinates.to_polar(x, y, "rad")
94
+ exp_r = np.array([0.0, np.sqrt(2.0), np.sqrt(8.0), np.sqrt(18.0), np.sqrt(32.0)])
95
+ exp_theta = np.array([0.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0])
96
+ check_array_result(f"{title}|r", r, exp_r)
97
+ check_array_result(f"{title}|theta", theta, exp_theta)
98
+
99
+ r, theta = sigima.tools.coordinates.to_polar(x, y, unit="°")
100
+ exp_theta = np.array([0.0, 45.0, 45.0, 45.0, 45.0])
101
+ check_array_result(f"{title}|r", r, exp_r)
102
+ check_array_result(f"{title}|theta", theta, exp_theta)
103
+
104
+
105
+ def test_to_cartesian() -> None:
106
+ """Unit test for the polar to Cartesian conversion."""
107
+ title = "Polar2Cartesian"
108
+ r = np.array([0.0, np.sqrt(2.0), np.sqrt(8.0), np.sqrt(18.0), np.sqrt(32.0)])
109
+ theta = np.array([0.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0])
110
+
111
+ x, y = sigima.tools.coordinates.to_cartesian(r, theta, "rad")
112
+ exp_x = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
113
+ exp_y = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
114
+ check_array_result(f"{title}|x", x, exp_x)
115
+ check_array_result(f"{title}|y", y, exp_y)
116
+
117
+ theta = np.array([0.0, 45.0, 45.0, 45.0, 45.0])
118
+ x, y = sigima.tools.coordinates.to_cartesian(r, theta, unit="°")
119
+ check_array_result(f"{title}|x", x, exp_x)
120
+ check_array_result(f"{title}|y", y, exp_y)
121
+
122
+
123
+ @pytest.mark.validation
124
+ def test_signal_to_polar() -> None:
125
+ """Validation test for the signal Cartesian to polar processing."""
126
+ title = "Cartesian2Polar"
127
+ p = sigima.params.AngleUnitParam()
128
+ x = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
129
+ y = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
130
+ src = sigima.objects.create_signal("test", x, y)
131
+
132
+ for p.unit in sigima.enums.AngleUnit:
133
+ dst1 = sigima.proc.signal.to_polar(src, p)
134
+ dst2 = sigima.proc.signal.to_cartesian(dst1, p)
135
+ check_array_result(f"{title}|x", dst2.x, x)
136
+ check_array_result(f"{title}|y", dst2.y, y)
137
+
138
+
139
+ @pytest.mark.validation
140
+ def test_signal_to_cartesian() -> None:
141
+ """Validation test for the signal polar to Cartesian processing."""
142
+ title = "Polar2Cartesian"
143
+ p = sigima.params.AngleUnitParam()
144
+ r = np.array([0.0, np.sqrt(2.0), np.sqrt(8.0), np.sqrt(18.0), np.sqrt(32.0)])
145
+
146
+ a_deg = np.array([0.0, 45.0, 45.0, 45.0, 45.0])
147
+ a_rad = np.array([0.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0, np.pi / 4.0])
148
+ for p.unit in sigima.enums.AngleUnit:
149
+ theta = a_rad if p.unit == sigima.enums.AngleUnit.RADIAN else a_deg
150
+ src = sigima.objects.create_signal("test", r, theta)
151
+ dst1 = sigima.proc.signal.to_cartesian(src, p)
152
+ dst2 = sigima.proc.signal.to_polar(dst1, p)
153
+ check_array_result(f"{title}|x", dst2.x, r)
154
+ check_array_result(f"{title}|y", dst2.y, theta)
155
+
156
+
157
+ @pytest.mark.validation
158
+ def test_signal_normalize() -> None:
159
+ """Validation test for the signal normalization processing."""
160
+ src = get_test_signal("paracetamol.txt")
161
+ p = sigima.params.NormalizeParam()
162
+ src.y[10:15] = np.nan # Adding some NaN values to the signal
163
+
164
+ # Given the fact that the normalization methods implementations are
165
+ # straightforward, we do not need to compare arrays with each other,
166
+ # we simply need to check if some properties are satisfied.
167
+ for method in sigima.enums.NormalizationMethod:
168
+ p.method = method
169
+ dst = sigima.proc.signal.normalize(src, p)
170
+ title = f"Normalize[method='{p.method}']"
171
+ exp_min, exp_max = None, None
172
+ if p.method == sigima.enums.NormalizationMethod.MAXIMUM:
173
+ exp_min, exp_max = np.nanmin(src.data) / np.nanmax(src.data), 1.0
174
+ elif p.method == sigima.enums.NormalizationMethod.AMPLITUDE:
175
+ exp_min, exp_max = 0.0, 1.0
176
+ elif p.method == sigima.enums.NormalizationMethod.AREA:
177
+ area = np.nansum(src.data)
178
+ exp_min, exp_max = np.nanmin(src.data) / area, np.nanmax(src.data) / area
179
+ elif p.method == sigima.enums.NormalizationMethod.ENERGY:
180
+ energy = np.sqrt(np.nansum(np.abs(src.data) ** 2))
181
+ exp_min, exp_max = (
182
+ np.nanmin(src.data) / energy,
183
+ np.nanmax(src.data) / energy,
184
+ )
185
+ elif p.method == sigima.enums.NormalizationMethod.RMS:
186
+ rms = np.sqrt(np.nanmean(np.abs(src.data) ** 2))
187
+ exp_min, exp_max = np.nanmin(src.data) / rms, np.nanmax(src.data) / rms
188
+ check_scalar_result(f"{title}|min", np.nanmin(dst.data), exp_min)
189
+ check_scalar_result(f"{title}|max", np.nanmax(dst.data), exp_max)
190
+
191
+
192
+ @pytest.mark.validation
193
+ def test_signal_clip() -> None:
194
+ """Validation test for the signal clipping processing."""
195
+ src = get_test_signal("paracetamol.txt")
196
+ p = sigima.params.ClipParam()
197
+
198
+ for lower, upper in ((float("-inf"), float("inf")), (250.0, 500.0)):
199
+ p.lower, p.upper = lower, upper
200
+ dst = sigima.proc.signal.clip(src, p)
201
+ exp = np.clip(src.data, p.lower, p.upper)
202
+ check_array_result(f"Clip[{lower},{upper}]", dst.data, exp)
203
+
204
+
205
+ @pytest.mark.validation
206
+ def test_signal_derivative() -> None:
207
+ """Validation test for the signal derivative processing."""
208
+ src = get_test_signal("paracetamol.txt")
209
+ dst = sigima.proc.signal.derivative(src)
210
+ x, y = src.xydata
211
+
212
+ # Compute the derivative using a simple finite difference:
213
+ dx = x[1:] - x[:-1]
214
+ dy = y[1:] - y[:-1]
215
+ dydx = dy / dx
216
+ exp = np.zeros_like(y)
217
+ exp[0] = dydx[0]
218
+ exp[1:-1] = (dydx[:-1] * dx[1:] + dydx[1:] * dx[:-1]) / (dx[1:] + dx[:-1])
219
+ exp[-1] = dydx[-1]
220
+
221
+ check_array_result("Derivative", dst.y, exp)
222
+
223
+
224
+ @pytest.mark.validation
225
+ def test_signal_integral() -> None:
226
+ """Validation test for the signal integral processing."""
227
+ src = get_test_signal("paracetamol.txt")
228
+ src.data /= np.max(src.data)
229
+
230
+ # Check the integral of the derivative:
231
+ dst = sigima.proc.signal.integral(sigima.proc.signal.derivative(src))
232
+ # The integral of the derivative should be the original signal, up to a constant:
233
+ dst.y += src.y[0]
234
+
235
+ check_array_result("Integral[Derivative]", dst.y, src.y, atol=0.05)
236
+
237
+ dst = sigima.proc.signal.integral(src)
238
+ x, y = src.xydata
239
+
240
+ # Compute the integral using a simple trapezoidal rule:
241
+ exp = np.zeros_like(y)
242
+ exp[1:] = np.cumsum(0.5 * (y[1:] + y[:-1]) * (x[1:] - x[:-1]))
243
+ exp[0] = exp[1]
244
+
245
+ check_array_result("Integral", dst.y, exp, atol=0.05)
246
+
247
+
248
+ @pytest.mark.validation
249
+ def test_signal_detrending() -> None:
250
+ """Validation test for the signal detrending processing."""
251
+ src = get_test_signal("paracetamol.txt")
252
+ for method_value, _method_name in sigima.params.DetrendingParam.methods:
253
+ p = sigima.params.DetrendingParam.create(method=method_value)
254
+ dst = sigima.proc.signal.detrending(src, p)
255
+ exp = sps.detrend(src.data, type=p.method)
256
+ check_array_result(f"Detrending [method={p.method}]", dst.data, exp)
257
+
258
+
259
+ @pytest.mark.validation
260
+ def test_signal_offset_correction() -> None:
261
+ """Validation test for the signal offset correction processing."""
262
+ src = get_test_signal("paracetamol.txt")
263
+ # Defining the ROI that will be used to estimate the offset
264
+ imin, imax = 0, 20
265
+ p = sigima.objects.ROI1DParam.create(xmin=src.x[imin], xmax=src.x[imax])
266
+ dst = sigima.proc.signal.offset_correction(src, p)
267
+ exp = src.data - np.mean(src.data[imin:imax])
268
+ check_array_result("OffsetCorrection", dst.data, exp)
269
+
270
+
271
+ @pytest.mark.validation
272
+ def test_signal_gaussian_filter() -> None:
273
+ """Validation test for the signal Gaussian filter processing."""
274
+ src = get_test_signal("paracetamol.txt")
275
+ for sigma in (10.0, 50.0):
276
+ p = sigima.params.GaussianParam.create(sigma=sigma)
277
+ dst = sigima.proc.signal.gaussian_filter(src, p)
278
+ exp = spi.gaussian_filter(src.data, sigma=sigma)
279
+ check_array_result(f"GaussianFilter[sigma={sigma}]", dst.data, exp)
280
+
281
+
282
+ @pytest.mark.validation
283
+ def test_signal_moving_average() -> None:
284
+ """Validation test for the signal moving average processing."""
285
+ src = get_test_signal("paracetamol.txt")
286
+ p = sigima.params.MovingAverageParam.create(n=30)
287
+ for mode in sigima.enums.FilterMode:
288
+ p.mode = mode
289
+ dst = sigima.proc.signal.moving_average(src, p)
290
+ exp = spi.uniform_filter(src.data, size=p.n, mode=mode.value)
291
+
292
+ # Implementation note:
293
+ # --------------------
294
+ #
295
+ # The SciPy's `uniform_filter` handles the edges more accurately than
296
+ # a method based on a simple convolution with a kernel of ones like this:
297
+ # (the following function was the original implementation of the moving average
298
+ # in Sigima before it was replaced by the SciPy's `uniform_filter` function)
299
+ #
300
+ # def moving_average(y: np.ndarray, n: int) -> np.ndarray:
301
+ # y_padded = np.pad(y, (n // 2, n - 1 - n // 2), mode="edge")
302
+ # return np.convolve(y_padded, np.ones((n,)) / n, mode="valid")
303
+
304
+ check_array_result(f"MovingAvg[n={p.n},mode={p.mode}]", dst.data, exp, rtol=0.1)
305
+
306
+
307
+ @pytest.mark.validation
308
+ @pytest.mark.skipif(
309
+ Version("1.15.0") <= Version(scipy.__version__) <= Version("1.15.2"),
310
+ reason="Skipping test: scipy median_filter is broken in 1.15.0-1.15.2",
311
+ )
312
+ def test_signal_moving_median() -> None:
313
+ """Validation test for the signal moving median processing."""
314
+ src = get_test_signal("paracetamol.txt")
315
+ p = sigima.params.MovingMedianParam.create(n=15)
316
+ for mode in sigima.enums.FilterMode:
317
+ p.mode = mode
318
+ dst = sigima.proc.signal.moving_median(src, p)
319
+ exp = spi.median_filter(src.data, size=p.n, mode=mode.value)
320
+ check_array_result(f"MovingMed[n={p.n},mode={p.mode}]", dst.data, exp, rtol=0.1)
321
+
322
+
323
+ @pytest.mark.validation
324
+ def test_signal_wiener() -> None:
325
+ """Validation test for the signal Wiener filter processing."""
326
+ src = get_test_signal("paracetamol.txt")
327
+ dst = sigima.proc.signal.wiener(src)
328
+ exp = sps.wiener(src.data)
329
+ check_array_result("Wiener", dst.data, exp)
330
+
331
+
332
+ @pytest.mark.validation
333
+ def test_signal_resampling() -> None:
334
+ """Validation test for the signal resampling processing."""
335
+ src1 = sigima.tests.data.create_periodic_signal(
336
+ sigima.objects.SignalTypes.SINE, freq=50.0, size=5
337
+ )
338
+ x1, y1 = src1.xydata
339
+ p1 = sigima.params.Resampling1DParam.create(
340
+ xmin=src1.x[0], xmax=src1.x[-1], nbpts=src1.x.size
341
+ )
342
+ p1.update_from_obj(src1) # Just to test this method
343
+ dst1 = sigima.proc.signal.resampling(src1, p1)
344
+ dst1x, dst1y = dst1.xydata
345
+ check_array_result("x1new", dst1x, x1)
346
+ check_array_result("y1new", dst1y, y1)
347
+
348
+ src2 = sigima.tests.data.create_periodic_signal(
349
+ sigima.objects.SignalTypes.SINE, freq=50.0, size=9
350
+ )
351
+ p2 = sigima.params.Resampling1DParam.create(
352
+ xmin=src1.x[0], xmax=src1.x[-1], nbpts=src1.x.size
353
+ )
354
+ dst2 = sigima.proc.signal.resampling(src2, p2)
355
+ dst2x, dst2y = dst2.xydata
356
+ check_array_result("x2new", dst2x, x1)
357
+ check_array_result("y2new", dst2y, y1)
358
+
359
+
360
+ @pytest.mark.validation
361
+ def test_signal_xy_mode() -> None:
362
+ """Validation test for the signal X-Y mode processing."""
363
+ s1 = sigima.tests.data.create_periodic_signal(
364
+ sigima.objects.SignalTypes.COSINE, freq=50.0, size=5
365
+ )
366
+ s2 = sigima.tests.data.create_periodic_signal(
367
+ sigima.objects.SignalTypes.SINE, freq=50.0, size=5
368
+ )
369
+ dst = sigima.proc.signal.xy_mode(s1, s2)
370
+ x, y = dst.xydata
371
+ check_array_result("XYMode", x, s1.y)
372
+ check_array_result("XYMode", y, s2.y)
373
+ check_array_result("XYMode", x**2 + y**2, np.ones_like(x))
374
+
375
+ s1 = sigima.tests.data.create_periodic_signal(
376
+ sigima.objects.SignalTypes.COSINE, freq=50.0, size=9
377
+ )
378
+ s2 = sigima.tests.data.create_periodic_signal(
379
+ sigima.objects.SignalTypes.SINE, freq=50.0, size=5
380
+ )
381
+ dst = sigima.proc.signal.xy_mode(s1, s2)
382
+ x, y = dst.xydata
383
+ check_array_result("XYMode2", x, s1.y[::2])
384
+ check_array_result("XYMode2", y, s2.y)
385
+ check_array_result("XYMode2", x**2 + y**2, np.ones_like(x))
386
+
387
+
388
+ @pytest.mark.validation
389
+ def test_signal_histogram() -> None:
390
+ """Validation test for the signal histogram processing."""
391
+ # Create a test signal with known data for histogram analysis
392
+ src = sigima.tests.data.create_periodic_signal(
393
+ sigima.objects.SignalTypes.SINE, freq=50.0, size=1000, a=2.0
394
+ )
395
+
396
+ # Test with default parameters
397
+ p = sigima.params.HistogramParam()
398
+ p.bins = 50
399
+ p.lower = None
400
+ p.upper = None
401
+ dst = sigima.proc.signal.histogram(src, p)
402
+
403
+ # Validate result properties
404
+ x, y = dst.xydata
405
+
406
+ # Check that we got the expected number of bins
407
+ check_scalar_result("Histogram|bins", len(x), 50)
408
+ check_scalar_result("Histogram|bins", len(y), 50)
409
+
410
+ # Check that histogram sums to the total number of data points
411
+ check_scalar_result("Histogram|total_counts", np.sum(y), len(src.y))
412
+
413
+ # Check that all counts are non-negative
414
+ assert np.all(y >= 0), "Histogram counts should be non-negative"
415
+
416
+ # Check that x values are within the data range
417
+ data_min, data_max = np.min(src.y), np.max(src.y)
418
+ assert np.min(x) >= data_min, "Histogram x values should be >= data minimum"
419
+ assert np.max(x) <= data_max, "Histogram x values should be <= data maximum"
420
+
421
+ # Test with explicit range
422
+ p.lower = -1.0
423
+ p.upper = 1.0
424
+ p.bins = 20
425
+ dst2 = sigima.proc.signal.histogram(src, p)
426
+ x2, y2 = dst2.xydata
427
+
428
+ # Check that we got the expected number of bins
429
+ check_scalar_result("Histogram|explicit_range_bins", len(x2), 20)
430
+
431
+ # Check that x values are within the specified range
432
+ assert np.min(x2) >= -1.0, "Histogram x values should be >= lower limit"
433
+ assert np.max(x2) <= 1.0, "Histogram x values should be <= upper limit"
434
+
435
+ # Check that counts sum to the number of data points within the range
436
+ data_in_range = src.y[(src.y >= -1.0) & (src.y <= 1.0)]
437
+ check_scalar_result("Histogram|range_counts", np.sum(y2), len(data_in_range))
438
+
439
+ # Test with a simple known dataset by creating a signal manually
440
+ # Create a signal with known uniform distribution data
441
+ simple_sig = sigima.objects.create_signal(
442
+ "Test Signal",
443
+ np.linspace(0, 1, 100), # x values
444
+ np.linspace(0, 1, 100), # y values: uniform distribution from 0 to 1
445
+ )
446
+
447
+ p_uniform = sigima.params.HistogramParam()
448
+ p_uniform.bins = 10
449
+ p_uniform.lower = 0.0
450
+ p_uniform.upper = 1.0
451
+ dst_uniform = sigima.proc.signal.histogram(simple_sig, p_uniform)
452
+ _x_uniform, y_uniform = dst_uniform.xydata
453
+
454
+ # For the uniform data (0 to 1), each bin should have exactly 10 values
455
+ expected_count = 10
456
+ check_array_result(
457
+ "Histogram|uniform_counts", y_uniform, np.full(10, expected_count, dtype=float)
458
+ )
459
+
460
+ # Test edge case: single bin
461
+ p_single = sigima.params.HistogramParam()
462
+ p_single.bins = 1
463
+ dst_single = sigima.proc.signal.histogram(src, p_single)
464
+ x_single, y_single = dst_single.xydata
465
+ check_scalar_result("Histogram|single_bin_x_count", len(x_single), 1)
466
+ check_scalar_result("Histogram|single_bin_y_count", len(y_single), 1)
467
+ check_scalar_result("Histogram|single_bin_total", y_single[0], len(src.y))
468
+
469
+ # Test with binary data
470
+ binary_sig = sigima.objects.create_signal(
471
+ "Binary Signal",
472
+ np.arange(20), # x values
473
+ np.array([0] * 10 + [1] * 10), # 10 zeros, 10 ones
474
+ )
475
+ p_binary = sigima.params.HistogramParam()
476
+ p_binary.bins = 2
477
+ p_binary.lower = 0.0
478
+ p_binary.upper = 1.0
479
+ dst_binary = sigima.proc.signal.histogram(binary_sig, p_binary)
480
+ _x_binary, y_binary = dst_binary.xydata
481
+
482
+ # Should have 10 counts in each bin for our binary data
483
+ check_array_result("Histogram|binary_counts", y_binary, np.array([10.0, 10.0]))
484
+
485
+
486
+ @pytest.mark.validation
487
+ def test_signal_interpolate() -> None:
488
+ """Validation test for the signal interpolation processing."""
489
+ # Create test signals
490
+ x1 = np.array([0.0, 1.0, 2.0, 3.0, 4.0])
491
+ y1 = np.array([0.0, 1.0, 4.0, 9.0, 16.0]) # Quadratic function: y = x²
492
+ src1 = sigima.objects.create_signal("src1", x1, y1)
493
+
494
+ # Create target x-axis for interpolation (denser sampling)
495
+ x2 = np.array([0.5, 1.5, 2.5, 3.5])
496
+ y2 = np.zeros_like(x2) # Y values don't matter for interpolation target
497
+ src2 = sigima.objects.create_signal("src2", x2, y2)
498
+
499
+ p = sigima.params.InterpolationParam()
500
+
501
+ # Test linear interpolation
502
+ p.method = sigima.enums.Interpolation1DMethod.LINEAR
503
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
504
+ expected_linear = np.array([0.5, 2.5, 6.5, 12.5]) # Linear interpolation of x²
505
+ check_array_result("Interpolate[LINEAR]", dst.y, expected_linear)
506
+ check_array_result("Interpolate[LINEAR]|x", dst.x, x2)
507
+
508
+ # Test spline interpolation (should be exact for polynomial functions)
509
+ p.method = sigima.enums.Interpolation1DMethod.SPLINE
510
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
511
+ expected_spline = np.array([0.25, 2.25, 6.25, 12.25]) # Exact values for x²
512
+ check_array_result("Interpolate[SPLINE]", dst.y, expected_spline, atol=1e-10)
513
+ check_array_result("Interpolate[SPLINE]|x", dst.x, x2)
514
+
515
+ # Test quadratic interpolation (should be exact for polynomial functions)
516
+ p.method = sigima.enums.Interpolation1DMethod.QUADRATIC
517
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
518
+ expected_quadratic = np.array([0.25, 2.25, 6.25, 12.25]) # Exact values for x²
519
+ check_array_result("Interpolate[QUADRATIC]", dst.y, expected_quadratic, atol=1e-10)
520
+ check_array_result("Interpolate[QUADRATIC]|x", dst.x, x2)
521
+
522
+ # Test cubic interpolation
523
+ p.method = sigima.enums.Interpolation1DMethod.CUBIC
524
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
525
+ expected_cubic = np.array([0.25, 2.25, 6.25, 12.25]) # Should be exact for x²
526
+ check_array_result("Interpolate[CUBIC]", dst.y, expected_cubic, atol=1e-10)
527
+ check_array_result("Interpolate[CUBIC]|x", dst.x, x2)
528
+
529
+ # Test PCHIP interpolation
530
+ p.method = sigima.enums.Interpolation1DMethod.PCHIP
531
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
532
+ expected_pchip = np.array([0.3125, 2.21875, 6.23958333, 12.22916667])
533
+ check_array_result("Interpolate[PCHIP]", dst.y, expected_pchip, atol=1e-10)
534
+ check_array_result("Interpolate[PCHIP]|x", dst.x, x2)
535
+
536
+ # Test barycentric interpolation
537
+ p.method = sigima.enums.Interpolation1DMethod.BARYCENTRIC
538
+ dst = sigima.proc.signal.interpolate(src1, src2, p)
539
+ expected_barycentric = np.array([0.25, 2.25, 6.25, 12.25]) # Should be exact
540
+ check_array_result(
541
+ "Interpolate[BARYCENTRIC]", dst.y, expected_barycentric, atol=1e-10
542
+ )
543
+ check_array_result("Interpolate[BARYCENTRIC]|x", dst.x, x2)
544
+
545
+ # Test fill_value parameter with extrapolation
546
+ x2_extrap = np.array([-1.0, 0.5, 1.5, 5.0]) # Include points outside range
547
+ y2_extrap = np.zeros_like(x2_extrap)
548
+ src2_extrap = sigima.objects.create_signal("src2_extrap", x2_extrap, y2_extrap)
549
+
550
+ p.method = sigima.enums.Interpolation1DMethod.LINEAR
551
+ p.fill_value = -999.0 # Custom fill value for extrapolation
552
+ dst = sigima.proc.signal.interpolate(src1, src2_extrap, p)
553
+ expected_with_fill = np.array([-999.0, 0.5, 2.5, -999.0])
554
+ check_array_result("Interpolate[LINEAR+fill_value]", dst.y, expected_with_fill)
555
+ check_array_result("Interpolate[LINEAR+fill_value]|x", dst.x, x2_extrap)
556
+
557
+
558
+ @pytest.mark.validation
559
+ def test_signal_apply_window() -> None:
560
+ """Validation test for the signal windowing processing."""
561
+ # Create a test signal with known data
562
+ x = np.linspace(0, 10, 100)
563
+ y = np.ones_like(x) # Constant signal to make windowing effects visible
564
+ src = sigima.objects.create_signal("test_signal", x, y)
565
+
566
+ p = sigima.params.WindowingParam()
567
+
568
+ # Test HAMMING window (default)
569
+ p.method = sigima.enums.WindowingMethod.HAMMING
570
+ dst = sigima.proc.signal.apply_window(src, p)
571
+ expected_hamming = y * np.hamming(len(y))
572
+ check_array_result("ApplyWindow[HAMMING]", dst.y, expected_hamming)
573
+ check_array_result("ApplyWindow[HAMMING]|x", dst.x, x)
574
+
575
+ # Test BLACKMAN window
576
+ p.method = sigima.enums.WindowingMethod.BLACKMAN
577
+ dst = sigima.proc.signal.apply_window(src, p)
578
+ expected_blackman = y * np.blackman(len(y))
579
+ check_array_result("ApplyWindow[BLACKMAN]", dst.y, expected_blackman)
580
+ check_array_result("ApplyWindow[BLACKMAN]|x", dst.x, x)
581
+
582
+ # Test HANN window
583
+ p.method = sigima.enums.WindowingMethod.HANN
584
+ dst = sigima.proc.signal.apply_window(src, p)
585
+ expected_hann = y * np.hanning(len(y))
586
+ check_array_result("ApplyWindow[HANN]", dst.y, expected_hann)
587
+ check_array_result("ApplyWindow[HANN]|x", dst.x, x)
588
+
589
+ # Test GAUSSIAN window with custom sigma
590
+ p.method = sigima.enums.WindowingMethod.GAUSSIAN
591
+ p.sigma = 7.0
592
+ dst = sigima.proc.signal.apply_window(src, p)
593
+ expected_gaussian = y * scipy.signal.windows.gaussian(len(y), p.sigma)
594
+ check_array_result("ApplyWindow[GAUSSIAN]", dst.y, expected_gaussian)
595
+ check_array_result("ApplyWindow[GAUSSIAN]|x", dst.x, x)
596
+
597
+ # Test KAISER window with custom beta
598
+ p.method = sigima.enums.WindowingMethod.KAISER
599
+ p.beta = 14.0
600
+ dst = sigima.proc.signal.apply_window(src, p)
601
+ expected_kaiser = y * np.kaiser(len(y), p.beta)
602
+ check_array_result("ApplyWindow[KAISER]", dst.y, expected_kaiser)
603
+ check_array_result("ApplyWindow[KAISER]|x", dst.x, x)
604
+
605
+ # Test TUKEY window with custom alpha
606
+ p.method = sigima.enums.WindowingMethod.TUKEY
607
+ p.alpha = 0.5
608
+ dst = sigima.proc.signal.apply_window(src, p)
609
+ expected_tukey = y * scipy.signal.windows.tukey(len(y), p.alpha)
610
+ check_array_result("ApplyWindow[TUKEY]", dst.y, expected_tukey)
611
+ check_array_result("ApplyWindow[TUKEY]|x", dst.x, x)
612
+
613
+ # Test BARTLETT window
614
+ p.method = sigima.enums.WindowingMethod.BARTLETT
615
+ dst = sigima.proc.signal.apply_window(src, p)
616
+ expected_bartlett = y * np.bartlett(len(y))
617
+ check_array_result("ApplyWindow[BARTLETT]", dst.y, expected_bartlett)
618
+ check_array_result("ApplyWindow[BARTLETT]|x", dst.x, x)
619
+
620
+ # Verify windowing preserves edge values for certain windows
621
+ # Most windows should have zero or near-zero values at the edges
622
+ p.method = sigima.enums.WindowingMethod.HAMMING
623
+ dst = sigima.proc.signal.apply_window(src, p)
624
+ assert dst.y[0] < 0.1, "Hamming window should have small edge values"
625
+ assert dst.y[-1] < 0.1, "Hamming window should have small edge values"
626
+
627
+ # Verify windowing preserves the original x-axis
628
+ assert np.array_equal(dst.x, src.x), "X-axis should be preserved after windowing"
629
+
630
+ # Verify the signal object metadata is properly set
631
+ assert "Apply Window" in dst.title, (
632
+ "Result title should indicate windowing operation"
633
+ )
634
+
635
+
636
+ if __name__ == "__main__":
637
+ test_signal_calibration()
638
+ test_signal_transpose()
639
+ test_to_polar()
640
+ test_to_cartesian()
641
+ test_signal_to_polar()
642
+ test_signal_to_cartesian()
643
+ test_signal_reverse_x()
644
+ test_signal_normalize()
645
+ test_signal_clip()
646
+ test_signal_derivative()
647
+ test_signal_integral()
648
+ test_signal_offset_correction()
649
+ test_signal_gaussian_filter()
650
+ test_signal_moving_average()
651
+ test_signal_moving_median()
652
+ test_signal_wiener()
653
+ test_signal_resampling()
654
+ test_signal_xy_mode()
655
+ test_signal_histogram()
656
+ test_signal_interpolate()
657
+ test_signal_apply_window()