API reference

Dataset

Creating a dataset

Dataset([variables, coords, attrs]) A netcdf-like data object consisting of variables and attributes which together form a self describing dataset.
open_dataset(nc[, decode_cf, ...]) Load a dataset from a file or file-like object.

Attributes and underlying data

Dataset.coords Dictionary of xray.Coordinate objects used for label based indexing.
Dataset.noncoords Dictionary of DataArrays whose names do not match dimensions.
Dataset.dims Mapping from dimension names to lengths.
Dataset.attrs Dictionary of global attributes on this dataset

Dataset contents

Datasets implement the mapping interface with keys given by variable names and values given by DataArray objects.

Dataset.__getitem__(key) Access the given variable name in this dataset as a DataArray.
Dataset.__setitem__(key, value) Add an array to this dataset.
Dataset.__delitem__(key) Remove a variable from this dataset.
Dataset.update(other[, inplace]) Update this dataset’s variables and attributes with those from another dataset.
Dataset.merge(other[, inplace, ...]) Merge the variables of two datasets into a single new dataset.
Dataset.concat(datasets[, dim, indexers, ...]) Concatenate datasets along a new or existing dimension.
Dataset.copy([deep]) Returns a copy of this dataset.
Dataset.load_data() Manually trigger loading of this dataset’s data from disk or a remote source into memory and return this dataset.
Dataset.iteritems(...)
Dataset.itervalues(...)
Dataset.virtual_variables A frozenset of variable names that don’t exist in this dataset but for which could be created on demand.

Comparisons

Dataset.equals(other) Two Datasets are equal if they have the same variables and all variables are equal.
Dataset.identical(other) Two Datasets are identical if they have the same variables and all variables are identical (with the same attributes), and they also have the same global attributes.

Selecting

Dataset.isel(**indexers) Return a new dataset with each array indexed along the specified dimension(s).
Dataset.sel(**indexers) Return a new dataset with each variable indexed by tick labels along the specified dimension(s).
Dataset.reindex([copy]) Conform this object onto a new set of coordinates, filling in missing values with NaN.
Dataset.reindex_like(other[, copy]) Conform this object onto the coordinates of another object, filling in missing values with NaN.
Dataset.rename(name_dict[, inplace]) Returns a new object with renamed variables and dimensions.
Dataset.select_vars(*names) Returns a new dataset that contains only the named variables and their coordinates.
Dataset.drop_vars(*names) Returns a new dataset without the named variables.
Dataset.squeeze([dim]) Return a new dataset with squeezed data.
Dataset.groupby(group[, squeeze]) Group this dataset by unique values of the indicated group.

Computations

