Xarray returns duplicate Longitude/Latitude values with sel method #7053
Replies: 5 comments
-
Hi @rogomichael, thanks for raising your issue. Could you possibly turn your problem into a minimal reproducible example? That would make it much easier for us to help you. You've included a lot of code, but from looking at it it seems to me that the only lines which matter are nc_file = xr.open_mfdataset('year2019.nc')
nc_file["tg"].sel(
longitude=[state_lon[0], state_lon[1]],
latitude=[state_lat[0], state_lat[1]],
method="nearest"
) This suggests to me that your original file has duplicate values, as all xarray has done here is open it. (However I still am not going to be able to reproduce this error without access to the file |
Beta Was this translation helpful? Give feedback.
-
@TomNicholas , https://1drv.ms/u/s!AvYOTGjStibEmGGsJwRlpoBfLvHm?e=LBLm95 I hope it is accessible. import xarray as xr
nc_file = xr.open_mfdataset('year2019.nc') #, chunks = {'time': 10})
two_months_255 = nc_file["tg"].sel(
longitude = [49.294, 49.376],
latitude = [10.971, 11.087]) |
Beta Was this translation helpful? Give feedback.
-
Hi @rogomichael, It is expected in your example that The resolution of the grid is too coarse compared to your ROI, which is why the two provided values for latitude (longitude) both select the same grid point. If you want to use ds.sel(
longitude=slice(49.294, 49.376),
latitude=slice(10.971, 11.087)
)
# <xarray.Dataset>
# Dimensions: (time: 365, longitude: 1, latitude: 0)
# Coordinates:
# * time (time) datetime64[ns] 2019-01-01 2019-01-02 ... 2019-12-31
# * longitude (longitude) float64 49.38
# * latitude (latitude) float64
# Data variables:
# tg (time, latitude, longitude) float32 ... |
Beta Was this translation helpful? Give feedback.
-
Hi @benbovy , |
Beta Was this translation helpful? Give feedback.
-
You'd need to adjust the latitude / longitude values passed to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What is your issue?
I am trying to select air temperature from Netcdf file and polgon regions from NUTS3 shape file with the aim of masking both to extract the values. However, for some regions, xarray returns a data frame with the same latitude or longitude values which cannot be masked by geopandas. The shape file and the netcdf I am using are zipped here
Here is the code:
ask.zip

Beta Was this translation helpful? Give feedback.
All reactions