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
in 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.timedelta64 for dt, but instead keep them as float. This however means that we'll probably lose all the advantages of particle.time being a np.datetime64 too; because particle.time + particle.dt won't work anymore
- (on-thy-fly) convert any mention of
particle.dt in a Kernel to a float; but that means a codeconverter (again...), which we wanted to get rid of in v4
- Create our own
parcels.timedelta64 class that inherits(?) from np.timedelta64 but also adds multiplications with a float (and then returns a float). 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?
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.dtanumpy.timedelta64object, but this means that we can't do something likein a Kernel (or anywhere else) because multiplying
u(afloat) withparticle.dt(atimedelta64) results in aTypeError...Three possible solutions I see
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 anymoreparticle.dtin a Kernel to afloat; but that means a codeconverter (again...), which we wanted to get rid of in v4parcels.timedelta64class that inherits(?) fromnp.timedelta64but also adds multiplications with afloat(and then returns afloat). Something likeWhat do you think, @VeckoTheGecko? Do you have a preference? Or do you see another solution?