Dataset.apply(func[, keep_attrs]) Apply a function over noncoordinate variables in this dataset.
Dataset.reduce(func[, dim, keep_attrs]) Reduce this dataset by applying func along some dimension(s).
Dataset.all([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.all along some dimension(s).
Dataset.any([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.any along some dimension(s).
Dataset.argmax([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.argmax along some dimension(s).
Dataset.argmin([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.argmin along some dimension(s).
Dataset.max([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.max along some dimension(s).
Dataset.min([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.min along some dimension(s).
Dataset.mean([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.mean along some dimension(s).
Dataset.std([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.std along some dimension(s).
Dataset.sum([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.sum along some dimension(s).
Dataset.var([dim, keep_attrs]) Reduce this Dataset’s data by applying numpy.var along some dimension(s).

IO / Conversion

Dataset.to_netcdf(filepath, **kwdargs) Dump dataset contents to a location on disk using the netCDF4 package.
Dataset.to_dataframe() Convert this dataset into a pandas.DataFrame.
Dataset.from_dataframe(dataframe) Convert a pandas.DataFrame into an xray.Dataset
Dataset.close() Close any datastores linked to this dataset

Dataset internals

These attributes and classes provide a low-level interface for working with Dataset variables. In general you should use the Dataset dictionary- like interface instead and working with DataArray objects:

Dataset.variables Dictionary of Variable objects contained in this dataset.
Variable(dims, data[, attrs, encoding]) A netcdf-like variable consisting of dimensions, data and attributes which describe a single Array.
Coordinate(name, data[, attrs, encoding]) Wrapper around pandas.Index that adds xray specific functionality.

Backends (experimental)

These backends provide a low-level interface for lazily loading data from external file-formats or protocols, and can be manually invoked to create arguments for the from_store and dump_to_store Dataset methods.

backends.NetCDF4DataStore(filename[, mode, ...]) Store for reading and writing data via the Python-NetCDF4 library.
backends.PydapDataStore(url) Store for accessing OpenDAP datasets with pydap.
backends.ScipyDataStore(filename_or_obj[, ...]) Store for reading and writing data via scipy.io.netcdf.

DataArray

DataArray([data, coords, dims, name, attrs, ...]) N-dimensional array with labeled coordinates and dimensions.

Attributes and underlying data

DataArray.values The variables’s data as a numpy.ndarray
DataArray.coords Dictionary-like container of xray.Coordinate objects used for label based indexing.
DataArray.dims
DataArray.name The name of the variable in dataset to which array operations are applied.
DataArray.attrs Dictionary storing arbitrary metadata with this array.
DataArray.encoding Dictionary of format-specific settings for how this array should be serialized.
DataArray.variable

Selecting

DataArray.__getitem__(key)
DataArray.__setitem__(key, value)
DataArray.loc Attribute for location based indexing like pandas..
DataArray.isel(**indexers) Return a new DataArray whose dataset is given by integer indexing along the specified dimension(s).
DataArray.sel(**indexers) Return a new DataArray whose dataset is given by selecting index labels along the specified dimension(s).
DataArray.reindex([copy]) Conform this object onto a new set of coordinates, filling in missing values with NaN.
DataArray.reindex_like(other[, copy]) Conform this object onto the coordinates of another object, filling in missing values with NaN.
DataArray.rename(new_name_or_name_dict) Returns a new DataArray with renamed variables.
DataArray.select_vars(*names) Returns a new DataArray with only the named variables, as well as this DataArray’s array variable (and all associated coordinates).
DataArray.drop_vars(*names) Returns a new DataArray without the named variables.
DataArray.squeeze([dim]) Return a new DataArray object with squeezed data.

Group operations

DataArray.groupby(group[, squeeze]) Group this dataset by unique values of the indicated group.
DataArray.concat(arrays[, dim, indexers, ...]) Stack arrays along a new or existing dimension to form a new DataArray.

Computations

DataArray.transpose(*dims) Return a new DataArray object with transposed dimensions.
DataArray.T
DataArray.reduce(func[, dim, axis, keep_attrs]) Reduce this array by applying func along some dimension(s).
DataArray.get_axis_num(dim) Return axis number(s) corresponding to dimension(s) in this array.
DataArray.all([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.all along some dimension(s).
DataArray.any([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.any along some dimension(s).
DataArray.argmax([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.argmax along some dimension(s).
DataArray.argmin([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.argmin along some dimension(s).
DataArray.max([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.max along some dimension(s).
DataArray.min([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.min along some dimension(s).
DataArray.mean([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.mean along some dimension(s).
DataArray.std([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.std along some dimension(s).
DataArray.sum([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.sum along some dimension(s).
DataArray.var([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.var along some dimension(s).
DataArray.isnull(*args, **kwargs) Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
DataArray.notnull(*args, **kwargs) Replacement for numpy.isfinite / -numpy.isnan which is suitable for use on object arrays.

Comparisons

DataArray.equals(other) True if two DataArrays have the same dimensions, coordinates and values; otherwise False.
DataArray.identical(other) Like equals, but also checks DataArray names and attributes, and attributes on their coordinates.

IO / Conversion

DataArray.to_dataset([name]) Convert a DataArray to a Dataset
DataArray.to_dataframe() Convert this array into a pandas.DataFrame.
DataArray.to_series() Convert this array into a pandas.Series.
DataArray.to_index() Convert this variable to a pandas.Index.
DataArray.from_series(series) Convert a pandas.Series into an xray.DataArray
DataArray.copy([deep]) Returns a copy of this array.
DataArray.load_data() Manually trigger loading of this array’s data from disk or a remote source into memory and return this array.

Top-level functions

align(*objects[, join, copy]) Given any number of Dataset and/or DataArray objects, returns new objects with aligned coordinates.