Skip to content

Commit 399ae10

Browse files
Using np.timedelta64 for internal time model
1 parent 68293ab commit 399ae10

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

parcels/particleset.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ def execute(
833833
outputdt = output_file.outputdt if output_file else None
834834

835835
# dt must be converted to float to avoid "TypeError: float() argument must be a string or a real number, not 'datetime.timedelta'"
836-
self.particledata._data["dt"][:] = dt.total_seconds()
836+
dt_seconds = dt / np.timedelta64(1, "s")
837+
self.particledata._data["dt"][:] = dt_seconds
837838

838839
# Set up pbar
839840
if output_file:
@@ -856,8 +857,8 @@ def execute(
856857
# Kernel and particledata currently expect all time objects to be numpy floats.
857858
# When converting absolute times to floats, we do them all relative to the start time.
858859
# TODO: To completely support datetime or timedelta objects, this really needs to be addressed in the kernels and particledata
859-
next_time_float = (next_time - start_time).total_seconds()
860-
res = self._kernel.execute(self, endtime=next_time_float, dt=dt.total_seconds())
860+
next_time_float = (next_time - start_time) / np.timedelta64(1, "s")
861+
res = self._kernel.execute(self, endtime=next_time_float, dt=dt_seconds)
861862
if res == StatusCode.StopAllExecution:
862863
return StatusCode.StopAllExecution
863864

0 commit comments

Comments
 (0)