xray.Dataset.sel

Dataset.sel(method=None, **indexers)

Returns a new dataset with each array indexed by tick labels along the specified dimension(s).

In contrast to Dataset.isel, indexers for this method should use labels instead of integers.

Under the hood, this method is powered by using Panda’s powerful Index objects. This makes label based indexing essentially just as fast as using integer indexing.

It also means this method uses pandas’s (well documented) logic for indexing. This means you can use string shortcuts for datetime indexes (e.g., ‘2000-01’ to select all values in January 2000). It also means that slices are treated as inclusive of both the start and stop values, unlike normal Python indexing.

Parameters:

method : {None, ‘nearest’, ‘pad’/’ffill’, ‘backfill’/’bfill’}, optional

Method to use for inexact matches (requires pandas>=0.16):

  • default: only exact matches
  • pad / ffill: propgate last valid index value forward
  • backfill / bfill: propagate next valid index value backward
  • nearest: use nearest valid index value

**indexers : {dim: indexer, ...}

Keyword arguments with names matching dimensions and values given by scalars, slices or arrays of tick labels.

Returns:

obj : Dataset

A new Dataset with the same contents as this dataset, except each variable and dimension is indexed by the appropriate indexers. In general, each variable’s data will be a view of the variable’s data in this dataset, unless numpy fancy indexing was triggered by using an array indexer, in which case the data will be a copy.