From 1b284cec2476cc7d36817af53c11d390adc4021b Mon Sep 17 00:00:00 2001 From: andrew-s28 Date: Mon, 17 Jun 2024 14:19:14 -0700 Subject: [PATCH] changed np.infty to np.inf for use with numpy 2.0 --- parcels/fieldset.py | 4 ++-- parcels/grid.py | 2 +- parcels/particlefile.py | 2 +- parcels/particleset.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/parcels/fieldset.py b/parcels/fieldset.py index 42ce71f95..e10276c1d 100644 --- a/parcels/fieldset.py +++ b/parcels/fieldset.py @@ -1186,7 +1186,7 @@ def computeTimeChunk(self, time=0., dt=1): Default is 1. """ signdt = np.sign(dt) - nextTime = np.infty if dt > 0 else -np.infty + nextTime = np.inf if dt > 0 else -np.inf for g in self.gridset.grids: g.update_status = 'not_updated' @@ -1320,7 +1320,7 @@ def computeTimeChunk(self, time=0., dt=1): depth_data = f.grid.depth_field.data f.grid.depth = depth_data if isinstance(depth_data, np.ndarray) else np.array(depth_data) - if abs(nextTime) == np.infty or np.isnan(nextTime): # Second happens when dt=0 + if abs(nextTime) == np.inf or np.isnan(nextTime): # Second happens when dt=0 return nextTime else: nSteps = int((nextTime - time) / dt) diff --git a/parcels/grid.py b/parcels/grid.py index 9c1ba4739..cc9bcaf2d 100644 --- a/parcels/grid.py +++ b/parcels/grid.py @@ -169,7 +169,7 @@ def add_Sdepth_periodic_halo(self, zonal, meridional, halosize): assert self.depth.shape[2] == self.ydim, "Third dim must be y." def computeTimeChunk(self, f, time, signdt): - nextTime_loc = np.infty if signdt >= 0 else -np.infty + nextTime_loc = np.inf if signdt >= 0 else -np.inf periods = self.periods.value if isinstance(self.periods, c_int) else self.periods prev_time_indices = self.time if self.update_status == 'not_updated': diff --git a/parcels/particlefile.py b/parcels/particlefile.py index c572fe407..e301f137b 100644 --- a/parcels/particlefile.py +++ b/parcels/particlefile.py @@ -59,7 +59,7 @@ class ParticleFile(ABC): time_origin = None lonlatdepth_dtype = None - def __init__(self, name, particleset, outputdt=np.infty, chunks=None, create_new_zarrfile=True): + def __init__(self, name, particleset, outputdt=np.inf, chunks=None, create_new_zarrfile=True): self.outputdt = outputdt.total_seconds() if isinstance(outputdt, delta) else outputdt self.chunks = chunks diff --git a/parcels/particleset.py b/parcels/particleset.py index adfe09629..0628452b6 100644 --- a/parcels/particleset.py +++ b/parcels/particleset.py @@ -882,7 +882,7 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime= raise ValueError('Time step dt is too small') if (dt * 1e6) % 1 != 0: raise ValueError('Output interval should not have finer precision than 1e-6 s') - outputdt = output_file.outputdt if output_file else np.infty + outputdt = output_file.outputdt if output_file else np.inf if isinstance(outputdt, delta): outputdt = outputdt.total_seconds() if isinstance(callbackdt, delta): @@ -920,7 +920,7 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime= self.particledata._data['dt'][:] = dt if callbackdt is None: - interupt_dts = [np.infty, outputdt] + interupt_dts = [np.inf, outputdt] if self.repeatdt is not None: interupt_dts.append(self.repeatdt) callbackdt = np.min(np.array(interupt_dts)) @@ -928,11 +928,11 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime= if self.repeatdt: next_prelease = self.repeat_starttime + (abs(time - self.repeat_starttime) // self.repeatdt + 1) * self.repeatdt * np.sign(dt) else: - next_prelease = np.infty if dt > 0 else - np.infty + next_prelease = np.inf if dt > 0 else - np.inf if output_file: next_output = time + dt else: - next_output = time + np.infty if dt > 0 else - np.infty + next_output = time + np.inf if dt > 0 else - np.inf next_callback = time + callbackdt if dt > 0 else time - callbackdt next_input = self.fieldset.computeTimeChunk(time, np.sign(dt)) if self.fieldset is not None else np.inf