xray.DataArray

class xray.DataArray

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.

Under the covers, a DataArray is a thin wrapper around an xray Dataset, and is uniquely defined by its dataset and name parameters.

Attributes

values The variables’s data as a numpy.ndarray
coordinates Dictionary of Coordinate objects used for label based indexing.
dimensions (tuple) Dimension names associated with this array.

Methods

all([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.all along some dimension(s).
any([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.any along some dimension(s).
argmax([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.argmax along some dimension(s).
argmin([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.argmin along some dimension(s).
argsort(*args, **kwargs)
astype(*args, **kwargs)
clip(*args, **kwargs)
concat(arrays[, dimension, indexers, ...]) Stack arrays along a new or existing dimension to form a new DataArray.
conj(*args, **kwargs)
conjugate(*args, **kwargs)
copy([deep]) Returns a copy of this array.
equals(other) True if two DataArrays have the same dimensions, coordinates and values; otherwise False.
from_series(series) Convert a pandas.Series into an xray.DatasetArray
get_axis_num(dimension) Return axis number(s) corresponding to dimension(s) in this array.
groupby(group[, squeeze]) Group this dataset by unique values of the indicated group.
identical(other) Like equals, but also checks DataArray names and attributes, and attributes on their coordinates.
indexed(**indexers) Return a new DataArray whose dataset is given by indexing along the specified dimension(s).
item() Calls numpy.ndarray.item on this array’s values
labeled(**indexers) Return a new DataArray whose dataset is given by selecting coordinate labels along the specified dimension(s).
max([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.max along some dimension(s).
mean([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.mean along some dimension(s).
min([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.min along some dimension(s).
prod([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.prod along some dimension(s).
ptp([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.ptp along some dimension(s).
reduce(func[, dimension, axis]) Reduce this array by applying func along some dimension(s).
reindex([copy]) Conform this object onto a new set of coordinates or pandas.Index objects, filling in missing values with NaN.
reindex_like(other[, copy]) Conform this object onto the coordinates of another object, filling in missing values with NaN.
rename(new_name_or_name_dict) Returns a new DataArray with renamed variables.
round(*args, **kwargs)
select(*names) Returns a new DataArray with only the named variables, as well as this DataArray’s array variable (and all associated coordinates).
squeeze([dimension]) Return a new DataArray object with squeezed data.
std([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.std along some dimension(s).
sum([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.sum along some dimension(s).
to_dataframe() Convert this array into a pandas.DataFrame.
to_series() Convert this array into a pandas.Series.
transpose(*dimensions) Return a new DataArray object with transposed dimensions.
unselect(*names) Returns a new DataArray without the named variables.
var([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.var along some dimension(s).
__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

Methods

all([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.all along some dimension(s).
any([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.any along some dimension(s).
argmax([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.argmax along some dimension(s).
argmin([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.argmin along some dimension(s).
argsort(*args, **kwargs)
astype(*args, **kwargs)
clip(*args, **kwargs)
concat(arrays[, dimension, indexers, ...]) Stack arrays along a new or existing dimension to form a new DataArray.
conj(*args, **kwargs)
conjugate(*args, **kwargs)
copy([deep]) Returns a copy of this array.
equals(other) True if two DataArrays have the same dimensions, coordinates and values; otherwise False.
from_series(series) Convert a pandas.Series into an xray.DatasetArray
get_axis_num(dimension) Return axis number(s) corresponding to dimension(s) in this array.
groupby(group[, squeeze]) Group this dataset by unique values of the indicated group.
identical(other) Like equals, but also checks DataArray names and attributes, and attributes on their coordinates.
indexed(**indexers) Return a new DataArray whose dataset is given by indexing along the specified dimension(s).
item() Calls numpy.ndarray.item on this array’s values
labeled(**indexers) Return a new DataArray whose dataset is given by selecting coordinate labels along the specified dimension(s).
max([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.max along some dimension(s).
mean([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.mean along some dimension(s).
min([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.min along some dimension(s).
prod([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.prod along some dimension(s).
ptp([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.ptp along some dimension(s).
reduce(func[, dimension, axis]) Reduce this array by applying func along some dimension(s).
reindex([copy]) Conform this object onto a new set of coordinates or pandas.Index objects, filling in missing values with NaN.
reindex_like(other[, copy]) Conform this object onto the coordinates of another object, filling in missing values with NaN.
rename(new_name_or_name_dict) Returns a new DataArray with renamed variables.
round(*args, **kwargs)
select(*names) Returns a new DataArray with only the named variables, as well as this DataArray’s array variable (and all associated coordinates).
squeeze([dimension]) Return a new DataArray object with squeezed data.
std([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.std along some dimension(s).
sum([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.sum along some dimension(s).
to_dataframe() Convert this array into a pandas.DataFrame.
to_series() Convert this array into a pandas.Series.
transpose(*dimensions) Return a new DataArray object with transposed dimensions.
unselect(*names) Returns a new DataArray without the named variables.
var([dimension, axis]) Reduce this DataArray’s data’ by applying numpy.var along some dimension(s).

Attributes

T
as_index The variable’s data as a pandas.Index.
attributes
attrs Dictionary storing arbitrary metadata with this array.
coordinates Dictionary of Coordinate objects used for label based indexing.
dataset The dataset with which this DataArray is associated.
dimensions
dtype
encoding Dictionary of format-specific settings for how this array should be serialized.
loc Attribute for location based indexing like pandas..
name The name of the variable in dataset to which array operations are applied.
ndim
shape
size
values The variables’s data as a numpy.ndarray
variable