class_docstr: Writer producing NetCDF/CF compatible datasets.
class_docstr_tok: ["Writer","producing","NetCDF\/CF","compatible","datasets","."]
docstr: Save the given datasets in one netCDF file.
  
  Note that all datasets (if grouping: in one group) must have the same projection coordinates.
  
  Args:
      datasets (list): List of xr.DataArray to be saved.
      filename (str): Output file.
      groups (dict): Group datasets according to the given assignment:
          `{'group_name': ['dataset1', 'dataset2', ...]}`.
          The group name `None` corresponds to the root of the file, i.e., no group will be created.
          Warning: The results will not be fully CF compliant!
      header_attrs: Global attributes to be included.
      engine (str, optional): Module to be used for writing netCDF files. Follows xarray's
          :meth:`~xarray.Dataset.to_netcdf` engine choices with a preference for 'netcdf4'.
      epoch (str, optional): Reference time for encoding of time coordinates.
          If None, the default reference time is defined using `from satpy.cf.coords import EPOCH`.
      flatten_attrs (bool, optional): If True, flatten dict-type attributes.
      exclude_attrs (list, optional): List of dataset attributes to be excluded.
      include_lonlats (bool, optional): Always include latitude and longitude coordinates,
          even for datasets with area definition.
      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 final netCDF.
      numeric_name_prefix (str, optional): Prefix to add to each variable with a name starting with a digit.
          Use '' or None to leave this out.
docstr_tok: ["Save","the","given","datasets","in","one","netCDF","file",".","Note","that","all","datasets","(","if","grouping",":","in","one","group",")","must","have","the","same","projection","coordinates",".","Args",":","datasets","(","list",")",":","List","of","xr.DataArray","to","be","saved",".","filename","(","str",")",":","Output","file",".","groups","(","dict",")",":","Group","datasets","according","to","the","given","assignment",":","`","{","'group_name","'",":","[","'dataset1","'",",","'dataset2","'",",","...","]","}","`",".","The","group","name","`","None","`","corresponds","to","the","root","of","the","file",",","i.e.",",","no","group","will","be","created",".","Warning",":","The","results","will","not","be","fully","CF","compliant","!","header_attrs",":","Global","attributes","to","be","included",".","engine","(","str",",","optional",")",":","Module","to","be","used","for","writing","netCDF","files",".","Follows","xarray's",":","meth",":","`","~xarray.Dataset.to_netcdf","`","engine","choices","with","a","preference","for","'netcdf4","'",".","epoch","(","str",",","optional",")",":","Reference","time","for","encoding","of","time","coordinates",".","If","None",",","the","default","reference","time","is","defined","using","`","from","satpy.cf.coords","import","EPOCH","`",".","flatten_attrs","(","bool",",","optional",")",":","If","True",",","flatten","dict-type","attributes",".","exclude_attrs","(","list",",","optional",")",":","List","of","dataset","attributes","to","be","excluded",".","include_lonlats","(","bool",",","optional",")",":","Always","include","latitude","and","longitude","coordinates",",","even","for","datasets","with","area","definition",".","pretty","(","bool",",","optional",")",":","Do","n'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","final","netCDF",".","numeric_name_prefix","(","str",",","optional",")",":","Prefix","to","add","to","each","variable","with","a","name","starting","with","a","digit",".","Use","``","or","None","to","leave","this","out","."]
code: def save_datasets(
      self,
      datasets,
      filename=None,
      groups=None,
      header_attrs=None,
      engine=None,
      epoch=None,  # noqa: D417
      flatten_attrs=False,
      exclude_attrs=None,
      include_lonlats=True,
      pretty=False,
      include_orig_name=True,
      numeric_name_prefix="CHANNEL_",
      **to_netcdf_kwargs,
  ):
      """Save the given datasets in one netCDF file.
  
      Note that all datasets (if grouping: in one group) must have the same projection coordinates.
  
      Args:
          datasets (list): List of xr.DataArray to be saved.
          filename (str): Output file.
          groups (dict): Group datasets according to the given assignment:
              `{'group_name': ['dataset1', 'dataset2', ...]}`.
              The group name `None` corresponds to the root of the file, i.e., no group will be created.
              Warning: The results will not be fully CF compliant!
          header_attrs: Global attributes to be included.
          engine (str, optional): Module to be used for writing netCDF files. Follows xarray's
              :meth:`~xarray.Dataset.to_netcdf` engine choices with a preference for 'netcdf4'.
          epoch (str, optional): Reference time for encoding of time coordinates.
              If None, the default reference time is defined using `from satpy.cf.coords import EPOCH`.
          flatten_attrs (bool, optional): If True, flatten dict-type attributes.
          exclude_attrs (list, optional): List of dataset attributes to be excluded.
          include_lonlats (bool, optional): Always include latitude and longitude coordinates,
              even for datasets with area definition.
          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 final netCDF.
          numeric_name_prefix (str, optional): Prefix to add to each variable with a name starting with a digit.
              Use '' or None to leave this out.
      """
      from satpy.cf.datasets import collect_cf_datasets
      from satpy.cf.encoding import update_encoding
  
      logger.info("Saving datasets to NetCDF4/CF.")
      _check_backend_versions()
  
      # Define netCDF filename if not provided
      # - It infers the name from the first DataArray
      filename = filename or self.get_filename(**datasets[0].attrs)
  
      # Collect xr.Dataset for each group
      grouped_datasets, header_attrs = collect_cf_datasets(
          list_dataarrays=datasets,  # list of xr.DataArray
          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=groups,
      )
      # Remove satpy-specific kwargs
      # - This kwargs can contain encoding dictionary
      to_netcdf_kwargs = _sanitize_writer_kwargs(to_netcdf_kwargs)
  
      # If writing grouped netCDF, create an empty "root" netCDF file
      # - Add the global attributes
      # - All groups will be appended in the for loop below
      if groups is not None:
          written = _initialize_root_netcdf(
              filename=filename,
              engine=engine,
              header_attrs=header_attrs,
              to_netcdf_kwargs=to_netcdf_kwargs,
          )
          mode = "a"
      else:
          mode = "w"
          written = []
  
      # Write the netCDF
      # - If grouped netCDF, it appends to the root file
      # - If single netCDF, it write directly
      for group_name, ds in grouped_datasets.items():
          encoding, other_to_netcdf_kwargs = update_encoding(
              ds,
              to_engine_kwargs=to_netcdf_kwargs,
              numeric_name_prefix=numeric_name_prefix,
          )
          res = ds.to_netcdf(
              filename,
              engine=engine,
              group=group_name,
              mode=mode,
              encoding=encoding,
              **other_to_netcdf_kwargs,
          )
          written.append(res)
      return written
  
file_path: satpy/satpy/writers/cf_writer.py
imports: import copy
  import logging
  import warnings
  import numpy
  import xarray
  from packaging.version import Version
  from satpy.cf.coords import EPOCH
  from satpy.writers import Writer
label_desc: Use image node_id 2 for calling the CFWriter obj's underlying member method code with example usage: obj.save_datasets(datasets, filename, groups, header_attrs, engine, epoch, flatten_attrs, exclude_attrs, include_lonlats, pretty, include_orig_name, numeric_name_prefix) and returns: written