def state_to_xarray(state):
from climlab.domain.field import Field<EOL>ds = Dataset()<EOL>for name, field in state.items():<EOL><INDENT>if isinstance(field, Field):<EOL><INDENT>ds[name] = Field_to_xarray(field)<EOL>dom = field.domain<EOL>for axname, ax in dom.axes.items():<EOL><INDENT>bounds_name = axname + '<STR_LIT>'<EOL>ds.coords[bounds_name] = DataArray(ax.bounds, dims=[bounds_name],<EOL>coords={bounds_name:ax.bounds})<EOL>try:<EOL><INDENT>ds[bounds_name].attrs['<STR_LIT>'] = ax.units<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>warnings.warn('<STR_LIT>'.format(name))<EOL><DEDENT><DEDENT>return ds<EOL>
Convert a dictionary of climlab.Field objects to xarray.Dataset

    Input: dictionary of climlab.Field objects
    (e.g. process.state or process.diagnostics dictionary)

    Output: xarray.Dataset object with all spatial axes,
    including 'bounds' axes indicating cell boundaries in each spatial dimension.

    Any items in the dictionary that are not instances of climlab.Field
    are ignored.