xray.DataArray

class xray.DataArray(data, coords=None, dims=None, name=None, attrs=None, encoding=None)

N-dimensional array with labeled coordinates and dimensions.

DataArray provides a wrapper around numpy ndarrays that uses labeled dimensions and coordinates to support metadata aware operations. The API is similar to that for the pandas Series or DataFrame, but DataArray objects can have any number of dimensions, and their contents have fixed data types.

Additional features over raw numpy arrays:

  • Apply operations over dimensions by name: x.sum('time').
  • Select or assign values by integer location (like numpy): x[:10] or by label (like pandas): x.loc['2014-01-01'] or x.labeled(time='2014-01-01').
  • Mathematical operations (e.g., x - y) vectorize across multiple dimensions (known in numpy as “broadcasting”) based on dimension names, regardless of their original order.
  • Keep track of arbitrary metadata in the form of a Python dictionary: x.attrs
  • Convert to a pandas Series: x.to_series().

Getting items from or doing mathematical operations with a DataArray always returns another DataArray.

Attributes

dims Dimension names associated with this array.
values The array’s data as a numpy.ndarray
coords Dictionary-like container of coordinate arrays.
name The name of this array.
attrs Dictionary storing arbitrary metadata with this array.
__init__(data, coords=None, dims=None, name=None, attrs=None, encoding=None)
Parameters:

data : array_like

Values for this array. Must be a numpy.ndarray, ndarray like, or castable to an ndarray. If a self-described xray or pandas object, attempst are made to use this array’s metadata to fill in other unspecified arguments.

coords : sequence or dict of array_like objects, optional

Coordinates (tick labels) to use for indexing along each dimension. If dict-like, should be a mapping from dimension names to the corresponding coordinates.

dims : str or sequence of str, optional

Name(s) of the the data dimension(s). Must be either a string (only for 1D data) or a sequence of strings with length equal to the number of dimensions. If this argument is omited, dimension names are taken from coords (if possible) and otherwise default to ['dim_0', ... 'dim_n'].

name : str or None, optional

Name of this array.

attrs : dict_like or None, optional

Attributes to assign to the new variable. By default, an empty attribute dictionary is initialized.

encoding : dict_like or None, optional

Dictionary specifying how to encode this array’s data into a serialized format like netCDF4. Currently used keys (for netCDF) include ‘_FillValue’, ‘scale_factor’, ‘add_offset’, ‘dtype’, ‘units’ and ‘calendar’ (the later two only for datetime arrays). Unrecognized keys are ignored.

Methods

__init__(data[, coords, dims, name, attrs, ...])
Parameters:
all([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.all along some dimension(s).
any([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.any along some dimension(s).
argmax([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.argmax along some dimension(s).
argmin([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.argmin along some dimension(s).
argsort([axis, kind, order]) Returns the indices that would sort this array.
astype(dtype[, order, casting, subok, copy]) Copy of the array, cast to a specified type.
clip(a_min, a_max[, out]) Return an array whose values are limited to [a_min, a_max].
concat(*args, **kwargs) Deprecated; use xray.concat instead
conj() Complex-conjugate all elements.
conjugate() Return the complex conjugate, element-wise.
copy([deep]) Returns a copy of this array.
count([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying count along some dimension(s).
drop_vars(*names) Deprecated; use reset_coords(names, drop=True) instead
dropna(dim[, how, thresh]) Returns a new array with dropped labels for missing values along the provided dimension.
equals(other) True if two DataArrays have the same dimensions, coordinates and values; otherwise False.
from_cdms2(variable) Convert a cdms2.Variable into an xray.DataArray
from_series(series) Convert a pandas.Series into an xray.DataArray.
get_axis_num(dim) Return axis number(s) corresponding to dimension(s) in this array.
groupby(group[, squeeze]) Returns a GroupBy object for performing grouped operations.
identical(other) Like equals, but also checks the array name and attributes, and attributes on all coordinates.
indexed(*args, **kwargs) Return a new DataArray whose dataset is given by integer indexing along the specified dimension(s).
isel(**indexers) Return a new DataArray whose dataset is given by integer indexing along the specified dimension(s).
isnull(*args, **kwargs) Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
item(*args) Copy an element of an array to a standard Python scalar and return it.
labeled(*args, **kwargs) Return a new DataArray whose dataset is given by selecting index labels along the specified dimension(s).
load_data() Manually trigger loading of this array’s data from disk or a remote source into memory and return this array.
max([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.max along some dimension(s).
mean([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.mean along some dimension(s).
min([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.min along some dimension(s).
notnull(*args, **kwargs) Replacement for numpy.isfinite / -numpy.isnan which is suitable for use on object arrays.
prod([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.prod along some dimension(s).
ptp([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.ptp along some dimension(s).
reduce(func[, dim, axis, keep_attrs]) Reduce this array by applying func along some dimension(s).
reindex([copy]) Conform this object onto a new set of indexes, filling in missing values with NaN.
reindex_like(other[, copy]) Conform this object onto the indexes of another object, filling in missing values with NaN.
rename(new_name_or_name_dict) Returns a new DataArray with renamed coordinates and/or a new name.
reset_coords([names, drop, inplace]) Given names of coordinates, reset them to become variables.
round([decimals, out]) Return a with each element rounded to the given number of decimals.
searchsorted(v[, side, sorter]) Find indices where elements of v should be inserted in a to maintain order.
sel(**indexers) Return a new DataArray whose dataset is given by selecting index labels along the specified dimension(s).
select(*args, **kwargs) Returns a new DataArray with only the named variables, as well as this DataArray’s array variable (and all associated coordinates).
select_vars(*names) Returns a new DataArray with only the named variables, as well as this DataArray’s array variable (and all associated coordinates).
squeeze([dim]) Return a new DataArray object with squeezed data.
std([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.std along some dimension(s).
sum([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.sum along some dimension(s).
to_cdms2() Convert this array into a cdms2.Variable
to_dataframe() Convert this array and its coordinates into a tidy pandas.DataFrame.
to_dataset([name]) Convert a DataArray to a Dataset
to_index() Convert this variable to a pandas.Index.
to_pandas() Convert this array into a pandas object with the same shape.
to_series() Convert this array into a pandas.Series.
transpose(*dims) Return a new DataArray object with transposed dimensions.
unselect(*args, **kwargs) Deprecated; use reset_coords(names, drop=True) instead
var([dim, axis, keep_attrs]) Reduce this DataArray’s data by applying numpy.var along some dimension(s).

Attributes

T
as_index
attributes
attrs Dictionary storing arbitrary metadata with this array.
coordinates
coords Dictionary-like container of coordinate arrays.
dataset The dataset with which this DataArray is associated.
dimensions Deprecated; use dims instead
dims Dimension names associated with this array.
dtype
encoding Dictionary of format-specific settings for how this array should be serialized.
indexes OrderedDict of pandas.Index objects used for label based indexing
loc Attribute for location based indexing like pandas.
name The name of this array.
ndim
shape
size
values The array’s data as a numpy.ndarray
variable