code: def _encode_nc_attrs(attrs):
      """Encode dataset attributes in a netcdf compatible datatype.
  
      Args:
          attrs (dict):
              Attributes to be encoded
      Returns:
          dict: Encoded (and sorted) attributes
  
      """
      encoded_attrs = []
      for key, val in sorted(attrs.items()):
          if val is not None:
              encoded_attrs.append((key, _encode_to_cf(val)))
      return OrderedDict(encoded_attrs)
  
imports: from __future__ import annotations
  import datetime
  import json
  import logging
  from collections import OrderedDict
  import numpy
  import xarray
  from satpy.writers.utils import flatten_dict
label_desc: Use image node_id 6 for calling a global function with example usage: _encode_nc_attrs(attrs) and returns: OrderedDict