Implement our own FFT functions for xr.DataArray - #677
Conversation
Add our own private functions to compute the fft and ifft of a `xr.DataArray`.
Remove other mentions of xrft in docs.
|
@santisoler could you make the FFT functions public? I've been using xrft a lot in classes along with Harmonica and it would be useful to have this. |
| } | ||
|
|
||
| # Compute FFT | ||
| fft = np.fft.fftshift(np.fft.fftn(grid.values)) |
There was a problem hiding this comment.
@santisoler it would be good to include parts of xrft that calculate the theoretical Fourier Transform instead of just the FFT result. That's in the true_phase and true_amplitude parts of the code: https://github.com/xgcm/xrft/blob/master/xrft/xrft.py#L462
For amplitude based filters this doesn't matter too much since it's all relative. But for spectrum analysis and other possible filters it could matter. So maybe we should add it always to be safe.
List them in the API reference as well.
Add `pad` and `unpad` functions to the `harmonica.filters` submodule and make them public. Add tests for them. Reorganize some utility functions that get reused by both the FFT and padding functions. Move the `apply_filter` function to the `_filters.py` file.
|
I think this is quite ready for our immediate goals of removing In the process, I've been thinking about improving how non-dimensional coordinates are handled. I don't quite like the fact that users need to drop coordinates before passing the Maybe we should assume that the padding will only get applied to dimensional coordinates (coordinates that have the same name as the dimension, i.e. they are Similar thing with FFT: we could only compute frequencies using the dimensional coordinates and ignore the other ones when building the grid in the frequency domain. I'll open an issue for this after merging this PR. |
Add public
harmonica.filters.fftandharmonica.filters.ifftfunctions to compute the FFT and its inverse of axr.DataArray, respectively. Removexrftas a dependency, but keep it as a requirement to run the tests. Addharmonica.filters.padandharmonica.filters.unpadfunctions as modified versions of the ones inxrft. Add tests for the new functions: the FFT functions are tested against theirxrftcounterparts, while the tests for the padding functions that were already existing inxrftwere included. Skip doctests for some padding functions since Xarray changed the order in which the coordinates are displayed when printing axr.DataArraysince a few versions ago.Relevant issues/PRs:
Related to #646
TODO:
fftandifftfunctionsxrftas a dependencyxrftfor the new functions throughout the codebase.