API reference
See also: :ref:_.
Dataset
Dataset ([data_vars, coords, attrs, compat]) | A multi-dimensional, in memory, array database. |
(obj[, concat_characters, …]) | Decode the given Dataset or Datastore according to CF conventions into a new Dataset. |
Attributes
| Mapping from dimension names to lengths. |
Dataset.sizes | Mapping from dimension names to lengths. |
| Dictionary of DataArray objects corresponding to data variables |
Dataset.coords | Dictionary of xarray.DataArray objects corresponding to coordinate variables |
| Dictionary of global attributes on this dataset |
Dataset.encoding | Dictionary of global encoding attributes on this dataset |
| Mapping of pandas.Index objects used for label based indexing |
Dataset.get_index (key) | Get an index for a dimension, with fall-back to a default RangeIndex |
| Block dimensions for this dataset’s data or None if it’s not a dask array. |
Dataset.nbytes | |
Dictionary interface
Datasets implement the mapping interface with keys given by variable namesand values given by DataArray
objects.
Dataset contents
Dataset.copy ([deep, data]) | Returns a copy of this dataset. |
([variables]) | Assign new data variables to a Dataset, returning a new object with all the original variables in addition to the new ones. |
Dataset.assign_coords (kwargs) | Assign new coordinates to this object. |
(*args, kwargs) | Assign new attrs to this object. |
Dataset.pipe (func, args, **kwargs) | Apply func(self, [](, **kwargs) |
(other[, inplace, …]) | Merge the arrays of two datasets into a single dataset. |
Dataset.rename ([name_dict, inplace]) | Returns a new object with renamed variables and dimensions. |
([name_dict]) | Returns a new object with renamed variables including coordinates |
Dataset.rename_dims ([dims_dict]) | Returns a new object with renamed dimensions only. |
(dims_dict[, inplace]) | Returns a new object with swapped dimensions. |
Dataset.expand_dims ([dim, axis]) | Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape. |
(labels[, dim, errors]) | Drop variables or index labels from this dataset. |
Dataset.drop_dims (drop_dims, *[, errors]) | Drop dimensions and associated variables from this dataset. |
(names[, inplace]) | Given names of one or more variables, set them as coordinates |
Dataset.reset_coords ([names, drop, inplace]) | Given names of coordinates, reset them to become variables |
Comparisons
Dataset.equals (other) | Two Datasets are equal if they have matching variables and coordinates, all of which are equal. |
(other) | Like equals, but also checks all dataset attributes and the attributes on all variables and coordinates. |
Dataset.broadcast_equals (other) | Two Datasets are broadcast equal if they are equal after broadcasting all variables against each other. |
Indexing
Dataset.loc | Attribute for location based indexing. |
([indexers, drop]) | Returns a new dataset with each array indexed along the specified dimension(s). |
Dataset.sel ([indexers, method, tolerance, drop]) | Returns a new dataset with each array indexed by tick labels along the specified dimension(s). |
([dim, drop, axis]) | Return a new object with squeezed data. |
Dataset.interp ([coords, method, …]) | Multidimensional interpolation of Dataset. |
(other[, method, …]) | Interpolate this object onto the coordinates of another object, filling the out of range values with NaN. |
Dataset.reindex ([indexers, method, …]) | Conform this object onto a new set of indexes, filling in missing values with fill_value . |
(other[, method, …]) | Conform this object onto the indexes of another object, filling in missing values with fill_value . |
Dataset.set_index ([indexes, append, inplace]) | Set Dataset (multi-)indexes using one or more existing coordinates or variables. |
(dims_or_levels[, drop, …]) | Reset the specified index(es) or multi-index level(s). |
Dataset.reorder_levels ([dim_order, inplace]) | Rearrange index levels using input order. |
(args, **kwargs) | |
Dataset.notnull (args, **kwargs) | |
(other) | Combine two Datasets, default to datavars of self. |
Dataset.count ([dim]) | Reduce this Dataset’s data by applying _count along some dimension(s). |
(dim[, how, thresh, subset]) | Returns a new dataset with dropped labels for missing values along the provided dimension. |
Dataset.fillna (value) | Fill missing values in this object. |
(dim[, limit]) | Fill NaN values by propogating values forward |
Dataset.bfill (dim[, limit]) | Fill NaN values by propogating values backward |
([dim, method, limit, …]) | Interpolate values according to different methods. |
Dataset.where (cond[, other, drop]) | Filter elements from this object according to a condition. |
(test_elements) | Tests each value in the array for whether it is in test elements. |
Computation
(func[, keepattrs, args]) | Apply a function over the data variables in this dataset. |
Dataset.reduce (func[, dim, keep_attrs, …]) | Reduce this dataset by applying _func along some dimension(s). |
(group[, squeeze, …]) | Returns a GroupBy object for performing grouped operations. |
Dataset.groupby_bins (group, bins[, right, …]) | Returns a GroupBy object for performing grouped operations. |
([dim, min_periods, center]) | Rolling window object. |
Dataset.rolling_exp ([window, window_type]) | Exponentially-weighted moving window. |
([dim, boundary, side, …]) | Coarsen object. |
Dataset.resample ([indexer, skipna, closed, …]) | Returns a Resample object for performing resampling operations. |
(dim[, n, label]) | Calculate the n-th order discrete difference along given axis. |
Dataset.quantile (q[, dim, interpolation, …]) | Compute the qth quantile of the data along the specified dimension. |
(coord[, edge_order, …]) | Differentiate with the second order accurate central differences. |
Dataset.integrate (coord[, datetime_unit]) | integrate the array with the trapezoidal rule. |
Aggregation:any
argmin
mean
min
sum
var
ndarray methods:astype
clip
conjugate
round
cumsum
rank
Reshaping and reorganizing
Dataset.transpose (*dims) | Return a new Dataset object with all array dimensions transposed. |
([dimensions]) | Stack any number of existing dimensions into a single new dimension. |
Dataset.unstack ([dim]) | Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions. |
(new_dim, sample_dims) | Combine variables of differing dimensionality into a DataArray without broadcasting. |
Dataset.shift ([shifts, fill_value]) | Shift this dataset by an offset along one or more dimensions. |
([shifts, roll_coords]) | Roll this dataset by an offset along one or more dimensions. |
Dataset.sortby (variables[, ascending]) | Sort object by labels or values (along an axis). |
DataArray
Attributes
| The array’s data as a numpy.ndarray |
DataArray.data | The array’s data as a dask or numpy array |
| Dictionary-like container of coordinate arrays. |
DataArray.dims | Tuple of dimension names associated with this array. |
| Ordered mapping from dimension names to lengths. |
DataArray.name | The name of this array. |
| Dictionary storing arbitrary metadata with this array. |
DataArray.encoding | Dictionary of format-specific settings for how this array should be serialized. |
| Mapping of pandas.Index objects used for label based indexing |
DataArray.get_index (key) | Get an index for a dimension, with fall-back to a default RangeIndex |
ndarray attributes:shape
dtype
chunks
DataArray contents
DataArray.assign_coords (kwargs) | Assign new coordinates to this object. |
(*args, kwargs) | Assign new attrs to this object. |
DataArray.pipe (func, args, **kwargs) | Apply func(self, [](, **kwargs) |
([new_name_or_name_dict]) | Returns a new DataArray with renamed coordinates or a new name. |
DataArray.swap_dims (dims_dict) | Returns a new DataArray with swapped dimensions. |
([dim, axis]) | Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape. |
DataArray.drop (labels[, dim, errors]) | Drop coordinates or index labels from this DataArray. |
([names, drop, inplace]) | Given names of coordinates, reset them to become variables. |
DataArray.copy ([deep, data]) | Returns a copy of this array. |
ndarray methods:item
Indexing
DataArray.getitem (key) | |
(key, value) | |
DataArray.loc | Attribute for location based indexing like pandas. |
([indexers, drop]) | Return a new DataArray whose data is given by integer indexing along the specified dimension(s). |
DataArray.sel ([indexers, method, tolerance, …]) | Return a new DataArray whose data is given by selecting index labels along the specified dimension(s). |
([dim, drop, axis]) | Return a new object with squeezed data. |
DataArray.interp ([coords, method, …]) | Multidimensional interpolation of variables. |
(other[, method, …]) | Interpolate this object onto the coordinates of another object, filling out of range values with NaN. |
DataArray.reindex ([indexers, method, …]) | Conform this object onto the indexes of another object, filling in missing values with fill_value . |
(other[, method, …]) | Conform this object onto the indexes of another object, filling in missing values with fill_value . |
DataArray.set_index ([indexes, append, inplace]) | Set DataArray (multi-)indexes using one or more existing coordinates. |
(dims_or_levels[, …]) | Reset the specified index(es) or multi-index level(s). |
DataArray.reorder_levels ([dim_order, inplace]) | Rearrange index levels using input order. |
(args, **kwargs) | |
DataArray.notnull (args, **kwargs) | |
(other) | Combine two DataArray objects, with union of coordinates. |
DataArray.count ([dim, axis]) | Reduce this DataArray’s data by applying count along some dimension(s). |
(dim[, how, thresh]) | Returns a new array with dropped labels for missing values along the provided dimension. |
DataArray.fillna (value) | Fill missing values in this object. |
(dim[, limit]) | Fill NaN values by propogating values forward |
DataArray.bfill (dim[, limit]) | Fill NaN values by propogating values backward |
([dim, method, …]) | Interpolate values according to different methods. |
DataArray.where (cond[, other, drop]) | Filter elements from this object according to a condition. |
(test_elements) | Tests each value in the array for whether it is in test elements. |
Comparisons
(other) | True if two DataArrays have the same dimensions, coordinates and values; otherwise False. |
DataArray.identical (other) | Like equals, but also checks the array name and attributes, and attributes on all coordinates. |
(other) | Two DataArrays are broadcast equal if they are equal after broadcasting them against each other such that they have the same dimensions. |
Computation
(func[, dim, axis, …]) | Reduce this array by applying func along some dimension(s). |
DataArray.groupby (group[, squeeze, …]) | Returns a GroupBy object for performing grouped operations. |
(group, bins[, right, …]) | Returns a GroupBy object for performing grouped operations. |
DataArray.rolling ([dim, min_periods, center]) | Rolling window object. |
([window, window_type]) | Exponentially-weighted moving window. |
DataArray.coarsen ([dim, boundary, side, …]) | Coarsen object. |
| Access datetime fields for DataArrays with datetime-like dtypes. |
DataArray.resample ([indexer, skipna, …]) | Returns a Resample object for performing resampling operations. |
(dim) | Return axis number(s) corresponding to dimension(s) in this array. |
DataArray.diff (dim[, n, label]) | Calculate the n-th order discrete difference along given axis. |
(other[, dims]) | Perform dot product of two DataArrays along their shared dims. |
DataArray.quantile (q[, dim, interpolation, …]) | Compute the qth quantile of the data along the specified dimension. |
(coord[, edge_order, …]) | Differentiate the array with the second order accurate central differences. |
DataArray.integrate (dim[, datetime_unit]) | integrate the array with the trapezoidal rule. |
| Vectorized string functions for string-like arrays. |
Aggregation:all
argmax
max
median
prod
std
ndarray methods:argsort
conj
imag
round
T
cumprod
Reshaping and reorganizing
(*dims[, transpose_coords]) | Return a new DataArray object with transposed dimensions. |
DataArray.stack ([dimensions]) | Stack any number of existing dimensions into a single new dimension. |
([dim]) | Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions. |
DataArray.to_unstacked_dataset (dim[, level]) | Unstack DataArray expanding to Dataset along a given level of a stacked coordinate. |
([shifts, fill_value]) | Shift this array by an offset along one or more dimensions. |
DataArray.roll ([shifts, roll_coords]) | Roll this array by an offset along one or more dimensions. |
(variables[, ascending]) | Sort object by labels or values (along an axis). |
Universal functions
Warning
With recent versions of numpy, dask and xarray, NumPy ufuncs are nowsupported directly on all xarray and dask objects. This obviates the needfor the xarray.ufuncs
module, which should not be used for new codeunless compatibility with versions of NumPy prior to v1.13 is required.
This functions are copied from NumPy, but extended to work on NumPy arrays,dask arrays and all xarray objects. You can find them in the xarray.ufuncs
module:
arccos
arcsin
arctan
arctanh
conj
cos
deg2rad
exp
fabs
floor
fmin
fmod
hypot
iscomplex
isinf
isreal
log1p
logaddexp
logical_and
logical_or
maximum
nextafter
radians
rint
signbit
sinh
square
tanh
Dataset methods
(filename_or_obj[, group, …]) | Open and decode a dataset from a file or file-like object. |
load_dataset (filename_or_obj, kwargs) | Open, load into memory, and close a Dataset from a file or file-like object. |
(paths[, chunks, concat_dim, …]) | Open multiple files as a single dataset. |
open_rasterio (filename[, parse_coordinates, …]) | Open a file with rasterio (experimental). |
(store[, group, synchronizer, …]) | Load and decode a dataset from a Zarr store. |
Dataset.to_netcdf ([path, mode, format, …]) | Write dataset contents to a netCDF file. |
([store, mode, synchronizer, …]) | Write dataset contents to a zarr group. |
save_mfdataset (datasets, paths[, mode, …]) | Write multiple datasets to disk as netCDF files simultaneously. |
([dim, name]) | Convert this dataset into an xarray.DataArray |
Dataset.to_dataframe () | Convert this dataset into a pandas.DataFrame. |
([dim_order, set_index]) | Convert this dataset into a dask.dataframe.DataFrame. |
Dataset.to_dict ([data]) | Convert this dataset to a dictionary following xarray naming conventions. |
(dataframe) | Convert a pandas.DataFrame into an xarray.Dataset |
Dataset.from_dict (d) | Convert a dictionary into an xarray.Dataset. |
() | Close any files linked to this object |
Dataset.compute (kwargs) | Manually trigger loading of this dataset’s data from disk or a remote source into memory and return a new dataset. |
(kwargs) | Trigger computation, keeping data as dask arrays |
Dataset.load (kwargs) | Manually trigger loading of this dataset’s data from disk or a remote source into memory and return this dataset. |
([chunks, name_prefix, token, lock]) | Coerce all arrays in this dataset into dask arrays with the given chunks. |
Dataset.filter_by_attrs (**kwargs) | Returns a Dataset with variables that match specific conditions. |
([buf]) | Concise summary of a Dataset variables and attributes. |
DataArray methods
(filename_or_obj[, group, …]) | Open an DataArray from a file or file-like object containing a single data variable. |
load_dataarray (filename_or_obj, kwargs) | Open, load into memory, and close a DataArray from a file or file-like object containing a single data variable. |
([dim, name]) | Convert a DataArray to a Dataset. |
DataArray.to_netcdf (*args, kwargs) | Write DataArray contents to a netCDF file. |
() | Convert this array into a pandas object with the same shape. |
DataArray.to_series () | Convert this array into a pandas.Series. |
([name]) | Convert this array and its coordinates into a tidy pandas.DataFrame. |
DataArray.to_index () | Convert this variable to a pandas.Index. |
([copy]) | Convert this array into a numpy.ma.MaskedArray |
DataArray.to_cdms2 () | Convert this array into a cdms2.Variable |
() | Convert this array into a iris.cube.Cube |
DataArray.from_iris (cube) | Convert a iris.cube.Cube into an xarray.DataArray |
([data]) | Convert this xarray.DataArray into a dictionary following xarray naming conventions. |
DataArray.from_series (series) | Convert a pandas.Series into an xarray.DataArray. |
(variable) | Convert a cdms2.Variable into an xarray.DataArray |
DataArray.from_dict (d) | Convert a dictionary into an xarray.DataArray |
() | Close any files linked to this object |
DataArray.compute (kwargs) | Manually trigger loading of this array’s data from disk or a remote source into memory and return a new array. |
(kwargs) | Trigger computation in constituent dask arrays |
DataArray.load (**kwargs) | Manually trigger loading of this array’s data from disk or a remote source into memory and return this array. |
([chunks, name_prefix, …]) | Coerce this array’s data into a dask arrays with the given chunks. |
GroupBy objects
Rolling objects
Resample objects
core.resample.DataArrayResample (args[, …]) | DataArrayGroupBy object specialized to time resampling operations over a specified dimension |
() | Return values of original object at the new up-sampling frequency; essentially a re-index with new times set to NaN. |
core.resample.DataArrayResample.backfill ([…]) | Backward fill new values at up-sampled frequency. |
([kind]) | Interpolate up-sampled data using the original data as knots. |
core.resample.DataArrayResample.nearest ([…]) | Take new values from nearest original coordinate to up-sampled frequency coordinates. |
([tolerance]) | Forward fill new values at up-sampled frequency. |
core.resample.DatasetResample (args[, dim, …]) | DatasetGroupBy object specialized to resampling a specified dimension |
() | Return values of original object at the new up-sampling frequency; essentially a re-index with new times set to NaN. |
core.resample.DatasetResample.backfill ([…]) | Backward fill new values at up-sampled frequency. |
([kind]) | Interpolate up-sampled data using the original data as knots. |
core.resample.DatasetResample.nearest ([…]) | Take new values from nearest original coordinate to up-sampled frequency coordinates. |
([tolerance]) | Forward fill new values at up-sampled frequency. |
Custom Indexes
| Custom Index for working with CF calendars and dates |
cftime_range ([start, end, periods, freq, …]) | Return a fixed frequency CFTimeIndex. |
Plotting
DataArray.plot | Access plotting functions |
(darray[, row, col, col_wrap, ax, …]) | Default plot of DataArray using matplotlib.pyplot. |
plot.contourf (x, y, z, ax, kwargs) | Filled contour plot of 2d DataArray |
(x, y, z, ax, kwargs) | Contour plot of 2d DataArray |
plot.hist (darray[, figsize, size, aspect, …]) | Histogram of DataArray |
(x, y, z, ax, *kwargs) | Image plot of 2d DataArray using matplotlib.pyplot |
plot.line (darray, args[, row, col, …]) | Line plot of DataArray index against values |
(x, y, z, ax[, infer_intervals]) | Pseudocolor plot of 2d DataArray |
plot.FacetGrid (data[, col, row, col_wrap, …]) | Initialize the matplotlib figure and FacetGrid object. |
Testing
MergeError | Error class for merge failures due to incompatible arguments. |
| Warnings about encoding/decoding issues in serialization. |
Advanced API
| Low level interface to Dataset contents as dict of Variable objects. |
DataArray.variable | Low level interface to the Variable object for this DataArray. |
(dims, data[, attrs, encoding, fastpath]) | A netcdf-like variable consisting of dimensions, data and attributes which describe a single Array. |
IndexVariable (dims, data[, attrs, encoding, …]) | Wrapper for accommodating a pandas.Index in an xarray.Variable. |
(obj[, name]) | Convert an object into a Variable. |
register_dataset_accessor (name) | Register a custom property on xarray.Dataset objects. |
(name) | Register a custom accessor on xarray.DataArray objects. |
These backends provide a low-level interface for lazily loading data fromexternal file-formats or protocols, and can be manually invoked to createarguments for the from_store
and dump_to_store
Dataset methods: