# Buggy code
def __call__(self, datasets, **info):
    refl_data, sensor_aa, sensor_za, solar_aa, solar_za = datasets
    if refl_data.info.get("rayleigh_corrected"):
        return refl_data

    if os.path.isfile(self.dem_file):
        LOG.debug(
            "Loading CREFL averaged elevation information from: %s", self.dem_file
        )
        from netCDF4 import Dataset as NCDataset

        # HDF4 file, NetCDF library needs to be compiled with HDF4 support
        nc = NCDataset(self.dem_file, "r")
        avg_elevation = nc.variables[self.dem_sds][:]
    else:
        avg_elevation = None

    from satpy.composites.crefl_utils import run_crefl, get_coefficients

    percent = refl_data.info["units"] == "%"

    coefficients = get_coefficients(
        refl_data.info["sensor"],
        refl_data.info["wavelength"],
        refl_data.info["resolution"],
    )

    results = run_crefl(
        refl_data,
        coefficients,
        sensor_aa.info["area"].lons,
        sensor_aa.info["area"].lats,
        sensor_aa,
        sensor_za,
        solar_aa,
        solar_za,
        avg_elevation=avg_elevation,
        percent=percent,
    )

    info.update(refl_data.info)
    info["rayleigh_corrected"] = True
    factor = 100.0 if percent else 1.0
    proj = Dataset(
        data=results.data * factor, mask=results.mask, dtype=results.dtype, **info
    )

    self.apply_modifier_info(refl_data, proj)

    return proj


# 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 __call__(self, datasets, **info):
    refl_data, sensor_aa, sensor_za, solar_aa, solar_za = datasets
    if refl_data.attrs.get("rayleigh_corrected"):
        return refl_data

    if os.path.isfile(self.dem_file):
        LOG.debug(
            "Loading CREFL averaged elevation information from: %s", self.dem_file
        )
        from netCDF4 import Dataset as NCDataset

        # HDF4 file, NetCDF library needs to be compiled with HDF4 support
        nc = NCDataset(self.dem_file, "r")
        avg_elevation = nc.variables[self.dem_sds][:]
    else:
        avg_elevation = None

    from satpy.composites.crefl_utils import run_crefl, get_coefficients

    percent = refl_data.attrs["units"] == "%"

    coefficients = get_coefficients(
        refl_data.attrs["sensor"],
        refl_data.attrs["wavelength"],
        refl_data.attrs["resolution"],
    )

    results = run_crefl(
        refl_data,
        coefficients,
        sensor_aa.attrs["area"].lons,
        sensor_aa.attrs["area"].lats,
        sensor_aa,
        sensor_za,
        solar_aa,
        solar_za,
        avg_elevation=avg_elevation,
        percent=percent,
    )

    info.update(refl_data.attrs)
    info["rayleigh_corrected"] = True
    factor = 100.0 if percent else 1.0
    proj = Dataset(
        data=results.data * factor, mask=results.mask, dtype=results.dtype, **info
    )

    self.apply_modifier_info(refl_data, proj)

    return proj