Skip to content

Commit ca652c9

Browse files
author
lanougue
committed
try
1 parent 19aff5e commit ca652c9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

xrft/xrft.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ def dft(
450450
dims=up_dim,
451451
coords={up_dim: newcoords[up_dim]},
452452
) # taking advantage of xarray broadcasting and ordered coordinates
453+
daft[up_dim].attrs.update({"direct_lag": lag.obj})
453454

454455
if true_amplitude:
455456
daft = daft * np.prod(delta_x)
@@ -539,8 +540,9 @@ def idft(
539540
dim = [d for d in dim if d != real_dim] + [
540541
real_dim
541542
] # real dim has to be moved or added at the end !
542-
543-
if lag is not None:
543+
if lag is None:
544+
lag = [daft[d].attrs.get("direct_lag", 0.0) for d in dim]
545+
else:
544546
if isinstance(lag, float) or isinstance(lag, int):
545547
lag = [lag]
546548
if len(dim) != len(lag):
@@ -549,8 +551,8 @@ def idft(
549551
msg = "Setting lag with true_phase=False does not guarantee accurate idft."
550552
warnings.warn(msg, Warning)
551553

552-
for d, l in zip(dim, lag):
553-
daft = daft * np.exp(1j * 2.0 * np.pi * daft[d] * l)
554+
for d, l in zip(dim, lag):
555+
daft = daft * np.exp(1j * 2.0 * np.pi * daft[d] * l)
554556

555557
if chunks_to_segments:
556558
daft = _stack_chunks(daft, dim)

0 commit comments

Comments
 (0)