xrft
xrft copied to clipboard
Question about dft
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)
/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.
Thanks for reporting this issue Mu. We will look at it right away.
Perhaps this has to do with xrft having trouble computing the frequency coordinate when the original data has no coordinate metadata?
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.
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 are you still having issues here? I just ran your code without issues using xrft=0.3.0.
@dougiesquire Thanks for your reply. Now I know the issue may be from my setting. Could you tell me your xarray version?
I ran your code using xarray=0.18.0. Perhaps more importantly, what version of xarray are you using?
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.
@gmuxu Does the xarray version solve your issue? If so, I'm gonna close this issue :)