cf.DomainList.to_xarray

DomainList.to_xarray(group=True)[source]

Convert the list elements to an xarray Dataset.

If the cf_xarray package (https://cf-xarray.readthedocs.io) is installed then the cf_xarray accessors that allow some interpretation of CF attributes will be present on xarray.DataArray and xarray.Dataset objects.

Note that ds = fl.to_xarray() is identical to ds = cf.write(fl, fmt='XARRAY'). Also, cfdm.write allows a mixture of fields and domains to be written to the same xarray dataset.

Added in version 3.21.0.

See also

cf.write

Parameter:
group: bool, optional

If False then create a “flat” dataset, i.e. one with only the root group, regardless of any group structure specified by the netCDF interfaces of the list elements and their components. If True (the default) then any sub-groups will be created and populated.

Returns:
xarray.Dataset or xarray.DataTree

The equivalent xarray dataset.

If there are no sub-groups of the root group, or if group is False, then an xarray.Dataset is returned.

If there are sub-groups of the root group and group is True, then an xarray.DataTree is returned.