Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subsetting by coord in xarray

I have a netCDF file that I opened using xarray. It has the foll. coords:

Coordinates:
  * lat      (lat) float32 89.875 89.625 89.375 89.125 88.875 88.625 88.375 ...
  * lon      (lon) float32 -179.875 -179.625 -179.375 -179.125 -178.875 ...
  * time     (time) int32 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 ...

How can I subset it so that time starts from 2010 instead of 2005 (lat and lon remain the same)? I want an xarray solution only

like image 705
user308827 Avatar asked Sep 11 '26 07:09

user308827


1 Answers

The .sel method should work, e.g., ds.sel(time=slice(2010, None)). See the docs for more details.

like image 188
shoyer Avatar answered Sep 12 '26 19:09

shoyer



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!