xarray accessor#

Much of the functionality of emsarray is accessed using the .ems attribute on an xarray Dataset.

dataset.ems: emsarray.conventions.Convention#

This accessor will automatically determine the geometry convention used in the dataset and create the appropriate Convention instance for this dataset.

Using the accessor#

Every xarray dataset will have a .ems attribute. This includes datasets opened with xarray.open_dataset(), xarray.open_mfdataset(), and emsarray.open_dataset():

import emsarray

dataset = emsarray.tutorial.open_dataset('austen')
dataset.ems.plot(dataset['eta'].isel(record=0))

Refer to the Convention documentation for a full list of available methods, and the available operations modules for more.

Registering the accessor#

emsarray registers the dataset.ems dataset accessor when it is is first imported.

You can not access the dataset.ems attribute before emsarray is imported. The following example will fail as emsarray has not been imported:

Incorrect#
>>> import xarray
>>> dataset = xarray.tutorial.open_dataset('air_temperature')
>>> dataset.ems.plot(dataset['air'].isel(time=0))
AttributeError: 'Dataset' object has no attribute 'ems'

To fix this, make sure to import emsarray before opening your datasets:

Correct#
>>> import xarray
>>> import emsarray
>>> dataset = xarray.tutorial.open_dataset('air_temperature')
>>> dataset.ems.plot(dataset['air'].isel(time=0))

The emsarray.open_dataset() shortcut is available. Using this function ensures that the dataset accessor is registered, and that the dataset uses a geometry convention that emsarray understands. Using this function is not required to access emsarray functionality.

Using emsarray.open_dataset()#
>>> import emsarray
>>> dataset = emsarray.open_dataset('path/to/dataset.nc')
>>> dataset.ems.plot(dataset['temp'].isel(record=0))