Skip to content

Commit 4bee8b5

Browse files
authored
Polygon resample (#116)
* More robust Polygon.resample using shapely segmentize/iterpolate
1 parent cd7b118 commit 4bee8b5

17 files changed

+119
-143
lines changed

.readthedocs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
version: 2
88

99
build:
10-
os: ubuntu-20.04
10+
os: ubuntu-22.04
1111
tools:
12-
python: "3.9"
12+
python: "3.12"
1313

1414
# Build documentation in the docs/ directory with Sphinx
1515
sphinx:

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# -- Project information -----------------------------------------------------
1919

2020
project = "SuperScreen"
21-
copyright = "2021-2023, Logan Bishop-Van Horn"
21+
copyright = "2021-2024, Logan Bishop-Van Horn"
2222
author = "Logan Bishop-Van Horn"
2323

2424

docs/images/logo_currents.png

9.82 KB
Loading

docs/images/logo_currents_small.png

2.71 KB
Loading

docs/images/logo_fields.png

6.85 KB
Loading

docs/images/logo_streams.png

1.69 KB
Loading
1.4 KB
Loading

docs/images/logo_terminal_streams.png

-10.9 KB
Loading

docs/notebooks/field-sources.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
{
8888
"data": {
8989
"text/html": [
90-
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>SuperScreen</td><td>0.11.0</td></tr><tr><td>Numpy</td><td>1.23.3</td></tr><tr><td>Numba</td><td>0.57.0</td></tr><tr><td>SciPy</td><td>1.9.1</td></tr><tr><td>matplotlib</td><td>3.6.0</td></tr><tr><td>IPython</td><td>8.5.0</td></tr><tr><td>Python</td><td>3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:01:00) \n",
91-
"[Clang 13.0.1 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Aug 28 20:27:01 2024 EDT</td></tr></table>"
90+
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>SuperScreen</td><td>0.12.0</td></tr><tr><td>Numpy</td><td>1.23.3</td></tr><tr><td>Numba</td><td>0.57.0</td></tr><tr><td>SciPy</td><td>1.9.1</td></tr><tr><td>matplotlib</td><td>3.6.0</td></tr><tr><td>IPython</td><td>8.5.0</td></tr><tr><td>Python</td><td>3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:01:00) \n",
91+
"[Clang 13.0.1 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Nov 06 20:46:15 2024 EST</td></tr></table>"
9292
],
9393
"text/plain": [
9494
"<IPython.core.display.HTML object>"
@@ -142,9 +142,9 @@
142142
"name": "stdout",
143143
"output_type": "stream",
144144
"text": [
145-
"x = 0.5515966127155993\n",
146-
"y = 0.16925251669093266\n",
147-
"z = 0.9275080254523002\n",
145+
"x = 0.7292460794150782\n",
146+
"y = 0.3839142913160034\n",
147+
"z = 0.9297509883825962\n",
148148
"field(x, y, z) = 5.0\n"
149149
]
150150
}

docs/notebooks/logo.ipynb

+14-14
Large diffs are not rendered by default.

docs/notebooks/polygons.ipynb

+4-4
Large diffs are not rendered by default.

docs/notebooks/quickstart.ipynb

+31-31
Large diffs are not rendered by default.

docs/notebooks/scanning-squid.ipynb

+10-10
Large diffs are not rendered by default.

docs/notebooks/terminal-currents.ipynb

+42-57
Large diffs are not rendered by default.

superscreen/device/polygon.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import matplotlib.pyplot as plt
77
import numpy as np
88
from matplotlib import path
9-
from scipy import interpolate
109
from shapely import affinity
1110
from shapely import geometry as geo
1211
from shapely.validation import explain_validity
@@ -481,9 +480,7 @@ def buffer(
481480
return polygon
482481
return polygon.points
483482

484-
def resample(
485-
self, num_points: Optional[int] = None, degree: int = 1, smooth: float = 0
486-
) -> "Polygon":
483+
def resample(self, num_points: Optional[int] = None) -> "Polygon":
487484
"""Resample vertices so that they are approximately uniformly distributed
488485
along the polygon boundary.
489486
@@ -492,25 +489,19 @@ def resample(
492489
the polygon is resampled to ``len(self.points)`` points. If
493490
``num_points`` is not None and has a boolean value of False,
494491
then an unaltered copy of the polygon is returned.
495-
degree: The degree of the spline with which to iterpolate.
496-
Defaults to 1 (linear spline).
497-
smooth: Smoothing condition.
498-
499492
"""
500493
if num_points is None:
501-
num_points = self.points.shape[0]
494+
num_points = len(self.points)
502495
if not num_points:
503496
return self.copy()
504-
points = self.points.copy()
505-
_, ix = np.unique(points, return_index=True, axis=0)
506-
points = close_curve(points[np.sort(ix)])
507-
tck, _ = interpolate.splprep(points.T, k=degree, s=smooth)
508-
x, y = interpolate.splev(np.linspace(0, 1, num_points), tck)
509-
points = close_curve(np.stack([x, y], axis=1))
497+
boundary = self.polygon.boundary
498+
new_points = boundary.segmentize(boundary.length / num_points).interpolate(
499+
np.linspace(0, 1, num_points), normalized=True
500+
)
510501
return Polygon(
511502
name=self.name,
512503
layer=self.layer,
513-
points=points,
504+
points=new_points,
514505
)
515506

516507
def plot(self, ax: Optional[plt.Axes] = None, **kwargs) -> plt.Axes:

superscreen/test/test_solution.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ def test_fluxoid_simply_connected(
226226
total_vortex_flux += (vortex.nPhi0 * ureg("Phi_0")).to(units).magnitude
227227
if total_vortex_flux:
228228
# There are vortices in the region.
229-
assert (abs(total_fluxoid - total_vortex_flux) / abs(total_vortex_flux)) < 5e-2
229+
assert (abs(total_fluxoid - total_vortex_flux) / abs(total_vortex_flux)) < 8e-2
230230
else:
231231
# No vortices - fluxoid should be zero.
232-
assert abs(total_fluxoid) / abs(flux_part) < 5e-2
232+
assert abs(total_fluxoid) / abs(flux_part) < 8e-2
233233

234234

235235
@pytest.mark.parametrize("units, with_units", [("uA / um", False), (None, True)])

superscreen/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version_info__ = (0, 11, 0)
1+
__version_info__ = (0, 12, 0)
22
__version__ = ".".join(map(str, __version_info__))

0 commit comments

Comments
 (0)