# Buggy code
def __call__(self, projectables, **info):
    vis = projectables[0]
    if vis.info.get("sunz_corrected"):
        LOG.debug("Sun zen correction already applied")
        return vis

    if hasattr(vis.info["area"], "name"):
        area_name = vis.info["area"].name
    else:
        area_name = "swath" + str(vis.shape)
    key = (vis.info["start_time"], area_name)
    tic = time.time()
    LOG.debug("Applying sun zen correction")
    if len(projectables) == 1:
        if key not in self.coszen:
            from pyorbital.astronomy import cos_zen

            LOG.debug("Computing sun zenith angles.")
            self.coszen[key] = np.ma.masked_outside(
                cos_zen(vis.info["start_time"], *vis.info["area"].get_lonlats()),
                # about 88 degrees.
                0.035,
                1,
                copy=False,
            )
        coszen = self.coszen[key]
    else:
        coszen = np.cos(np.deg2rad(projectables[1]))

    if vis.shape != coszen.shape:
        # assume we were given lower resolution szen data than band data
        LOG.debug("Interpolating coszen calculations for higher resolution band")
        factor = int(vis.shape[1] / coszen.shape[1])
        coszen = np.repeat(np.repeat(coszen, factor, axis=0), factor, axis=1)

    # sunz correction will be in place so we need a copy
    proj = vis.copy()
    proj = self._apply_correction(proj, coszen)
    vis.mask[coszen < 0] = True
    self.apply_modifier_info(vis, proj)
    LOG.debug(
        "Sun-zenith correction applied. Computation time: %5.1f (sec)",
        time.time() - tic,
    )
    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, projectables, **info):
    vis = projectables[0]
    if vis.attrs.get("sunz_corrected"):
        LOG.debug("Sun zen correction already applied")
        return vis

    if hasattr(vis.attrs["area"], "name"):
        area_name = vis.attrs["area"].name
    else:
        area_name = "swath" + str(vis.shape)
    key = (vis.attrs["start_time"], area_name)
    tic = time.time()
    LOG.debug("Applying sun zen correction")
    if len(projectables) == 1:
        coszen = self.coszen.get(key)
        if coszen is None:
            from pyorbital.astronomy import cos_zen

            LOG.debug("Computing sun zenith angles.")
            lons, lats = vis.attrs["area"].get_lonlats_dask(CHUNK_SIZE)

            coszen = xr.DataArray(
                cos_zen(vis.attrs["start_time"], lons, lats),
                dims=["y", "x"],
                coords=[vis["y"], vis["x"]],
            )
            coszen = coszen.where((coszen > 0.035) & (coszen < 1))
            self.coszen[key] = coszen
    else:
        coszen = np.cos(np.deg2rad(projectables[1]))
        self.coszen[key] = coszen

    if vis.shape != coszen.shape:
        # assume we were given lower resolution szen data than band data
        LOG.debug("Interpolating coszen calculations for higher resolution band")
        factor = int(vis.shape[1] / coszen.shape[1])
        coszen = np.repeat(np.repeat(coszen, factor, axis=0), factor, axis=1)

    proj = self._apply_correction(vis, coszen)
    proj.attrs = vis.attrs.copy()
    self.apply_modifier_info(vis, proj)
    LOG.debug(
        "Sun-zenith correction applied. Computation time: %5.1f (sec)",
        time.time() - tic,
    )
    return proj