Skip to content

Commit

Permalink
Replace asfarray with asarray
Browse files Browse the repository at this point in the history
NumPy 2.x has removed `asfarray`.

Based on a patch from Sandro <devel@penguinpee.nl>
  • Loading branch information
dschwoerer committed Dec 16, 2024
1 parent 84dafa4 commit 99e61b1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions zoidberg/fieldtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def trace_poincare(
raise ValueError("nplot and y_slices cannot both be None")

if y_slices is not None:
y_slices = np.asfarray(y_slices)
y_slices = np.asarray(y_slices)

if np.amin(y_slices) < 0.0 or np.amax(y_slices) > yperiod:
raise ValueError(
Expand Down Expand Up @@ -384,8 +384,8 @@ def trace_poincare(
) * y_values[:-1]

# Starting location
xpos = np.asfarray(xpos)
zpos = np.asfarray(zpos)
xpos = np.asarray(xpos)
zpos = np.asarray(zpos)

field_tracer = FieldTracer(magnetic_field)
result = field_tracer.follow_field_lines(xpos, zpos, y_values_over)
Expand Down
2 changes: 1 addition & 1 deletion zoidberg/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, poloidal_grids, ycoords, Ly, yperiodic=False, name="fci_grid"

self.poloidal_grids = poloidal_grids
self._ngrids = ngrids # This is an implementation detail, whether we have one or multiple separate grids
self.ycoords = np.asfarray(ycoords)
self.ycoords = np.asarray(ycoords)
self.Ly = Ly
self.yperiodic = yperiodic

Expand Down
4 changes: 2 additions & 2 deletions zoidberg/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def plot_3d_field_line(magnetic_field, xpos, zpos, yperiod, cycles=20, y_res=50)
# Go round toroidally cycles times
phivals_hires = np.linspace(0, cycles * yperiod, num=y_res * cycles, endpoint=False)

xpos = np.asfarray(xpos)
zpos = np.asfarray(zpos)
xpos = np.asarray(xpos)
zpos = np.asarray(zpos)

field_tracer = fieldtracer.FieldTracer(magnetic_field)
result_hires = field_tracer.follow_field_lines(xpos, zpos, phivals_hires)
Expand Down
16 changes: 8 additions & 8 deletions zoidberg/poloidal_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def getCoordinate(self, xind, zind, dx=0, dz=0):
"""

# Convert to NumPy arrays if not already
xind = np.asfarray(xind)
zind = np.asfarray(zind)
xind = np.asarray(xind)
zind = np.asarray(zind)
# Make sure dx and dz are integers
dx = int(dx)
dz = int(dz)
Expand Down Expand Up @@ -213,8 +213,8 @@ def findIndex(self, R, Z):
"""

# Make sure inputs are NumPy arrays
R = np.asfarray(R)
Z = np.asfarray(Z)
R = np.asarray(R)
Z = np.asarray(Z)

# Check that they have the same shape
assert R.shape == Z.shape
Expand Down Expand Up @@ -353,8 +353,8 @@ def findIndex(self, R, Z, tol=1e-10, show=False):
"""

# Make sure inputs are NumPy arrays
R = np.asfarray(R)
Z = np.asfarray(Z)
R = np.asarray(R)
Z = np.asarray(Z)

# Check that they have the same shape
assert R.shape == Z.shape
Expand All @@ -378,8 +378,8 @@ def findIndex(self, R, Z, tol=1e-10, show=False):
zind = ind - xind * nz

# Convert indices to float
xind = np.asfarray(xind)
zind = np.asfarray(zind)
xind = np.asarray(xind, dtype=float)
zind = np.asarray(zind, dtype=float)

# Create a mask for the positions
mask = np.ones(xind.shape)
Expand Down
12 changes: 6 additions & 6 deletions zoidberg/rzline.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class RZline:
"""

def __init__(self, r, z, anticlockwise=True, spline_order=None, smooth=False):
r = np.asfarray(r)
z = np.asfarray(z)
r = np.asarray(r)
z = np.asarray(z)

# Check the sizes of the variables
n = len(r)
Expand Down Expand Up @@ -421,8 +421,8 @@ def line_from_points_poly(rarray, zarray, show=False, spline_order=None):
"""

rarray = np.asfarray(rarray)
zarray = np.asfarray(zarray)
rarray = np.asarray(rarray)
zarray = np.asarray(zarray)

assert rarray.size >= 3
assert rarray.shape == zarray.shape
Expand Down Expand Up @@ -610,8 +610,8 @@ def line_from_points(
"""

# Make sure we have Numpy arrays
rarray = np.asfarray(rarray)
zarray = np.asfarray(zarray)
rarray = np.asarray(rarray)
zarray = np.asarray(zarray)

assert rarray.size == zarray.size

Expand Down

0 comments on commit 99e61b1

Please sign in to comment.