surfacetopography 0.91.2__py3.6-linux-x86_64.egg

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 (129) hide show
  1. EGG-INFO/PKG-INFO +11 -0
  2. EGG-INFO/SOURCES.txt +96 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/native_libs.txt +1 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +6 -0
  7. EGG-INFO/top_level.txt +3 -0
  8. SurfaceTopography/ChangeLog.md +358 -0
  9. SurfaceTopography/Converters.py +197 -0
  10. SurfaceTopography/Generation.py +440 -0
  11. SurfaceTopography/HeightContainer.py +315 -0
  12. SurfaceTopography/IO/DI.py +261 -0
  13. SurfaceTopography/IO/FromFile.py +802 -0
  14. SurfaceTopography/IO/H5.py +79 -0
  15. SurfaceTopography/IO/IBW.py +176 -0
  16. SurfaceTopography/IO/MI.py +307 -0
  17. SurfaceTopography/IO/Matlab.py +106 -0
  18. SurfaceTopography/IO/NC.py +228 -0
  19. SurfaceTopography/IO/NPY.py +139 -0
  20. SurfaceTopography/IO/OPDx.py +885 -0
  21. SurfaceTopography/IO/Reader.py +389 -0
  22. SurfaceTopography/IO/__init__.py +241 -0
  23. SurfaceTopography/IO/__pycache__/DI.cpython-36.pyc +0 -0
  24. SurfaceTopography/IO/__pycache__/FromFile.cpython-36.pyc +0 -0
  25. SurfaceTopography/IO/__pycache__/H5.cpython-36.pyc +0 -0
  26. SurfaceTopography/IO/__pycache__/IBW.cpython-36.pyc +0 -0
  27. SurfaceTopography/IO/__pycache__/MI.cpython-36.pyc +0 -0
  28. SurfaceTopography/IO/__pycache__/Matlab.cpython-36.pyc +0 -0
  29. SurfaceTopography/IO/__pycache__/NC.cpython-36.pyc +0 -0
  30. SurfaceTopography/IO/__pycache__/NPY.cpython-36.pyc +0 -0
  31. SurfaceTopography/IO/__pycache__/OPDx.cpython-36.pyc +0 -0
  32. SurfaceTopography/IO/__pycache__/Reader.cpython-36.pyc +0 -0
  33. SurfaceTopography/IO/__pycache__/__init__.cpython-36.pyc +0 -0
  34. SurfaceTopography/Interpolation.py +30 -0
  35. SurfaceTopography/Nonuniform/Autocorrelation.py +161 -0
  36. SurfaceTopography/Nonuniform/Detrending.py +87 -0
  37. SurfaceTopography/Nonuniform/PowerSpectrum.py +178 -0
  38. SurfaceTopography/Nonuniform/ScalarParameters.py +140 -0
  39. SurfaceTopography/Nonuniform/VariableBandwidth.py +155 -0
  40. SurfaceTopography/Nonuniform/__init__.py +28 -0
  41. SurfaceTopography/Nonuniform/__pycache__/Autocorrelation.cpython-36.pyc +0 -0
  42. SurfaceTopography/Nonuniform/__pycache__/Detrending.cpython-36.pyc +0 -0
  43. SurfaceTopography/Nonuniform/__pycache__/PowerSpectrum.cpython-36.pyc +0 -0
  44. SurfaceTopography/Nonuniform/__pycache__/ScalarParameters.cpython-36.pyc +0 -0
  45. SurfaceTopography/Nonuniform/__pycache__/VariableBandwidth.cpython-36.pyc +0 -0
  46. SurfaceTopography/Nonuniform/__pycache__/__init__.cpython-36.pyc +0 -0
  47. SurfaceTopography/Nonuniform/__pycache__/common.cpython-36.pyc +0 -0
  48. SurfaceTopography/Nonuniform/common.py +95 -0
  49. SurfaceTopography/NonuniformLineScan.py +310 -0
  50. SurfaceTopography/Special.py +225 -0
  51. SurfaceTopography/Tools/__init__.py +28 -0
  52. SurfaceTopography/Tools/__pycache__/__init__.cpython-36.pyc +0 -0
  53. SurfaceTopography/Tools/__pycache__/common.cpython-36.pyc +0 -0
  54. SurfaceTopography/Tools/common.py +75 -0
  55. SurfaceTopography/Uniform/Autocorrelation.py +211 -0
  56. SurfaceTopography/Uniform/Detrending.py +155 -0
  57. SurfaceTopography/Uniform/Filtering.py +226 -0
  58. SurfaceTopography/Uniform/Interpolation.py +159 -0
  59. SurfaceTopography/Uniform/PowerSpectrum.py +197 -0
  60. SurfaceTopography/Uniform/ScalarParameters.py +173 -0
  61. SurfaceTopography/Uniform/VariableBandwidth.py +169 -0
  62. SurfaceTopography/Uniform/__init__.py +28 -0
  63. SurfaceTopography/Uniform/__pycache__/Autocorrelation.cpython-36.pyc +0 -0
  64. SurfaceTopography/Uniform/__pycache__/Detrending.cpython-36.pyc +0 -0
  65. SurfaceTopography/Uniform/__pycache__/Filtering.cpython-36.pyc +0 -0
  66. SurfaceTopography/Uniform/__pycache__/Interpolation.cpython-36.pyc +0 -0
  67. SurfaceTopography/Uniform/__pycache__/PowerSpectrum.cpython-36.pyc +0 -0
  68. SurfaceTopography/Uniform/__pycache__/ScalarParameters.cpython-36.pyc +0 -0
  69. SurfaceTopography/Uniform/__pycache__/VariableBandwidth.cpython-36.pyc +0 -0
  70. SurfaceTopography/Uniform/__pycache__/__init__.cpython-36.pyc +0 -0
  71. SurfaceTopography/Uniform/__pycache__/common.cpython-36.pyc +0 -0
  72. SurfaceTopography/Uniform/common.py +260 -0
  73. SurfaceTopography/UniformLineScanAndTopography.py +887 -0
  74. SurfaceTopography/__init__.py +62 -0
  75. SurfaceTopography/__pycache__/Converters.cpython-36.pyc +0 -0
  76. SurfaceTopography/__pycache__/Generation.cpython-36.pyc +0 -0
  77. SurfaceTopography/__pycache__/HeightContainer.cpython-36.pyc +0 -0
  78. SurfaceTopography/__pycache__/Interpolation.cpython-36.pyc +0 -0
  79. SurfaceTopography/__pycache__/NonuniformLineScan.cpython-36.pyc +0 -0
  80. SurfaceTopography/__pycache__/Special.cpython-36.pyc +0 -0
  81. SurfaceTopography/__pycache__/UniformLineScanAndTopography.cpython-36.pyc +0 -0
  82. SurfaceTopography/__pycache__/__init__.cpython-36.pyc +0 -0
  83. SurfaceTopography/__pycache__/common.cpython-36.pyc +0 -0
  84. SurfaceTopography/common.py +111 -0
  85. _SurfaceTopography.cpython-36m-x86_64-linux-gnu.so +0 -0
  86. _SurfaceTopography.py +8 -0
  87. __pycache__/_SurfaceTopography.cpython-36.pyc +0 -0
  88. test/IO/__init__.py +28 -0
  89. test/IO/__pycache__/__init__.cpython-36.pyc +0 -0
  90. test/IO/__pycache__/test_ibw.cpython-36.pyc +0 -0
  91. test/IO/__pycache__/test_io.cpython-36.pyc +0 -0
  92. test/IO/__pycache__/test_mi.cpython-36.pyc +0 -0
  93. test/IO/__pycache__/test_netcdf.cpython-36.pyc +0 -0
  94. test/IO/__pycache__/test_npy.cpython-36.pyc +0 -0
  95. test/IO/__pycache__/test_opdx.cpython-36.pyc +0 -0
  96. test/IO/test_ibw.py +178 -0
  97. test/IO/test_io.py +401 -0
  98. test/IO/test_mi.py +103 -0
  99. test/IO/test_netcdf.py +134 -0
  100. test/IO/test_npy.py +135 -0
  101. test/IO/test_opdx.py +441 -0
  102. test/__init__.py +26 -0
  103. test/__pycache__/__init__.cpython-36.pyc +0 -0
  104. test/__pycache__/compare-orientation-with-gwyddion.cpython-36.pyc +0 -0
  105. test/__pycache__/conftest.cpython-36.pyc +0 -0
  106. test/__pycache__/test_autocorrelation.cpython-36.pyc +0 -0
  107. test/__pycache__/test_bicubic.cpython-36.pyc +0 -0
  108. test/__pycache__/test_filtering.cpython-36.pyc +0 -0
  109. test/__pycache__/test_generation.cpython-36.pyc +0 -0
  110. test/__pycache__/test_import.cpython-36.pyc +0 -0
  111. test/__pycache__/test_make_sphere.cpython-36.pyc +0 -0
  112. test/__pycache__/test_power_spectrum.cpython-36.pyc +0 -0
  113. test/__pycache__/test_scalar_parameters.cpython-36.pyc +0 -0
  114. test/__pycache__/test_topography1.cpython-36.pyc +0 -0
  115. test/__pycache__/test_topography2.cpython-36.pyc +0 -0
  116. test/__pycache__/test_variable_bandwidth.cpython-36.pyc +0 -0
  117. test/compare-orientation-with-gwyddion.py +102 -0
  118. test/conftest.py +80 -0
  119. test/test_autocorrelation.py +311 -0
  120. test/test_bicubic.py +190 -0
  121. test/test_filtering.py +69 -0
  122. test/test_generation.py +259 -0
  123. test/test_import.py +54 -0
  124. test/test_make_sphere.py +108 -0
  125. test/test_power_spectrum.py +259 -0
  126. test/test_scalar_parameters.py +176 -0
  127. test/test_topography1.py +1287 -0
  128. test/test_topography2.py +328 -0
  129. test/test_variable_bandwidth.py +107 -0
