code: def preprocess_attrs(
      data_arr: xr.DataArray,
      flatten_attrs: bool,
      exclude_attrs: list[str] | None,
  ) -> xr.DataArray:
      """Preprocess DataArray attributes to be written into CF-compliant netCDF/Zarr."""
      _drop_attrs(data_arr, exclude_attrs)
      _add_ancillary_variables_attrs(data_arr)
      _format_prerequisites_attrs(data_arr)
  
      if (
          "long_name" not in data_arr.attrs
          and "standard_name" not in data_arr.attrs
      ):
          data_arr.attrs["long_name"] = data_arr.name
  
      if flatten_attrs:
          data_arr.attrs = flatten_dict(data_arr.attrs)
  
      data_arr.attrs = _encode_nc_attrs(data_arr.attrs)
  
      return data_arr
  
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 7 for calling a global function with example usage: preprocess_attrs(data_arr, flatten_attrs, exclude_attrs) and returns: data_arr