# Buggy code
def _get_reflectance(self, projectables, optional_datasets):
    """Calculate 3.x reflectance with pyspectral"""
    _nir, _tb11 = projectables
    LOG.info("Getting reflective part of %s", _nir.info["name"])

    sun_zenith = None
    tb13_4 = None
    for dataset in optional_datasets:
        if (
            dataset.info["units"] == "K"
            and "wavelengh" in dataset.info
            and dataset.info["wavelength"][0] <= 13.4 <= dataset.info["wavelength"][2]
        ):
            tb13_4 = dataset
        elif dataset.info["standard_name"] == "solar_zenith_angle":
            sun_zenith = dataset

    # Check if the sun-zenith angle was provided:
    if sun_zenith is None:
        from pyorbital.astronomy import sun_zenith_angle as sza

        lons, lats = _nir.info["area"].get_lonlats()
        sun_zenith = sza(_nir.info["start_time"], lons, lats)

    return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4)


# 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 _get_reflectance(self, projectables, optional_datasets):
    """Calculate 3.x reflectance with pyspectral"""
    _nir, _tb11 = projectables
    LOG.info("Getting reflective part of %s", _nir.attrs["name"])

    sun_zenith = None
    tb13_4 = None

    for dataset in optional_datasets:
        if (
            dataset.attrs["units"] == "K"
            and "wavelengh" in dataset.attrs
            and dataset.attrs["wavelength"][0] <= 13.4 <= dataset.attrs["wavelength"][2]
        ):
            tb13_4 = dataset
        elif dataset.attrs["standard_name"] == "solar_zenith_angle":
            sun_zenith = dataset

    # Check if the sun-zenith angle was provided:
    if sun_zenith is None:
        from pyorbital.astronomy import sun_zenith_angle as sza

        lons, lats = _nir.attrs["area"].get_lonlats_dask(CHUNK_SIZE)
        sun_zenith = sza(_nir.attrs["start_time"], lons, lats)

    return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4)