DASDAE / dascore

A python library for distributed fiber optic sensing
Other
71 stars 16 forks source link

timedelta's should work with units #379

Closed d-chambers closed 2 weeks ago

d-chambers commented 3 months ago

Description

Both numpy and python time deltas should be recognized as time units.

For example, this currently fails:

import dascore as dc

patch = dc.get_example_patch()

time = dc.to_timedelta64(2)
patch.taper(time=time)

It should recognize time as a time.

Versions

ahmadtourei commented 3 months ago

Hey @d-chambers, I just ran this, and it works with applying units:

import dascore as dc
from dascore.units import s

time = dc.to_timedelta64(2)
pa_tapered_1 = pa.taper(time=time*s)
pa_tapered_2 = pa.taper(time=2*s)
assert p_tapered_1 == p_tapered_2
assert np.array_equal(pa_tapered_1.data, pa_tapered_2.data), "The arrays are not equal."

It's expected to use units with taper since kwarg is the percentage of the total length of the dimension or absolute units.

I also tried rolling (without specifying units) and got the same result:

import dascore as dc

time = dc.to_timedelta64(2)
mean_pa_1 = pa.rolling(time=time, step=0.5).mean()
mean_pa_2 = pa.rolling(time=2, step=0.5).mean()
assert np.array_equal(mean_pa_1.dropna("time").data, mean_pa_2.dropna("time").data), "The arrays are not equal."
d-chambers commented 2 months ago

Hey @d-chambers, I just ran this, and it works with applying units:

Interesting. Yes, I think the current issue is when a single timedelta64 is passed without applying units to it. Timedelta64 is a bit of a weird case in that it already has units implied.

d-chambers commented 2 weeks ago

closed by #422