From f901ed392ea383b12f46aa8138fcde258723d09d Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 14 Nov 2025 12:26:55 +0100 Subject: [PATCH 1/5] Add a check for inner_outer convention --- zoidberg/poloidal_grid.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/zoidberg/poloidal_grid.py b/zoidberg/poloidal_grid.py index 290e91b..e059180 100644 --- a/zoidberg/poloidal_grid.py +++ b/zoidberg/poloidal_grid.py @@ -281,17 +281,31 @@ def __init__(self, R, Z): self.R = R self.Z = Z - # Create a KDTree for quick lookup of nearest points - n = R.size - data = np.concatenate((R.reshape((n, 1)), Z.reshape((n, 1))), axis=1) - self.tree = KDTree(data) - - # Create splines for quick interpolation of coordinates nx, nz = R.shape - self.nx = nx self.nz = nz + try: + import shapely + except ImportError: + pass + else: + if nx > 4: + inner = shapely.Polygon(zip(R[2], Z[2])) + outer = shapely.Polygon(zip(R[-2], Z[-2])) + + assert ( + inner.area <= outer.area + ), f"""You are trying to create a grid with inner boundary at high x +and outer boundary at low x. This is against the convention - +switch inner and outer boundary. + {inner.area} {outer.area}""" + + # Create a KDTree for quick lookup of nearest points + data = np.concatenate((R.reshape((-1, 1)), Z.reshape((-1, 1))), axis=1) + self.tree = KDTree(data) + + # Create splines for quick interpolation of coordinates xinds = np.arange(nx) zinds = np.arange(nz * 3) # Repeat the data in z, to approximate periodicity From 952536e61b7bb807390f8343a64dfdcae77047e6 Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 5 Jan 2026 13:20:23 +0100 Subject: [PATCH 2/5] be more explicit that R and Z are 2d --- zoidberg/poloidal_grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zoidberg/poloidal_grid.py b/zoidberg/poloidal_grid.py index e059180..5a66c20 100644 --- a/zoidberg/poloidal_grid.py +++ b/zoidberg/poloidal_grid.py @@ -291,8 +291,8 @@ def __init__(self, R, Z): pass else: if nx > 4: - inner = shapely.Polygon(zip(R[2], Z[2])) - outer = shapely.Polygon(zip(R[-2], Z[-2])) + inner = shapely.Polygon(zip(R[2, :], Z[2, :])) + outer = shapely.Polygon(zip(R[-2, :], Z[-2, :])) assert ( inner.area <= outer.area From 8dadcf34d3a1cc8ee28c3817d1303097a3498f06 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 14 Jan 2026 14:09:44 +0100 Subject: [PATCH 3/5] Make shapely a hard requirement --- pyproject.toml | 1 + zoidberg/poloidal_grid.py | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1b32946..51ea922 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ dependencies = [ "matplotlib >= 3.8.0", "netCDF4 >= 1.7", "freeqdsk >= 0.4.0", + "shapely", ] dynamic = ["version"] diff --git a/zoidberg/poloidal_grid.py b/zoidberg/poloidal_grid.py index 5a66c20..5afdafc 100644 --- a/zoidberg/poloidal_grid.py +++ b/zoidberg/poloidal_grid.py @@ -24,6 +24,7 @@ from numpy import linspace, pi, zeros from scipy.interpolate import RectBivariateSpline from scipy.spatial import cKDTree as KDTree +import shapely try: import matplotlib.pyplot as plt @@ -285,18 +286,13 @@ def __init__(self, R, Z): self.nx = nx self.nz = nz - try: - import shapely - except ImportError: - pass - else: - if nx > 4: - inner = shapely.Polygon(zip(R[2, :], Z[2, :])) - outer = shapely.Polygon(zip(R[-2, :], Z[-2, :])) + if nx > 4: + inner = shapely.Polygon(zip(R[2, :], Z[2, :])) + outer = shapely.Polygon(zip(R[-2, :], Z[-2, :])) - assert ( - inner.area <= outer.area - ), f"""You are trying to create a grid with inner boundary at high x + assert ( + inner.area <= outer.area + ), f"""You are trying to create a grid with inner boundary at high x and outer boundary at low x. This is against the convention - switch inner and outer boundary. {inner.area} {outer.area}""" From 774d850795cc6224c54c637e75f61db4f012b041 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 14 Jan 2026 14:09:53 +0100 Subject: [PATCH 4/5] Update comment --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0888706..991a969 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -# the following line installs requirements from setup.py +# the following line installs requirements from pyproject.toml -e . From eed546afa13991e38178721ab8f97065943049ee Mon Sep 17 00:00:00 2001 From: dschwoerer Date: Wed, 14 Jan 2026 13:10:13 +0000 Subject: [PATCH 5/5] Apply black/isort changes --- zoidberg/poloidal_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zoidberg/poloidal_grid.py b/zoidberg/poloidal_grid.py index 5afdafc..3483f7f 100644 --- a/zoidberg/poloidal_grid.py +++ b/zoidberg/poloidal_grid.py @@ -21,10 +21,10 @@ import warnings import numpy as np +import shapely from numpy import linspace, pi, zeros from scipy.interpolate import RectBivariateSpline from scipy.spatial import cKDTree as KDTree -import shapely try: import matplotlib.pyplot as plt