user308827
user308827

Reputation: 22031

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

Upvotes: 3

Views: 345

Answers (1)

shoyer
shoyer

Reputation: 9623

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

Upvotes: 4

Related Questions