prtools 1.2.0__tar.gz → 1.2.1__tar.gz

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.
prtools-1.2.1/PKG-INFO ADDED
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.1
2
+ Name: prtools
3
+ Version: 1.2.1
4
+ Summary: Utility functions for image-based phase retrieval
5
+ Author: Andy Kee
6
+ License: MIT License
7
+
8
+ Copyright (c) 2023 Andy Kee
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/andykee/prtools
28
+ Project-URL: Documentation, https://andykee.github.io/prtools/
29
+ Project-URL: Bug Tracker, https://github.com/andykee/prtools/issues
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Intended Audience :: Science/Research
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Topic :: Scientific/Engineering
35
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
36
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
37
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
38
+ Classifier: Topic :: Scientific/Engineering :: Physics
39
+ Classifier: Topic :: Software Development
40
+ Classifier: Topic :: Software Development :: Libraries
41
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
42
+ Requires-Python: >=3.8
43
+ Description-Content-Type: text/x-rst
44
+ License-File: LICENSE
45
+ License-File: NOTICE
46
+ Requires-Dist: numpy
47
+ Requires-Dist: scipy
48
+
49
+ prtools
50
+ =======
51
+ |pypi version|
52
+
53
+ The prtools package implements functionality and tools that may be helpful
54
+ when performing image-based phase retrieval including:
55
+
56
+ * Image processing, reduction, and analysis
57
+ * Creating, fitting, and removing Zernike polynomials
58
+ * Drawing various shapes in arrays
59
+ * Computing statistics and optical simulation parameters
60
+
61
+ Installation
62
+ ------------
63
+ Install and update prtools using `pip`_:
64
+
65
+ .. code-block:: text
66
+
67
+ pip install prtools
68
+
69
+ Links
70
+ -----
71
+ * **Docs:** https://andykee.github.io/prtools/
72
+ * **Releases:** https://pypi.org/project/prtools/
73
+ * **Source:** https://github.com/andykee/prtools/
74
+ * **Issues:** https://github.com/andykee/prtools/issues/
75
+
76
+ .. _pip: https://pip.pypa.io/en/stable/getting-started/
77
+
78
+ .. |pypi version| image:: https://img.shields.io/pypi/v/prtools.svg
79
+ :target: https://pypi.python.org/pypi/prtools
@@ -20,7 +20,7 @@ Install and update prtools using `pip`_:
20
20
 
21
21
  Links
22
22
  -----
23
- * **Docs:** https://prtools.readthedocs.io/
23
+ * **Docs:** https://andykee.github.io/prtools/
24
24
  * **Releases:** https://pypi.org/project/prtools/
25
25
  * **Source:** https://github.com/andykee/prtools/
26
26
  * **Issues:** https://github.com/andykee/prtools/issues/
@@ -1,8 +1,8 @@
1
1
 
2
- __version__ = '1.2.0'
2
+ __version__ = '1.2.1'
3
3
 
4
4
  from prtools.array import (
5
- centroid, pad, boundary, rebin, rescale, normpow,
5
+ centroid, pad, subarray, boundary, rebin, rescale, normpow,
6
6
  shift, register, medfix
7
7
  )
8
8
 
@@ -10,7 +10,7 @@ from prtools.fourier import dft2, idft2
10
10
 
11
11
  from prtools.misc import (
12
12
  min_sampling, pixelscale_nyquist, radial_avg,
13
- translation_defocus, fft_shape, calcpsf
13
+ translation_defocus, fft_shape, calcpsf, find_wrapped
14
14
  )
15
15
 
16
16
  from prtools.segmented import hex_segments
@@ -160,6 +160,71 @@ def pad(a, shape, fill=0):
160
160
  return np.squeeze(out)
161
161
 
162
162
 
