Skip to content

Commit

Permalink
Polygon resample (#116)
Browse files Browse the repository at this point in the history
* More robust Polygon.resample using shapely segmentize/iterpolate
  • Loading branch information
loganbvh authored Nov 9, 2024
1 parent cd7b118 commit 4bee8b5
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
version: 2

build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.12"

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# -- Project information -----------------------------------------------------

project = "SuperScreen"
copyright = "2021-2023, Logan Bishop-Van Horn"
copyright = "2021-2024, Logan Bishop-Van Horn"
author = "Logan Bishop-Van Horn"


Expand Down
Binary file modified docs/images/logo_currents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo_currents_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo_fields.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo_streams.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo_terminal_currents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/logo_terminal_streams.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/notebooks/field-sources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
{
"data": {
"text/html": [
"<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",
"[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>"
"<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",
"[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>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down Expand Up @@ -142,9 +142,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"x = 0.5515966127155993\n",
"y = 0.16925251669093266\n",
"z = 0.9275080254523002\n",
"x = 0.7292460794150782\n",
"y = 0.3839142913160034\n",
"z = 0.9297509883825962\n",
"field(x, y, z) = 5.0\n"
]
}
Expand Down
28 changes: 14 additions & 14 deletions docs/notebooks/logo.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/notebooks/polygons.ipynb

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions docs/notebooks/quickstart.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/notebooks/scanning-squid.ipynb

Large diffs are not rendered by default.

99 changes: 42 additions & 57 deletions docs/notebooks/terminal-currents.ipynb

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions superscreen/device/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import path
from scipy import interpolate
from shapely import affinity
from shapely import geometry as geo
from shapely.validation import explain_validity
Expand Down Expand Up @@ -481,9 +480,7 @@ def buffer(
return polygon
return polygon.points

def resample(
self, num_points: Optional[int] = None, degree: int = 1, smooth: float = 0
) -> "Polygon":
def resample(self, num_points: Optional[int] = None) -> "Polygon":
"""Resample vertices so that they are approximately uniformly distributed
along the polygon boundary.
Expand All @@ -492,25 +489,19 @@ def resample(
the polygon is resampled to ``len(self.points)`` points. If
``num_points`` is not None and has a boolean value of False,
then an unaltered copy of the polygon is returned.
degree: The degree of the spline with which to iterpolate.
Defaults to 1 (linear spline).
smooth: Smoothing condition.
"""
if num_points is None:
num_points = self.points.shape[0]
num_points = len(self.points)
if not num_points:
return self.copy()
points = self.points.copy()
_, ix = np.unique(points, return_index=True, axis=0)
points = close_curve(points[np.sort(ix)])
tck, _ = interpolate.splprep(points.T, k=degree, s=smooth)
x, y = interpolate.splev(np.linspace(0, 1, num_points), tck)
points = close_curve(np.stack([x, y], axis=1))
boundary = self.polygon.boundary
new_points = boundary.segmentize(boundary.length / num_points).interpolate(
np.linspace(0, 1, num_points), normalized=True
)
return Polygon(
name=self.name,
layer=self.layer,
points=points,
points=new_points,
)

def plot(self, ax: Optional[plt.Axes] = None, **kwargs) -> plt.Axes:
Expand Down
4 changes: 2 additions & 2 deletions superscreen/test/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ def test_fluxoid_simply_connected(
total_vortex_flux += (vortex.nPhi0 * ureg("Phi_0")).to(units).magnitude
if total_vortex_flux:
# There are vortices in the region.
assert (abs(total_fluxoid - total_vortex_flux) / abs(total_vortex_flux)) < 5e-2
assert (abs(total_fluxoid - total_vortex_flux) / abs(total_vortex_flux)) < 8e-2
else:
# No vortices - fluxoid should be zero.
assert abs(total_fluxoid) / abs(flux_part) < 5e-2
assert abs(total_fluxoid) / abs(flux_part) < 8e-2


@pytest.mark.parametrize("units, with_units", [("uA / um", False), (None, True)])
Expand Down
2 changes: 1 addition & 1 deletion superscreen/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (0, 11, 0)
__version_info__ = (0, 12, 0)
__version__ = ".".join(map(str, __version_info__))

0 comments on commit 4bee8b5

Please sign in to comment.