@@ -0,0 +1,161 @@
1
+ #
2
+ # Copyright 2019-2020 Lars Pastewka
3
+ # 2019 Antoine Sanner
4
+ #
5
+ # ### MIT license
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+
26
+ """
27
+ Height-difference autocorrelation functions for nonuniform line scans
28
+ """
29
+
30
+ import numpy as np
31
+
32
+ import _SurfaceTopography
33
+
34
+ from ..HeightContainer import NonuniformLineScanInterface
35
+
36
+
37
+ def height_height_autocorrelation_1D(line_scan, distances=None):
38
+ r"""
39
+ Compute the one-dimensional height-height autocorrelation function
40
+ (ACF).
41
+
42
+ This function treats the nonuniform line scan as a piece-wise function of
43
+ straight lines between the data points. The ACF is computed exactly for
44
+ this piece-wise linear interpolation of the data.
45
+
46
+ Parameters
47
+ ----------
48
+ line_scan : :obj:`NonuniformLineScan`
49
+ Container storing the nonuniform line scan.
50
+ r : array_like
51
+ Array containing distances for which to compute the ACF. If no array
52
+ is given, the function will automatically construct an array with
53
+ equally spaced distances. (Default: None)
54
+
55
+ Returns
56
+ -------
57
+ distances : array
58
+ Distances. (Units: length)
59
+ A : array
60
+ Autocorrelation function. (Units: length**2)
61
+ """
62
+ size, = line_scan.physical_sizes
63
+ if distances is None:
64
+ # FIXME!!! We need a better heuristics to decide on the distances
65
+ res, = line_scan.nb_grid_pts
66
+ distances = np.linspace(0, size, res)
67
+ else:
68
+ distances = np.asarray(distances, dtype=float)
69
+ A = np.zeros_like(distances)
70
+
71
+ x, h = line_scan.positions_and_heights()
72
+ s = line_scan.derivative(1)
73
+ # FIXME!!! This is slow
74
+ for i in range(len(x) - 1):
75
+ for j in range(len(x) - 1):
76
+ # Determine lower and upper distance between segment i, i+1 and
77
+ # segment j, j+1
78
+ x1 = x[i]
79
+ x2 = x[j]
80
+ h1 = h[i]
81
+ h2 = h[j]
82
+ s1 = s[i]
83
+ s2 = s[j]
84
+ b1 = np.maximum(x1, x2 - distances)
85
+ b2 = np.minimum(x[i + 1], x[j + 1] - distances)
86
+ b = (b1 + b2) / 2
87
+ db = (b2 - b1) / 2
88
+ m = db > 0
89
+ if m.sum() > 0:
90
+ b = b[m]
91
+ db = db[m]
92
+ # f1[x_] := (h1 + s1*(x - x1))
93
+ # f2[x_] := (h2 + s2*(x - x2))
94
+ # FullSimplify[Integrate[f1[x]*f2[x + d],
95
+ # {x, b - db, b + db}]]
96
+ # = 2 * f1[b] * f2[b + d] * db + 2 * s1 * s2 * db ** 3 / 3
97
+ A[m] += 2 * (h1 + s1 * (b - x1)) * (
98
+ h2 + s2 * (b + distances[m] - x2)) * db + 2 * (
99
+ s1 * s2 * db ** 3) / 3
100
+ return distances, A
101
+
102
+
103
+ def height_difference_autocorrelation_1D(line_scan, algorithm='fft',
104
+ distances=None, ninterpolate=5):
105
+ r"""
106
+ Compute the one-dimensional height-difference autocorrelation function
107
+ (ACF).
108
+
109
+ This function treats the nonuniform line scan as a piece-wise function of
110
+ straight lines between the data points. The ACF is computed exactly for
111
+ this piece-wise linear interpolation of the data.
112
+
113
+ Parameters
114
+ ----------
115
+ line_scan : :obj:`NonuniformLineScan`
116
+ Container storing the nonuniform line scan.
117
+ algorithms : str
118
+ Algorithm to compute autocorrelation.
119
+ * 'fft': Interpolates the nonuniform line scan on a grid and then uses
120
+ the FFT to compute the autocorrelation. Scales O(N log N)
121
+ * 'brute-force': Brute-force computation using between line segements.
122
+ Scale O(N^2 M) where M is the number of distance point.
123
+ (Default: 'fft')
124
+ distances : array_like
125
+ Array containing distances for which to compute the ACF. If no array
126
+ is given, the function will automatically construct an array with
127
+ equally spaced distances. Can be used only if 'brute-force'
128
+ algorithm is used. (Default: None)
129
+ ninterpolate : int
130
+ Number of grid points to put between closest points on surface. Only
131
+ used for 'fft' algorithm. (Default: 5)
132
+
133
+ Returns
134
+ -------
135
+ distances : array
136
+ Distances. (Units: length)
137
+ A : array
138
+ Autocorrelation function. (Units: length**2)
139
+ """
140
+ s, = line_scan.physical_sizes
141
+ x, h = line_scan.positions_and_heights()
142
+ if algorithm == 'fft':
143
+ if distances is not None:
144
+ raise ValueError(
145
+ "`distances` can only be used with 'brute-force' algorithm.")
146
+ min_dist = np.min(np.diff(x))
147
+ if min_dist <= 0:
148
+ raise RuntimeError('Positions not sorted.')
149
+ return line_scan.to_uniform(ninterpolate * int(s / min_dist),
150
+ 0).autocorrelation_1D()
151
+ elif algorithm == 'brute-force':
152
+ return _SurfaceTopography.nonuniform_autocorrelation_1D(x, h, s,
153
+ distances)
154
+ else:
155
+ raise ValueError("Unknown algorithm '{}' specified."
156
+ .format(algorithm))
157
+
158
+
159
+ # Register analysis functions from this module
160
+ NonuniformLineScanInterface.register_function(
161
+ 'autocorrelation_1D', height_difference_autocorrelation_1D)
@@ -0,0 +1,87 @@
1
+ #
2
+ # Copyright 2018, 2020 Lars Pastewka
3
+ # 2019 Antoine Sanner
4
+ #
5
+ # ### MIT license
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+
26
+ """
27
+ Helper functions to compute trends of surfaces
28
+ """
29
+
30
+ import numpy as np
31
+
32
+
33
+ def polyfit(x, h, deg):
34
+ r"""
35
+ Compute the detrending plane that, if subtracted, minimizes the rms height
36
+ of the surface. The detrending plane is parameterized as a polynomial:
37
+
38
+ .. math::
39
+
40
+ p(x) = \sum_{k=0}^n a_k x^k
41
+
42
+ The values of :math:`a_k` are returned by this function.
43
+
44
+ The rms height of the surface is given by (see `rms_height`)
45
+
46
+ .. math::
47
+
48
+ h_\text{rms}^2 = \frac{1}{3L} \sum_{i=0}^{N-2} \left( h_i^2 + h_{i+1}^2 + h_i h_{i+1} \right) \Delta x_i
49
+
50
+ where :math:`N` is the total number of data points. Hence we need to solve the following minimization problem:
51
+
52
+ .. math::
53
+
54
+ \min_{\{a_k\}} \left\{ \frac{1}{3L} \sum_{i=0}^{N-2} \left[ (h_i - p(x_i))^2 + (h_{i+1} - p(x_{i+1}))^2 + (h_i - p(x_i))(h_{i+1} - p(x_{i+1})) \right] \Delta x_i \right\}
55
+
56
+ This gives the system of linear equations (one for each :math:`k`)
57
+
58
+ .. math::
59
+
60
+ \sum_{i=0}^{N-2} \left( \left[ 2h_i + h_{i+1} \right] x_i^k + \left[ 2h_{i+1} + h_i \right] x_{i+1}^k \right) \Delta x_i = \sum_{l=0}^n a_l \sum_{i=0}^{N-2} \left( 2x_i^{k+l} + 2x_{i+1}^{k+l} + x_i^k x_{i+1}^l + x_{i+1}^k x_i^l \right) \Delta x_i
61
+
62
+ Parameters
63
+ ----------
64
+ x : array_like
65
+ Array containing positions. This function assumes that this array is
66
+ sorted in ascending order.
67
+ h : array_like
68
+ Array containing heights.
69
+ deg : int
70
+ Degree of polynomial :math:`n`.
71
+
72
+ Returns
73
+ -------
74
+ a : array
75
+ Array with coefficients :math:`a_k`.
76
+ """ # noqa: E501
77
+ dx = np.diff(x)
78
+ k = np.arange(deg + 1).reshape(-1, 1)
79
+ b = np.sum(((2 * h[:-1] + h[1:]) * x[:-1] ** k +
80
+ (2 * h[1:] + h[:-1]) * x[1:] ** k) * dx,
81
+ axis=1)
82
+ L = k.reshape(1, -1, 1)
83
+ k = k.reshape(-1, 1, 1)
84
+ A = np.sum((2 * x[:-1] ** (k + L) + 2 * x[1:] ** (k + L) +
85
+ x[:-1] ** k * x[1:] ** L + x[1:] ** k * x[:-1] ** L) * dx,
86
+ axis=2)
87
+ return np.linalg.solve(A, b)
@@ -0,0 +1,178 @@
1
+ #
2
+ # Copyright 2018, 2020 Lars Pastewka
3
+ # 2019 Antoine Sanner
4
+ #
5
+ # ### MIT license
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+
26
+ """
27
+ Power-spectral density for nonuniform topographies.
28
+ """
29
+
30
+ import numpy as np
31
+
32
+ from ..HeightContainer import NonuniformLineScanInterface
33
+
34
+
35
+ def sinc(x):
36
+ """sinc function"""
37
+ return np.sinc(x / np.pi)
38
+
39
+
40
+ def dsinc(x):
41
+ """Derivative of the sinc function"""
42
+ tol = 1e-6
43
+ x = np.asarray(x)
44
+ small_values = np.abs(x) < tol
45
+ if small_values.sum() > 0:
46
+ ret = np.zeros_like(x)
47
+
48
+ # For small values, use the Taylor series expansion
49
+ # (accurate to O(x^^))
50
+ ret[small_values] = -x[small_values] / 3 + x[small_values] ** 3 / 30
51
+
52
+ # For large values, use the normal expression
53
+ large_values = np.logical_not(small_values)
54
+ ret[large_values] = (np.cos(x[large_values]) -
55
+ sinc(x[large_values])) / x[large_values]
56
+ return ret
57
+ else:
58
+ return (np.cos(x) - sinc(x)) / x
59
+
60
+
61
+ def ft_rectangle(q):
62
+ r"""
63
+ Fourier transform of a rectangle, :math:`f(x) = 1` for :math:`|x| < 1/2`,
64
+
65
+ .. math ::
66
+
67
+ \tilde{f}(q) = 2\sin(q/2)/q = sinc(q/2)
68
+ """
69
+ # np.sinc is sin(pi*x)/(pi*x), sinc is sin(x)/xCo
70
+ return sinc(q / 2)
71
+
72
+
73
+ def ft_one_sided_triangle(q):
74
+ r"""
75
+ Fourier transform of the one-sided triangle, :math:`f(x) = x` for
76
+ :math:`|x| < 1/2`,
77
+
78
+ .. math ::
79
+
80
+ \tilde{f}(q) = i [\cos(q/2)/q - 2\sin(q/2)/q^2] = d sinc(q/2)/dq
81
+
82
+ Returned value does not contain the factor of :math:`i`, i.e. this
83
+ function is real-valued.
84
+ """
85
+ return dsinc(q / 2) / 2
86
+
87
+
88
+ def apply_window(x, y, window=None):
89
+ if window == 'hann':
90
+ length = x.max() - x.min()
91
+ return (2 / 3) ** (1 / 2) * (1 - np.cos(2 * np.pi * x / length)) * y
92
+ elif window is None or window == 'None':
93
+ return y
94
+ else:
95
+ raise ValueError('Unknown window {}'.format(window))
96
+
97
+
98
+ def power_spectrum_1D(line_scan, algorithm='fft', wavevectors=None,
99
+ ninterpolate=5, window=None):
100
+ r"""
101
+ Compute power-spectral density (PSD) for a nonuniform topography. The
102
+ topography is assumed to be given by a series of points connected by
103
+ straight lines.
104
+
105
+ Parameters
106
+ ----------
107
+ line_scan : :obj:`NonuniformLineScan`
108
+ Container storing the nonuniform line scan.
109
+ algorithms : str
110
+ Algorithm to compute autocorrelation.
111
+ * 'fft': Interpolates the nonuniform line scan on a grid and then uses
112
+ the FFT to compute the autocorrelation. Scales O(N log N)
113
+ * 'brute-force': Brute-force computation using between line segements.
114
+ Scale O(N^2 M) where M is the number of distance point.
115
+ (Default: 'fft')
116
+ wavevectors : array, optional
117
+ Wavevectors at which to compute the PSD. If omitted, wavevectors are
118
+ equally spaced with a spacing that corresponds to :math:`2\pi/\lambda`
119
+ where :math:`\lambda` is the shortest distance between two points in
120
+ the `x`-array. (Default: None)
121
+ ninterpolate : int
122
+ Number of grid points to put between closest points on surface. Only
123
+ used for 'fft' algorithm. (Default: 5)
124
+ window : str, optional
125
+ Name of the window function to apply before computing the PSD.
126
+ Presently only supports Hann window ('hann') or no window (None or
127
+ 'None').
128
+ Default: no window for periodic Topographies, "hann" window for
129
+ nonperiodic Topographies
130
+
131
+ Returns
132
+ -------
133
+ q : array
134
+ Wavevector array at which the PSD has been computed.
135
+ C : array
136
+ PSD values.
137
+ """
138
+ if not line_scan.is_periodic and window is None:
139
+ window = "hann"
140
+
141
+ s, = line_scan.physical_sizes
142
+ x, y = line_scan.positions_and_heights()
143
+ if algorithm == 'fft':
144
+ if wavevectors is not None:
145
+ raise ValueError("`wavevectors` can only be used with "
146
+ "'brute-force' algorithm.")
147
+ min_dist = np.min(np.diff(x))
148
+ if min_dist <= 0:
149
+ raise RuntimeError('Positions not sorted.')
150
+ return line_scan.to_uniform(ninterpolate * int(s / min_dist),
151
+ 0).power_spectrum_1D(window=window)
152
+ elif algorithm == 'brute-force':
153
+ y = apply_window(x, y, window=window)
154
+ L = x[-1] - x[0]
155
+ if wavevectors is None:
156
+ wavevectors = 2 * np.pi * np.arange(int(L / np.diff(x).min())) / L
157
+ y_q = np.zeros_like(wavevectors, dtype=np.complex128)
158
+ for x1, x2, y1, y2 in zip(x[:-1], x[1:], y[:-1], y[1:]):
159
+ dx = x2 - x1
160
+ if dx > 0:
161
+ dy = y2 - y1
162
+ x0 = (x1 + x2) / 2
163
+ y0 = (y1 + y2) / 2
164
+ y_q += dx * (y0 * ft_rectangle(wavevectors * dx) + 1j * dy *
165
+ ft_one_sided_triangle(wavevectors * dx)) * np.exp(
166
+ -1j * x0 * wavevectors)
167
+ else:
168
+ raise ValueError('Nonuniform data points must be sorted in '
169
+ 'order of ascending x-values.')
170
+ return wavevectors, np.abs(y_q) ** 2 / L
171
+ else:
172
+ raise ValueError("Unknown algorithm '{}' specified."
173
+ .format(algorithm))
174
+
175
+
176
+ # Register analysis functions from this module
177
+ NonuniformLineScanInterface.register_function('power_spectrum_1D',
178
+ power_spectrum_1D)
@@ -0,0 +1,140 @@
1
+ #
2
+ # Copyright 2015-2016, 2018, 2020 Lars Pastewka
3
+ # 2018-2019 Antoine Sanner
4
+ # 2015-2016 Till Junge
5
+ #
6
+ # ### MIT license
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ # SOFTWARE.
25
+ #
26
+
27
+ """
28
+ Functions computing scalar roughness parameters
29
+ """
30
+
31
+ import numpy as np
32
+
33
+ from ..HeightContainer import NonuniformLineScanInterface
34
+
35
+
36
+ def rms_height(topography, kind='Rq', tol=1e-6):
37
+ r"""
38
+ Computes root-mean square height fluctuation of the line scan:
39
+
40
+ .. math::
41
+
42
+ h_\text{rms} = \left[\frac{1}{L} \int_0^L dx\, h^2(x)\right]^{1/2}
43
+
44
+ Function approximates topography between data points as piece-wise linear.
45
+ The piece-wise linear section between point :math:`i` and point
46
+ :math:`i+1` contributes
47
+
48
+ .. math::
49
+
50
+ \int_{0}^{\Delta x_i} dx\, \left( h_i + \frac{\Delta h_i}{\Delta x_i} x \right)^2 = \frac{1}{3} \left( h_i^2 + h_{i+1}^2 + h_i h_{i+1} \right) \Delta x_i
51
+
52
+ to the above integral, where :math:`\Delta x_i=x_{i+1}-x_i` and :math:`\Delta h_i=h_{i+1}-h_i`.
53
+
54
+ Parameters
55
+ ----------
56
+ topography : :obj:`NonuniformLineScan`
57
+ SurfaceTopography object containing height information.
58
+ kind : str
59
+ For compatibility with uniform topographies that have different ways
60
+ of computing the rms height. Only 'Rq' is supported here.
61
+ (Default: 'Rq')
62
+ tol : float
63
+ Tolerance for searching for existing data points at domain boundaries.
64
+ (Default: 1e-6)
65
+
66
+ Returns
67
+ -------
68
+ rms_height : float or array
69
+ Root-mean square height.
70
+ """ # noqa: E501
71
+ if kind != 'Rq':
72
+ raise ValueError("Unsupported rms height kind '{}'.".format(kind))
73
+ x, h = topography.positions_and_heights()
74
+ dx = np.diff(x)
75
+ if len(x) <= 1:
76
+ return 0.0
77
+ L = x[-1] - x[0]
78
+ h0 = h - topography.mean()
79
+ return np.sqrt(
80
+ np.sum((h0[:-1] ** 2 + h0[1:] ** 2 + h0[:-1] * h0[1:]) * dx) / (3 * L))
81
+
82
+
83
+ def rms_slope(topography):
84
+ r"""
85
+ Computes root-mean square slope fluctuation of the line scan:
86
+
87
+ .. math:: h^\prime_\text{rms} = \left[ \frac{1}{L} \int_0^L dx\, \left(\frac{\partial h}{\partial x}\right)^2 \right]^{1/2}
88
+
89
+ Function approximates topography between data points as piece-wise linear.
90
+ The piece-wise linear section between point :math:`i` and point
91
+ :math:`i+1` contributes
92
+
93
+ .. math:: \int_{0}^{\Delta x_i} dx\, \left( \frac{\Delta h_i}{\Delta x_i} \right)^2 = \frac{\Delta h_i^2}{\Delta x_i}
94
+
95
+ where :math:`\Delta x_i=x_{i+1}-x_i` and :math:`\Delta h_i=h_{i+1}-h_i` to the above integral.
96
+
97
+ Parameters
98
+ ----------
99
+ topography : :obj:`NonuniformLineScan`
100
+ SurfaceTopography object containing height information.
101
+
102
+ Returns
103
+ -------
104
+ rms_slope : float
105
+ Root-mean square slope.
106
+ """ # noqa: E501
107
+ x, h = topography.positions_and_heights()
108
+ dh = np.diff(h)
109
+ dx = np.diff(x)
110
+ L = x[-1] - x[0]
111
+
112
+ return np.sqrt(np.sum(dh ** 2 / dx) / L)
113
+
114
+
115
+ def rms_curvature(topography):
116
+ r"""
117
+ Computes root-mean square slope fluctuation of the line scan:
118
+
119
+ Parameters
120
+ ----------
121
+ topography : :obj:`NonuniformLineScan`
122
+ SurfaceTopography object containing height information.
123
+
124
+ Returns
125
+ -------
126
+ rms_slope : float
127
+ Root-mean square slope.
128
+ """
129
+ x = topography.positions()
130
+ d2 = topography.derivative(n=2)
131
+ # The second derivative cannot be evaluated on the two end points
132
+ L = x[-2] - x[1]
133
+
134
+ return np.sqrt(np.trapz(d2 ** 2, x[1:-1]) / L)
135
+
136
+
137
+ # Register analysis functions from this module
138
+ NonuniformLineScanInterface.register_function('rms_height', rms_height)
139
+ NonuniformLineScanInterface.register_function('rms_slope', rms_slope)
140
+ NonuniformLineScanInterface.register_function('rms_curvature', rms_curvature)