163
+ def subarray(a, shape, shift=(0,0)):
164
+ """Extract a contiguous subarray from a larger array.
165
+
166
+ The subarray is extracted about the center of the source array unless
167
+ a shift is specified.
168
+
169
+ Parameters
170
+ ----------
171
+ a : array_like
172
+ Source array
173
+ shape : array_like of ints
174
+ Shape of subarray array in ``(nrows, ncols)``.
175
+ shift : array_like of ints
176
+ Relative shift of the center of the subarray in ``(row, col)``.
177
+
178
+ Returns
179
+ -------
180
+ out : ndarray
181
+ Subarray extracted from the source array.
182
+
183
+ Examples
184
+ --------
185
+ .. plot::
186
+ :include-source:
187
+ :context: reset
188
+ :scale: 50
189
+
190
+ >>> circ = prtools.circle(shape=(128,128), radius=64)
191
+ >>> circ_subarray = prtools.subarray(circ, shape=(110,110))
192
+ >>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5,2))
193
+ >>> ax[0].imshow(circ, cmap='gray')
194
+ >>> ax[0].set_title('Original array')
195
+ >>> ax[1].imshow(circ_subarray, cmap='gray')
196
+ >>> ax[1].set_title('Subarray')
197
+
198
+ .. plot::
199
+ :include-source:
200
+ :context: reset
201
+ :scale: 50
202
+
203
+ >>> circ = prtools.circle(shape=(128,128), radius=64)
204
+ >>> circ_subarray = prtools.subarray(circ, shape=(64,64), shift=(32,32))
205
+ >>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5,2))
206
+ >>> ax[0].imshow(circ, cmap='gray')
207
+ >>> ax[0].set_title('Original array')
208
+ >>> ax[1].imshow(circ_subarray, cmap='gray')
209
+ >>> ax[1].set_title('Subarray')
210
+
211
+ """
212
+
213
+ a = np.asarray(a)
214
+ shape = np.asarray(shape)
215
+
216
+
217
+ rmin = a.shape[0]//2 - shape[0]//2 + shift[0]
218
+ cmin = a.shape[1]//2 - shape[1]//2 + shift[1]
219
+ rmax = rmin + shape[0]
220
+ cmax = cmin + shape[1]
221
+
222
+ if any((rmin<0, cmin<0, rmax>a.shape[0], cmax>a.shape[1])):
223
+ raise ValueError('window lies outside of array')
224
+
225
+ return a[rmin:rmax, cmin:cmax]
226
+
227
+
163
228
  def boundary(x, threshold=0):
164
229
  """Find bounding row and column indices of data within an array.
165
230
 
@@ -234,3 +234,42 @@ def pixelscale_nyquist(wave, f_number):
234
234
 
235
235
  """
236
236
  return f_number * wave / 2
237
+
238
+
239
+ def find_wrapped(opd, grad_thresh):
240
+ """Attempt to find phase wrapping using gradient edge detection while
241
+ automatically ignoring large gradients at mask edges.
242
+
243
+ Parameters
244
+ ----------
245
+ opd : array_like
246
+ OPD to detect wrapping in
247
+ grad_thresh : float
248
+ Threshold on magnitude of OPD gradient for determining wrapping
249
+
250
+ Returns
251
+ -------
252
+ wrapped : ndarray
253
+ Map of wrapped pixels
254
+ grad : ndarray
255
+ Gradient amplitude
256
+
257
+ """
258
+ opd = np.asarray(opd)
259
+
260
+ # compute gradient magnitude
261
+ gr, gc = np.gradient(opd)
262
+ G = np.sqrt(gr**2 + gc**2)
263
+
264
+ # compute mask to ignore gradient boundary
265
+ mask = np.zeros_like(opd)
266
+ mask[np.where(opd != 0)] = 1
267
+ grm, gcm = np.gradient(mask)
268
+ Gm = np.zeros_like(G)
269
+ Gm[np.where(np.sqrt(grm**2 + gcm**2) == 0)] = 1
270
+
271
+ grad = G * Gm
272
+ wrapped = np.zeros_like(grad)
273
+ wrapped[np.where(grad > grad_thresh)] = 1
274
+
275
+ return wrapped, grad
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.1
2
+ Name: prtools
3
+ Version: 1.2.1
4
+ Summary: Utility functions for image-based phase retrieval
5
+ Author: Andy Kee
6
+ License: MIT License
7
+
8
+ Copyright (c) 2023 Andy Kee
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/andykee/prtools
28
+ Project-URL: Documentation, https://andykee.github.io/prtools/
29
+ Project-URL: Bug Tracker, https://github.com/andykee/prtools/issues
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Intended Audience :: Science/Research
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Topic :: Scientific/Engineering
35
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
36
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
37
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
38
+ Classifier: Topic :: Scientific/Engineering :: Physics
39
+ Classifier: Topic :: Software Development
40
+ Classifier: Topic :: Software Development :: Libraries
41
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
42
+ Requires-Python: >=3.8
43
+ Description-Content-Type: text/x-rst
44
+ License-File: LICENSE
45
+ License-File: NOTICE
46
+ Requires-Dist: numpy
47
+ Requires-Dist: scipy
48
+
49
+ prtools
50
+ =======
51
+ |pypi version|
52
+
53
+ The prtools package implements functionality and tools that may be helpful
54
+ when performing image-based phase retrieval including:
55
+
56
+ * Image processing, reduction, and analysis
57
+ * Creating, fitting, and removing Zernike polynomials
58
+ * Drawing various shapes in arrays
59
+ * Computing statistics and optical simulation parameters
60
+
61
+ Installation
62
+ ------------
63
+ Install and update prtools using `pip`_:
64
+
65
+ .. code-block:: text
66
+
67
+ pip install prtools
68
+
69
+ Links
70
+ -----
71
+ * **Docs:** https://andykee.github.io/prtools/
72
+ * **Releases:** https://pypi.org/project/prtools/
73
+ * **Source:** https://github.com/andykee/prtools/
74
+ * **Issues:** https://github.com/andykee/prtools/issues/
75
+
76
+ .. _pip: https://pip.pypa.io/en/stable/getting-started/
77
+
78
+ .. |pypi version| image:: https://img.shields.io/pypi/v/prtools.svg
79
+ :target: https://pypi.python.org/pypi/prtools
@@ -1,8 +1,7 @@
1
1
  LICENSE
2
2
  NOTICE
3
3
  README.rst
4
- setup.cfg
5
- setup.py
4
+ pyproject.toml
6
5
  prtools/__init__.py
7
6
  prtools/array.py
8
7
  prtools/fourier.py
@@ -16,4 +15,5 @@ prtools.egg-info/PKG-INFO
16
15
  prtools.egg-info/SOURCES.txt
17
16
  prtools.egg-info/dependency_links.txt
18
17
  prtools.egg-info/requires.txt
19
- prtools.egg-info/top_level.txt
18
+ prtools.egg-info/top_level.txt
19
+ tests/test_array.py
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "prtools"
7
+ description = "Utility functions for image-based phase retrieval"
8
+ authors = [
9
+ {name = "Andy Kee"},
10
+ ]
11
+ readme = "README.rst"
12
+ requires-python = ">=3.8"
13
+ license = {file = "LICENSE"}
14
+ dependencies = [
15
+ "numpy",
16
+ "scipy",
17
+ ]
18
+ dynamic = ["version"]
19
+ classifiers = [
20
+ "Development Status :: 5 - Production/Stable",
21
+ "Intended Audience :: Science/Research",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python :: 3",
24
+ "Topic :: Scientific/Engineering",
25
+ "Topic :: Scientific/Engineering :: Astronomy",
26
+ "Topic :: Scientific/Engineering :: Image Processing",
27
+ "Topic :: Scientific/Engineering :: Mathematics",
28
+ "Topic :: Scientific/Engineering :: Physics",
29
+ "Topic :: Software Development",
30
+ "Topic :: Software Development :: Libraries",
31
+ "Topic :: Software Development :: Libraries :: Python Modules "
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/andykee/prtools"
36
+ Documentation = "https://andykee.github.io/prtools/"
37
+ "Bug Tracker" = "https://github.com/andykee/prtools/issues"
38
+
39
+ [tool.setuptools]
40
+ packages = ["prtools"]
41
+
42
+ [tool.setuptools.dynamic]
43
+ version = {attr = "prtools.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,45 @@
1
+ import warnings
2
+
3
+ import numpy as np
4
+
5
+ import prtools
6
+
7
+
8
+ def test_centroid():
9
+ x = np.zeros((5,5))
10
+ x[2,2] = 1
11
+ assert(np.array_equal(prtools.centroid(x), [2,2]))
12
+
13
+
14
+ def test_centroid_where():
15
+ x = np.zeros((5,5))
16
+ x[2,2] = 1
17
+ x[1,1] = 1
18
+ mask = np.ones_like(x)
19
+ mask[1,1] = 0
20
+ assert(np.array_equal(prtools.centroid(x, where=mask), [2,2]))
21
+
22
+
23
+ def test_centroid_nan():
24
+ x = np.zeros((5,5))
25
+ x[2,2] = 1
26
+ x[2,3] = np.nan
27
+ assert(np.array_equal(prtools.centroid(x), [2,2]))
28
+
29
+
30
+ x, _ = np.meshgrid(range(10), range(10))
31
+ x[2,2] = 100
32
+
33
+ def test_medfix():
34
+ m = np.zeros_like(x)
35
+ m[2,2] = 1
36
+ y = prtools.medfix(x, mask=m, kernel=(3,3))
37
+ assert(y[2,2] == 2)
38
+
39
+ def test_medfix_bigmask():
40
+ m = np.zeros_like(x)
41
+ m[2:6, 2:6] = 1
42
+ with warnings.catch_warnings():
43
+ warnings.simplefilter('error')
44
+ y = prtools.medfix(x, mask=m, kernel=(3,3))
45
+ assert(np.all(np.isnan(y[3:5,3:5])))
prtools-1.2.0/PKG-INFO DELETED
@@ -1,20 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: prtools
3
- Version: 1.2.0
4
- Summary: Utility functions for image-based phase retrieval
5
- Author: Andy Kee
6
- License: MIT
7
- Classifier: Development Status :: 4 - Beta
8
- Classifier: Intended Audience :: Science/Research
9
- Classifier: License :: OSI Approved :: BSD License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Topic :: Scientific/Engineering
12
- Classifier: Topic :: Scientific/Engineering :: Astronomy
13
- Classifier: Topic :: Scientific/Engineering :: Image Processing
14
- Classifier: Topic :: Scientific/Engineering :: Mathematics
15
- Classifier: Topic :: Scientific/Engineering :: Physics
16
- Classifier: Topic :: Software Development
17
- Classifier: Topic :: Software Development :: Libraries
18
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
- License-File: LICENSE
20
- License-File: NOTICE
@@ -1,20 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: prtools
3
- Version: 1.2.0
4
- Summary: Utility functions for image-based phase retrieval
5
- Author: Andy Kee
6
- License: MIT
7
- Classifier: Development Status :: 4 - Beta
8
- Classifier: Intended Audience :: Science/Research
9
- Classifier: License :: OSI Approved :: BSD License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Topic :: Scientific/Engineering
12
- Classifier: Topic :: Scientific/Engineering :: Astronomy
13
- Classifier: Topic :: Scientific/Engineering :: Image Processing
14
- Classifier: Topic :: Scientific/Engineering :: Mathematics
15
- Classifier: Topic :: Scientific/Engineering :: Physics
16
- Classifier: Topic :: Software Development
17
- Classifier: Topic :: Software Development :: Libraries
18
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
- License-File: LICENSE
20
- License-File: NOTICE
prtools-1.2.0/setup.cfg DELETED
@@ -1,24 +0,0 @@
1
- [metadata]
2
- name = prtools
3
- author = Andy Kee
4
- version = attr:prtools.__version__
5
- license = MIT
6
- description = Utility functions for image-based phase retrieval
7
- classifiers =
8
- Development Status :: 4 - Beta
9
- Intended Audience :: Science/Research
10
- License :: OSI Approved :: BSD License
11
- Programming Language :: Python :: 3
12
- Topic :: Scientific/Engineering
13
- Topic :: Scientific/Engineering :: Astronomy
14
- Topic :: Scientific/Engineering :: Image Processing
15
- Topic :: Scientific/Engineering :: Mathematics
16
- Topic :: Scientific/Engineering :: Physics
17
- Topic :: Software Development
18
- Topic :: Software Development :: Libraries
19
- Topic :: Software Development :: Libraries :: Python Modules
20
-
21
- [egg_info]
22
- tag_build =
23
- tag_date = 0
24
-
prtools-1.2.0/setup.py DELETED
@@ -1,9 +0,0 @@
1
- from setuptools import setup
2
-
3
- setup(
4
- name='prtools',
5
- install_requires=[
6
- 'numpy',
7
- 'scipy'
8
- ],
9
- )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes