-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error raised when array has additional 2D coordinates #166
Comments
Another idea would be to apply |
Can you elaborate on this? |
Sure! Sorry for the brevity, now that I reread it sounds like I was thinking out loud. One alternative way to select the possible coordinates along which the fft can be performed could be through the indexes. For instance, if I have an array with several coordinates:
import numpy as np
import xarray as xr
# Build a sample array
# --------------------
# Generate easting and northing, and their versions in km
easting = np.linspace(-5e3, 3e3, 91)
northing = np.linspace(4e3, 10e3, 61)
easting_km, northing_km = easting * 1e-3, northing * 1e-3
# Generate sample data and the upward coordinate
ee, nn = np.meshgrid(easting, northing)
upward = np.ones_like(ee)
data = ee ** 2 + nn ** 2
# Build the array
dims = ("northing", "easting")
da = xr.DataArray(
data,
coords={
"easting": easting,
"northing": northing,
"northing_km": ("northing", northing_km),
"easting_km": ("easting", easting_km),
"upward": (dims, upward),
},
dims=dims,
)
print(da)
print("\nIndexes:", tuple(i for i in da.indexes))
If I run This is an unpolished idea, so feel free to disagree and/or offer another way to solve this issue. |
If working with indexes is too complex, maybe we could just ignore these extra coordinates and apply the FFT only on the ones that are named after the dimensions of the array. I think my main issue is with the error against bad coordinates. Is there any special reason for it to exist? |
I personally like this idea. |
I've just noticed that |
In Harmonica we usually produce 2D grids out of scattered data whose dimensions are
northing
andeasting
. In addition, we often have an extra coordinate: theupward
, which is the vertical coordinate of each point of the grid. Theupward
coordinate is included into the list of coordinates inside the array, but as a 2D array with the same dimensions as the grid itself.When trying to compute the
fft
over this kind of arrays,xrft
is raising and error because it recognizes theupward
as a bad coordinate. I leave a minimal working example to reproduce the error:Version of
xrft
:v0.4.0
I think we could improve the detection of the bad coordinates in a way that it doesn't include any n-dimensional coordinate (where n > 1) so we don't need to drop them before passing them to
fft
.What do you think?
The text was updated successfully, but these errors were encountered: