xrft icon indicating copy to clipboard operation
xrft copied to clipboard

Question about dft

Open gmuxu opened this issue 4 years ago • 9 comments

Hi, I meet a problem when I run dft. My code is:

from dask.diagnostics import ProgressBar import xrft n = int(2**3) da = xr.DataArray(np.random.rand(n,int(n/2),int(n/2)), dims=['time','y','x']) with ProgressBar(): uhat2 = xrft.dft(da.chunk({'time':8,'x':1,'y':1}), dim=['time'], detrend='linear', window=True).compute()

I got the error:

KeyError Traceback (most recent call last) in 3 with ProgressBar(): 4 uhat2 = xrft.dft(da.chunk({'time':8,'x':1,'y':1}), ----> 5 dim=['time'], detrend='linear', window=True).compute()

/rigel/ocp/users/mx2212/.conda/envs/geo_scipy/lib/python3.6/site-packages/xrft/xrft.py in dft(da, spacing_tol, dim, real_dim, shift, detrend, window, true_phase, true_amplitude, chunks_to_segments, prefix, **kwargs) 422 f, dims=da.dims, coords=dict([c for c in da.coords.items() if c[0] not in dim]) 423 ) --> 424 daft = daft.swap_dims(swap_dims).assign_coords(newcoords) 425 daft = daft.drop([d for d in dim if d in daft.coords]) 426

/rigel/ocp/users/mx2212/.conda/envs/geo_scipy/lib/python3.6/site-packages/xarray/core/dataarray.py in swap_dims(self, dims_dict) 1455 Dataset.swap_dims 1456 """ -> 1457 ds = self._to_temp_dataset().swap_dims(dims_dict) 1458 return self._from_temp_dataset(ds) 1459

/rigel/ocp/users/mx2212/.conda/envs/geo_scipy/lib/python3.6/site-packages/xarray/core/dataset.py in swap_dims(self, dims_dict, inplace) 2694 "not an existing dimension" % k 2695 ) -> 2696 if self.variables[v].dims != (k,): 2697 raise ValueError( 2698 "replacement dimension %r is not a 1D "

/rigel/ocp/users/mx2212/.conda/envs/geo_scipy/lib/python3.6/site-packages/xarray/core/utils.py in getitem(self, key) 383 384 def getitem(self, key: K) -> V: --> 385 return self.mapping[key] 386 387 def iter(self) -> Iterator[K]:

KeyError: 'freq_time'

My xrft version is 0.3. The weird thing is that when I run the exact same code on xrft 0.2, there is no error.

gmuxu avatar Apr 29 '21 12:04 gmuxu

Thanks for reporting this issue Mu. We will look at it right away.

rabernat avatar Apr 29 '21 13:04 rabernat

Perhaps this has to do with xrft having trouble computing the frequency coordinate when the original data has no coordinate metadata?

roxyboy avatar Apr 29 '21 13:04 roxyboy

Perhaps this has to do with xrft having trouble computing the frequency coordinate when the original data has no coordinate metadata?

Sounds like a good hunch. But we should be able to handle this situation somehow.

rabernat avatar Apr 29 '21 13:04 rabernat

Actually, I don't think so. I run the data with coordinate metadata too. It has the same error. I doubt it may be from my system setting. Could you run my code and let me know if you have the same error?

gmuxu avatar Apr 29 '21 14:04 gmuxu

@gmuxu are you still having issues here? I just ran your code without issues using xrft=0.3.0.

dougiesquire avatar May 09 '21 05:05 dougiesquire

@dougiesquire Thanks for your reply. Now I know the issue may be from my setting. Could you tell me your xarray version?

gmuxu avatar May 10 '21 12:05 gmuxu

I ran your code using xarray=0.18.0. Perhaps more importantly, what version of xarray are you using?

dougiesquire avatar May 10 '21 23:05 dougiesquire

FYI: I ran into the same error using xrft=0.3.0 and xarray=0.12.1 - upgrading to xarray=0.18.0 resolved the issue.

sgibson-mse avatar May 27 '21 16:05 sgibson-mse

@gmuxu Does the xarray version solve your issue? If so, I'm gonna close this issue :)

roxyboy avatar May 30 '21 11:05 roxyboy