code: def to_xarray(
      scn,
      datasets=None,  # DataID
      header_attrs=None,
      exclude_attrs=None,
      flatten_attrs=False,
      pretty=True,
      include_lonlats=True,
      epoch=None,
      include_orig_name=True,
      numeric_name_prefix="CHANNEL_",
  ):
      """Merge all xr.DataArray(s) of a satpy.Scene to a CF-compliant xarray object.
  
      If all Scene DataArrays are on the same area, it returns an xr.Dataset.
      If Scene DataArrays are on different areas, currently it fails, although
      in future we might return a DataTree object, grouped by area.
  
      Args:
          scn (satpy.Scene): Satpy Scene.
          datasets (iterable, optional): List of Satpy Scene datasets to include in
              the output xr.Dataset. Elements can be string name, a wavelength as a
              number, a DataID, or DataQuery object. If None (the default), it
              includes all loaded Scene datasets.
          header_attrs: Global attributes of the output xr.Dataset.
          epoch (str, optional): Reference time for encoding the time coordinates
              (if available). Format example: "seconds since 1970-01-01 00:00:00".
              If None, the default reference time is retrieved using
              "from satpy.cf_writer import EPOCH".
          flatten_attrs (bool, optional): If True, flatten dict-type attributes.
          exclude_attrs (list, optional): List of xr.DataArray attribute names to
              be excluded.
          include_lonlats (bool, optional): If True, includes 'latitude' and
              'longitude' coordinates. If the 'area' attribute is a SwathDefinition,
              it always includes latitude and longitude coordinates.
          pretty (bool, optional): Don't modify coordinate names, if possible. Makes
              the file prettier, but possibly less consistent.
          include_orig_name (bool, optional): Include the original dataset name as a
              variable attribute in the xr.Dataset.
          numeric_name_prefix (str, optional): Prefix to add to each variable with
              name starting with a digit. Use '' or None to leave this out.
  
      Returns:
          xr.Dataset: A CF-compliant xr.Dataset
  
      """
      from satpy.cf.datasets import collect_cf_datasets
  
      # Get list of DataArrays
      if datasets is None:
          datasets = list(scn.keys())  # list all loaded DataIDs
      list_dataarrays = _get_dataarrays_from_identifiers(scn, datasets)
  
      # Check that some DataArray could be returned
      if len(list_dataarrays) == 0:
          return xr.Dataset()
  
      # Collect xr.Dataset for each group
      grouped_datasets, header_attrs = collect_cf_datasets(
          list_dataarrays=list_dataarrays,
          header_attrs=header_attrs,
          exclude_attrs=exclude_attrs,
          flatten_attrs=flatten_attrs,
          pretty=pretty,
          include_lonlats=include_lonlats,
          epoch=epoch,
          include_orig_name=include_orig_name,
          numeric_name_prefix=numeric_name_prefix,
          groups=None,
      )
      if len(grouped_datasets) == 1:
          ds = grouped_datasets[None]
          return ds
      else:
          msg = """The Scene object contains datasets with different areas.
                    Resample the Scene to have matching dimensions using i.e. scn.resample(resampler="native") """
          raise NotImplementedError(msg)
  
imports: import xarray
  from satpy.composites import enhance2dataset
  from satpy.dataset import DataID
label_desc: Use image node_id 4 for calling a global function with example usage: to_xarray(scn, datasets, header_attrs, exclude_attrs, flatten_attrs, pretty, include_lonlats, epoch, include_orig_name, numeric_name_prefix) and returns: xr, ds