Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xarray select on 2 dimensional coordinates

I am using xarray to work with gridded data and the coordinates latitude and longitude are 2dimensional arrays. It is quite similar to on of the tutorial datasets coming along with xarray.

ds = xarray.tutorial.open_dataset('rasm').load() 

Now I want to use the sel feature to access data from specific points.

ds.sel(yc=50, xc=50, method='nearest') 

In this example DataArray the coordinates xc and yc are no dimensions, so It is necessary to define them as an index. Does any one know how to do this?

like image 734
dl.meteo Avatar asked Nov 30 '25 22:11

dl.meteo


1 Answers

Unfortunately, this is not currently possible. The reasons why (and path forward) are detailed in this GitHub issue: https://github.com/pydata/xarray/issues/475.

There are various work arounds available though. You may try using the groupby_bins method (e.g. http://xarray.pydata.org/en/stable/examples/multidimensional-coords.html).

like image 75
jhamman Avatar answered Dec 02 '25 10:12

jhamman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!