# Buggy code
def adjust_scaling_factors(self, factors, file_units, output_units):
    if file_units == output_units:
        LOG.debug("File units and output units are the same (%s)", file_units)
        return factors
    if factors is None:
        factors = [1, 0]
    factors = np.array(factors)

    if file_units == "W cm-2 sr-1" and output_units == "W m-2 sr-1":
        LOG.debug(
            "Adjusting scaling factors to convert '%s' to '%s'",
            file_units,
            output_units,
        )
        factors[::2] = np.where(factors[::2] != -999, factors[::2] * 10000.0, -999)
        factors[1::2] = np.where(factors[1::2] != -999, factors[1::2] * 10000.0, -999)
        return factors
    elif file_units == "1" and output_units == "%":
        LOG.debug(
            "Adjusting scaling factors to convert '%s' to '%s'",
            file_units,
            output_units,
        )
        factors[::2] = np.where(factors[::2] != -999, factors[::2] * 100.0, -999)
        factors[1::2] = np.where(factors[1::2] != -999, factors[1::2] * 100.0, -999)
        return factors
    else:
        return factors


# Traceback (AttributeError)
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] Saving datasets to NetCDF4/CF.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No longitude and latitude data to save.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No grid mapping to save.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-58ece08c15f3> in <module>()
----> 1 lcl.save_datasets(writer='cf', filename='/tmp/foo.nc')

/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.pyc in save_datasets(self, writer, datasets, **kwargs)
632             datasets = self.datasets.values()
633         writer = self.get_writer(writer, **kwargs)
--> 634         writer.save_datasets(datasets, **kwargs)
635
636     def get_writer(self, writer="geotiff", **kwargs):

/home/lahtinep/Software/pytroll/packages/satpy/satpy/writers/cf_writer.pyc in save_datasets(self, datasets, filename, **kwargs)
176                     coords = [line_coord, pixel_coord]
177
--> 178                 domain = cf.Domain(dim=coords,
179                                    aux=aux,
180                                    ref=grid_mapping)

AttributeError: 'module' object has no attribute 'Domain'

# Fixed code
def adjust_scaling_factors(self, factors, file_units, output_units):
    if file_units == output_units:
        LOG.debug("File units and output units are the same (%s)", file_units)
        return factors
    if factors is None:
        factors = xr.DataArray([1, 0])
    factors = factors.where(factors != -999.0)

    if file_units == "W cm-2 sr-1" and output_units == "W m-2 sr-1":
        LOG.debug(
            "Adjusting scaling factors to convert '%s' to '%s'",
            file_units,
            output_units,
        )
        factors = factors * 10000.0
        return factors
    elif file_units == "1" and output_units == "%":
        LOG.debug(
            "Adjusting scaling factors to convert '%s' to '%s'",
            file_units,
            output_units,
        )
        factors = factors * 100.0
        return factors
    else:
        return factors