API reference¶
This page provides an auto-generated summary of xray’s API. For more details and examples, refer to the relevant chapter in the main part of the documentation.
Top-level functions¶
align(*objects[, join, copy]) | Given any number of Dataset and/or DataArray objects, returns new objects with aligned indexes. |
concat(objs[, dim, indexers, mode, ...]) | Concatenate xray objects along a new or existing dimension. |
Dataset¶
Creating a dataset¶
Dataset([variables, coords, attrs]) | A multi-dimensional, in memory, array database. |
open_dataset(filename_or_obj[, decode_cf, ...]) | Load and decode a dataset from a file or file-like object. |
decode_cf(obj[, concat_characters, ...]) | Decode the given Dataset or Datastore according to CF conventions into a new Dataset. |
Attributes¶
Dataset.dims | Mapping from dimension names to lengths. |
Dataset.vars | |
Dataset.coords | Dictionary of xray.Coordinate objects used for label based indexing. |
Dataset.attrs | Dictionary of global attributes on this dataset |
Dictionary interface¶
Datasets implement the mapping interface with keys given by variable names and values given by DataArray objects.
Dataset.__getitem__(key) | Access variables or coordinates 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.iteritems(...) | |
Dataset.itervalues(...) |
Dataset contents¶
Dataset.copy([deep]) | Returns a copy of this dataset. |
Dataset.merge(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. |
Dataset.drop_vars(*names) | Returns a new dataset without the named variables. |
Dataset.set_coords(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. |
Dataset.identical(other) | Like equals, but also checks all dataset attributes and the attributes on all variables and coordinates. |
Indexing¶
Dataset.loc | Attribute for location based indexing. |
Dataset.isel(**indexers) | Returns a new dataset with each array indexed along the specified dimension(s). |
Dataset.sel(**indexers) | Returns a new dataset with each array indexed by tick labels along the specified dimension(s). |
Dataset.squeeze([dim]) | Returns a new dataset with squeezed data. |
Dataset.reindex([indexers, copy]) | Conform this object onto a new set of indexes, filling in missing values with NaN. |
Dataset.reindex_like(other[, copy]) | Conform this object onto the indexes of another object, filling in missing values with NaN. |
Computation¶
Dataset.apply(func[, keep_attrs, args]) | Apply a function over the variables in this dataset. |
Dataset.reduce(func[, dim, keep_attrs]) | Reduce this dataset by applying func along some dimension(s). |
Dataset.groupby(group[, squeeze]) | Returns a GroupBy object for performing grouped operations. |
Dataset.transpose(*dims) | Return a new Dataset object with all array dimensions transposed. |
Aggregation: all any argmax argmin max mean min prod sum std var
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 files linked to 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. |
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¶
DataArray.values | The array’s data as a numpy.ndarray |
DataArray.coords | Dictionary-like container of coordinate arrays. |
DataArray.dims | Dimension names associated with this array. |
DataArray.name | The name of this array. |
DataArray.attrs | Dictionary storing arbitrary metadata with this array. |
DataArray.encoding | Dictionary of format-specific settings for how this array should be serialized. |
DataArray contents¶
DataArray.rename(new_name_or_name_dict) | Returns a new DataArray with renamed coordinates and/or a new name. |
DataArray.reset_coords([names, drop, inplace]) | Given names of coordinates, reset them to become variables. |
DataArray.copy([deep]) | Returns a copy of this array. |
Indexing¶
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.squeeze([dim]) | Return a new DataArray object with squeezed data. |
DataArray.reindex([copy]) | Conform this object onto a new set of indexes, filling in missing values with NaN. |
DataArray.reindex_like(other[, copy]) | Conform this object onto the indexes of another object, filling in missing values with NaN. |
Computation¶
DataArray.reduce(func[, dim, axis, keep_attrs]) | Reduce this array by applying func along some dimension(s). |
DataArray.groupby(group[, squeeze]) | Returns a GroupBy object for performing grouped operations. |
DataArray.transpose(*dims) | Return a new DataArray object with transposed dimensions. |
DataArray.get_axis_num(dim) | Return axis number(s) corresponding to dimension(s) in this array. |
Aggregation: all any argmax argmin max mean min prod sum std var
Missing values: isnull notnull count dropna
ndarray methods: argsort clip conj conjugate searchsorted round T
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 the array name and attributes, and attributes on all coordinates. |
IO / Conversion¶
DataArray.to_dataset([name]) | Convert a DataArray to a Dataset |
DataArray.to_pandas() | Convert this array into a pandas object with the same shape. |
DataArray.to_series() | Convert this array into a pandas.Series. |
DataArray.to_dataframe() | Convert this array and its coordinates into a tidy pandas.DataFrame. |
DataArray.to_index() | Convert this variable to a pandas.Index. |
DataArray.to_cdms2() | Convert this array into a cdms2.Variable |
DataArray.from_series(series) | Convert a pandas.Series into an xray.DataArray. |
DataArray.from_cdms2(variable) | Convert a cdms2.Variable into an xray.DataArray |
DataArray.load_data() | Manually trigger loading of this array’s data from disk or a remote source into memory and return this array. |