Skip to content

Commit

Permalink
coords with calendar accepted + removing obj call
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Nouguier committed Feb 8, 2023
1 parent 5688129 commit 74730fc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions xrft/xrft.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def _lag_coord(coord):
decoded_time = cftime.date2num(lag, ref_units, calendar)
return decoded_time
elif pd.api.types.is_datetime64_dtype(v0):
return lag.astype("timedelta64[s]").astype("f8").data
return lag.astype("timedelta64[s]").astype("f8")
else:
return lag.data
return lag


def dft(
Expand Down Expand Up @@ -353,7 +353,11 @@ def fft(

if not np.all(
[
(is_numeric_dtype(da.coords[d]) or is_datetime64_any_dtype(da.coords[d]))
(
is_numeric_dtype(da.coords[d])
or is_datetime64_any_dtype(da.coords[d])
or bool(getattr(da.coords[d][0].item(), "calendar", False))
)
for d in dim
]
): # checking if coodinates are numerical or datetime
Expand Down Expand Up @@ -461,7 +465,7 @@ def fft(
dims=up_dim,
coords={up_dim: newcoords[up_dim]},
) # taking advantage of xarray broadcasting and ordered coordinates
daft[up_dim].attrs.update({"direct_lag": lag.obj})
daft[up_dim].attrs.update({"direct_lag": lag})

if true_amplitude:
daft = daft * np.prod(delta_x)
Expand Down Expand Up @@ -554,6 +558,7 @@ def ifft(
(
is_numeric_dtype(daft.coords[d])
or is_datetime64_any_dtype(daft.coords[d])
or bool(getattr(daft.coords[d][0].item(), "calendar", False))
)
for d in dim
]
Expand Down

0 comments on commit 74730fc

Please sign in to comment.