-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Description
I want to get your quick thoughts on a stumbling block I've hit with the particledata-xarray implementation (implementing #1822).
I've made particle.dt a numpy.timedelta64 object, but this means that we can't do something like
lon += u * particle.dtin a Kernel (or anywhere else) because multiplying u (a float) with particle.dt (a timedelta64) results in a TypeError...
Three possible solutions I see
- Don't use
np.timedelta64fordt, but instead keep them asfloat. This however means that we'll probably lose all the advantages ofparticle.timebeing anp.datetime64too; becauseparticle.time + particle.dtwon't work anymore - (on-thy-fly) convert any mention of
particle.dtin a Kernel to afloat; but that means a codeconverter (again...), which we wanted to get rid of in v4 - Create our own
parcels.timedelta64class that inherits(?) fromnp.timedelta64but also adds multiplications with afloat(and then returns afloat). Something like
class timedelta64:
def __init__(self, value):
self.value = np.timedelta64(value)
def __mul__(self, other):
# Returns float seconds
return (self.value / np.timedelta64(1, "s")) * other
def __rmul__(self, other):
return self.__mul__(other)What do you think, @VeckoTheGecko? Do you have a preference? Or do you see another solution?
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Backlog