You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to interpolate it on 1D coordinate
however da.interp is expecting input of dimension name.
So the code below does not work.
Is there any work around?
import xarray as xr
import rioxarray
import numpy as np
import matplotlib.pyplot as plt
# Define 1D latitude and longitude
lat = np.linspace(-90, 90, 100) # 1D array for latitude
lon = np.linspace(-180, 180, 200) # 1D array for longitude
# Create a 2D data array, but using 1D coordinates for lat and lon
data = np.random.rand(100, 200) # Data array of size (lat, lon)
# Set up the DataArray with 1D coordinates
da = xr.DataArray(
data.T,
coords={"latitude": (["y", "x"],np.meshgrid(lat, lon)[0]),
"longitude": (["y", "x"],np.meshgrid(lat, lon)[1]),
},
dims=["y", "x"]
)
da = da.rio.write_crs("EPSG:4326", inplace=True)
new_lat = np.linspace(-90, 90, 100) # 1D array for latitude
new_lon = np.linspace(-180, 180, 200) # 1D array for longitude
interpolated_data = da.interp(latitude=new_lat, longitude=new_lon)
error is
da can however be plotted on latitude and longitude using
da.plot(x='longitude',y='latitude')
plt.show()
The text was updated successfully, but these errors were encountered:
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
max-sixty
added
needs mcve
https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
and removed
needs triage
Issue that has not been reviewed by xarray team member
labels
Nov 6, 2024
Hi @3dfirelab - this seems like it would be a great question for StackOverflow or the xarray github Discussions forum, since it's not a bug with xarray, but more a usage question. Working with 2D coordinates is tricky! If you do ask on Discussions, be sure to check out the Discussions norms guide. Good luck!
What is your issue?
I have a data array with 2d coordinate array
I try to interpolate it on 1D coordinate
however da.interp is expecting input of dimension name.
So the code below does not work.
Is there any work around?
error is
da can however be plotted on latitude and longitude using
The text was updated successfully, but these errors were encountered: