polargrid-mapping 0.1.0__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.
- polargrid_mapping-0.1.0/LICENSE.txt +19 -0
- polargrid_mapping-0.1.0/PKG-INFO +45 -0
- polargrid_mapping-0.1.0/README.md +33 -0
- polargrid_mapping-0.1.0/pyproject.toml +18 -0
- polargrid_mapping-0.1.0/setup.cfg +4 -0
- polargrid_mapping-0.1.0/src/polargrid/__init__.py +4 -0
- polargrid_mapping-0.1.0/src/polargrid/core.py +83 -0
- polargrid_mapping-0.1.0/src/polargrid/utils.py +63 -0
- polargrid_mapping-0.1.0/src/polargrid_mapping.egg-info/PKG-INFO +45 -0
- polargrid_mapping-0.1.0/src/polargrid_mapping.egg-info/SOURCES.txt +11 -0
- polargrid_mapping-0.1.0/src/polargrid_mapping.egg-info/dependency_links.txt +1 -0
- polargrid_mapping-0.1.0/src/polargrid_mapping.egg-info/requires.txt +2 -0
- polargrid_mapping-0.1.0/src/polargrid_mapping.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polargrid-mapping
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generate structured grids from scattered 2D points using convex hull layering
|
|
5
|
+
Author-email: ArmanddeCacqueray <armanddecacqueray@sfr.fr>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: scipy
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
\# polargrid
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Generate structured square grids from scattered 2D points using convex hull layering.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
\## Installation
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
|
|
27
|
+
pip install polargrid
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
import numpy as np
|
|
32
|
+
|
|
33
|
+
from polargrid import polargrid
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
points = np.random.rand(1000, 2)
|
|
38
|
+
|
|
39
|
+
grid = polargrid(points)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
points are now structured as a perfect grid, such that grid\[i, j] is the point with index i, j
|
|
44
|
+
|
|
45
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
\# polargrid
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Generate structured square grids from scattered 2D points using convex hull layering.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
\## Installation
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
|
|
15
|
+
pip install polargrid
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from polargrid import polargrid
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
points = np.random.rand(1000, 2)
|
|
26
|
+
|
|
27
|
+
grid = polargrid(points)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
points are now structured as a perfect grid, such that grid\[i, j] is the point with index i, j
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "polargrid-mapping"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Generate structured grids from scattered 2D points using convex hull layering"
|
|
9
|
+
authors = [{ name = "ArmanddeCacqueray", email = "armanddecacqueray@sfr.fr" }]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"numpy",
|
|
14
|
+
"scipy"
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["src"]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.spatial import ConvexHull
|
|
3
|
+
from .utils import select, approx
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def polargrid(points: np.ndarray) -> np.ndarray:
|
|
7
|
+
"""
|
|
8
|
+
Generate a structured square grid from scattered 2D points
|
|
9
|
+
using convex hull layering.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
points : ndarray of shape (N, 2)
|
|
14
|
+
Input 2D points.
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
grid : ndarray of shape (n, n, 2)
|
|
19
|
+
Structured grid of points.
|
|
20
|
+
"""
|
|
21
|
+
pts = points - points.mean(axis=0)
|
|
22
|
+
|
|
23
|
+
N = len(pts)
|
|
24
|
+
nn, n, layersizes = approx(N)
|
|
25
|
+
pts = pts[:nn]
|
|
26
|
+
|
|
27
|
+
x, y = pts[:, 0], pts[:, 1]
|
|
28
|
+
thetas = np.arctan2(y, x)
|
|
29
|
+
thetas0 = np.abs(thetas)
|
|
30
|
+
|
|
31
|
+
grid = np.zeros((n, n, 2))
|
|
32
|
+
remaining_idx = np.arange(nn)
|
|
33
|
+
|
|
34
|
+
for lsize in layersizes:
|
|
35
|
+
temp_idx = remaining_idx.copy()
|
|
36
|
+
layer = []
|
|
37
|
+
|
|
38
|
+
empty = False
|
|
39
|
+
while (len(layer) < 1.3 * lsize) and (not empty):
|
|
40
|
+
if len(temp_idx) > 2:
|
|
41
|
+
hull = ConvexHull(pts[temp_idx]).vertices
|
|
42
|
+
else:
|
|
43
|
+
hull = np.arange(len(temp_idx))
|
|
44
|
+
empty = True
|
|
45
|
+
|
|
46
|
+
hull_global = temp_idx[hull]
|
|
47
|
+
layer += list(hull_global)
|
|
48
|
+
|
|
49
|
+
mask = np.zeros(len(temp_idx), dtype=bool)
|
|
50
|
+
mask[hull] = True
|
|
51
|
+
temp_idx = temp_idx[~mask]
|
|
52
|
+
|
|
53
|
+
layer = np.array(layer)
|
|
54
|
+
|
|
55
|
+
# angular sort
|
|
56
|
+
layer = layer[np.argsort(thetas[layer])]
|
|
57
|
+
|
|
58
|
+
# thinning
|
|
59
|
+
thinning = select(thetas[layer], lsize)
|
|
60
|
+
layer = layer[thinning]
|
|
61
|
+
|
|
62
|
+
# rotate
|
|
63
|
+
start_idx = np.argmin(thetas0[layer])
|
|
64
|
+
layer = np.roll(layer, -start_idx)
|
|
65
|
+
|
|
66
|
+
# insert
|
|
67
|
+
if lsize != 1:
|
|
68
|
+
d = lsize // 4
|
|
69
|
+
indices = [i * d for i in range(4)] + [lsize]
|
|
70
|
+
pl = pts[layer]
|
|
71
|
+
segments = [pl[slice(indices[i], indices[i + 1])] for i in range(4)]
|
|
72
|
+
|
|
73
|
+
L = (n - (d + 1)) // 2
|
|
74
|
+
R = L + d
|
|
75
|
+
|
|
76
|
+
grid[L:R, L] = segments[0]
|
|
77
|
+
grid[R, L:R] = segments[1]
|
|
78
|
+
grid[R:L:-1, R] = segments[2]
|
|
79
|
+
grid[L, R:L:-1] = segments[3]
|
|
80
|
+
|
|
81
|
+
remaining_idx = np.setdiff1d(remaining_idx, layer)
|
|
82
|
+
|
|
83
|
+
return grid
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def select(input_array, size):
|
|
6
|
+
input_array = np.asarray(input_array)
|
|
7
|
+
n = len(input_array)
|
|
8
|
+
|
|
9
|
+
order = np.argsort(input_array)
|
|
10
|
+
sorted_input = input_array[order]
|
|
11
|
+
|
|
12
|
+
target = np.linspace(sorted_input[0], sorted_input[-1], size)
|
|
13
|
+
j = np.searchsorted(sorted_input, target)
|
|
14
|
+
|
|
15
|
+
left = np.clip(j - 1, 0, n - 1)
|
|
16
|
+
right = np.clip(j, 0, n - 1)
|
|
17
|
+
|
|
18
|
+
dist_left = np.abs(sorted_input[left] - target)
|
|
19
|
+
dist_right = np.abs(sorted_input[right] - target)
|
|
20
|
+
|
|
21
|
+
selected = np.where(dist_right < dist_left, right, left)
|
|
22
|
+
|
|
23
|
+
used = np.zeros(n, dtype=bool)
|
|
24
|
+
result = np.empty(size, dtype=int)
|
|
25
|
+
|
|
26
|
+
for i, idx in enumerate(selected):
|
|
27
|
+
if not used[idx]:
|
|
28
|
+
used[idx] = True
|
|
29
|
+
result[i] = idx
|
|
30
|
+
continue
|
|
31
|
+
|
|
32
|
+
l = idx - 1
|
|
33
|
+
r = idx + 1
|
|
34
|
+
|
|
35
|
+
while True:
|
|
36
|
+
if l >= 0 and not used[l]:
|
|
37
|
+
used[l] = True
|
|
38
|
+
result[i] = l
|
|
39
|
+
break
|
|
40
|
+
if r < n and not used[r]:
|
|
41
|
+
used[r] = True
|
|
42
|
+
result[i] = r
|
|
43
|
+
break
|
|
44
|
+
l -= 1
|
|
45
|
+
r += 1
|
|
46
|
+
|
|
47
|
+
return np.sort(order[result])
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def approx(N):
|
|
51
|
+
n = int(math.sqrt(N))
|
|
52
|
+
|
|
53
|
+
is_even = (n % 2 == 0)
|
|
54
|
+
l = n // 2
|
|
55
|
+
|
|
56
|
+
idx = np.arange(1, l + 1)
|
|
57
|
+
if is_even:
|
|
58
|
+
layersizes = 8 * idx - 4
|
|
59
|
+
else:
|
|
60
|
+
layersizes = np.concatenate([[1], 8 * idx])
|
|
61
|
+
|
|
62
|
+
nn = n ** 2
|
|
63
|
+
return nn, n, layersizes[::-1]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polargrid-mapping
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Generate structured grids from scattered 2D points using convex hull layering
|
|
5
|
+
Author-email: ArmanddeCacqueray <armanddecacqueray@sfr.fr>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: scipy
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
\# polargrid
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Generate structured square grids from scattered 2D points using convex hull layering.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
\## Installation
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
|
|
27
|
+
pip install polargrid
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
import numpy as np
|
|
32
|
+
|
|
33
|
+
from polargrid import polargrid
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
points = np.random.rand(1000, 2)
|
|
38
|
+
|
|
39
|
+
grid = polargrid(points)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
points are now structured as a perfect grid, such that grid\[i, j] is the point with index i, j
|
|
44
|
+
|
|
45
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/polargrid/__init__.py
|
|
5
|
+
src/polargrid/core.py
|
|
6
|
+
src/polargrid/utils.py
|
|
7
|
+
src/polargrid_mapping.egg-info/PKG-INFO
|
|
8
|
+
src/polargrid_mapping.egg-info/SOURCES.txt
|
|
9
|
+
src/polargrid_mapping.egg-info/dependency_links.txt
|
|
10
|
+
src/polargrid_mapping.egg-info/requires.txt
|
|
11
|
+
src/polargrid_mapping.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polargrid
|