def Field_to_xarray(field):
dom = field.domain<EOL>dims = []; dimlist = []; coords = {};<EOL>for axname in dom.axes:<EOL><INDENT>dimlist.append(axname)<EOL>try:<EOL><INDENT>assert field.interfaces[dom.axis_index[axname]]<EOL>bounds_name = axname + '<STR_LIT>'<EOL>dims.append(bounds_name)<EOL>coords[bounds_name] = dom.axes[axname].bounds<EOL><DEDENT>except:<EOL><INDENT>dims.append(axname)<EOL>coords[axname] = dom.axes[axname].points<EOL><DEDENT><DEDENT>da = DataArray(field.transpose([dom.axis_index[name] for name in dimlist]),<EOL>dims=dims, coords=coords)<EOL>for name in dims:<EOL><INDENT>try:<EOL><INDENT>da[name].attrs['<STR_LIT>'] = dom.axes[name].units<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return da<EOL>
Convert a climlab.Field object to xarray.DataArray