code: def convert_units(dataset, in_unit, out_unit):
      """Convert units of *dataset*.
  
      Convert dataset units for the benefit of writing NinJoTIFF.  The main
      background here is that NinJoTIFF would like brightness temperatures in °C,
      but satellite data files are in K.  For simplicity of implementation, this
      function can only convert from K to °C.
  
      This function will convert input data from K to °C and write the new unit
      in the ``"units"`` attribute.  When output and input units are equal, it
      returns the input dataset.
  
      Args:
          dataset (xarray DataArray):
              Dataarray for which to convert the units.
          in_unit (str):
              Unit for input data.
          out_unit (str):
              Unit for output data.
  
      Returns:
          dataset, possibly with new units.
      """
      if in_unit == out_unit:
          return dataset
  
      if in_unit.lower() in {"k", "kelvin"} and out_unit.lower() in {
          "c",
          "celsius",
      }:
          logger.debug("Converting temperature units from K to °C")
          with xr.set_options(keep_attrs=True):
              new_dataset = dataset - 273.15
          new_dataset.attrs["units"] = out_unit
          return new_dataset
  
      # Other units not implemented.  Before Satpy 0.16.1 there was a
      # non-working implementation based on pint here.
  
      raise NotImplementedError(
          "NinJoTIFF unit conversion only implemented between K and C, not "
          f"between {in_unit!s} and {out_unit!s}"
      )
  
file_path: satpy/satpy/writers/ninjotiff.py
imports: import logging
  import numpy
  import pyninjotiff.ninjotiff
  import xarray
  from trollimage.xrimage import invert_scale_offset
  from satpy.writers import ImageWriter
label_desc: Use image node_id 1 for calling a global function with example usage: convert_units(dataset, in_unit, out_unit) and returns: dataset, new_dataset