# Buggy code
def resample(
    self, destination, datasets=None, compute=True, unload=True, **resample_kwargs
):
    """Resample the datasets and return a new scene."""
    new_scn = Scene()
    new_scn.info = self.info.copy()
    # new_scn.cpl = self.cpl
    new_scn.dep_tree = self.dep_tree.copy()
    for ds_id, projectable in self.datasets.items():
        LOG.debug("Resampling %s", ds_id)
        if datasets and ds_id not in datasets:
            continue
        new_scn[ds_id] = projectable.resample(destination, **resample_kwargs)
    # MUST set this after assigning the resampled datasets otherwise
    # composite prereqs that were resampled will be considered "wishlisted"
    if datasets is None:
        new_scn.wishlist = self.wishlist
    else:
        new_scn.wishlist = set([ds.id for ds in new_scn])

    # recompute anything from the wishlist that needs it (combining multiple
    # resolutions, etc.)
    keepables = None
    if compute:
        nodes = [
            self.dep_tree[i] for i in new_scn.wishlist if not self.dep_tree[i].is_leaf
        ]
        keepables = new_scn.compute(nodes=nodes)
    if new_scn.missing_datasets:
        # copy the set of missing datasets because they won't be valid
        # after they are removed in the next line
        missing = new_scn.missing_datasets.copy()
        new_scn._remove_failed_datasets(keepables)
        missing_str = ", ".join(str(x) for x in missing)
        LOG.warning("The following datasets were not created: {}".format(missing_str))
    if unload:
        new_scn.unload(keepables)

    return new_scn


# 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 resample(
    self, destination, datasets=None, compute=True, unload=True, **resample_kwargs
):
    """Resample the datasets and return a new scene."""
    to_resample = [
        dataset
        for (dsid, dataset) in self.datasets.items()
        if (not datasets) or dsid in datasets
    ]

    new_scn = self._resampled_scene(to_resample, destination, **resample_kwargs)

    new_scn.attrs = self.attrs.copy()
    new_scn.dep_tree = self.dep_tree.copy()

    # MUST set this after assigning the resampled datasets otherwise
    # composite prereqs that were resampled will be considered "wishlisted"
    if datasets is None:
        new_scn.wishlist = self.wishlist
    else:
        new_scn.wishlist = set([DatasetID.from_dict(ds.attrs) for ds in new_scn])

    # recompute anything from the wishlist that needs it (combining
    # multiple resolutions, etc.)
    keepables = None
    if compute:
        nodes = [
            self.dep_tree[i]
            for i in new_scn.wishlist
            if i in self.dep_tree and not self.dep_tree[i].is_leaf
        ]
        keepables = new_scn.compute(nodes=nodes)
    if new_scn.missing_datasets:
        # copy the set of missing datasets because they won't be valid
        # after they are removed in the next line
        missing = new_scn.missing_datasets.copy()
        new_scn._remove_failed_datasets(keepables)
        missing_str = ", ".join(str(x) for x in missing)
        LOG.warning("The following datasets were not created: {}".format(missing_str))
    if unload:
        new_scn.unload(keepables)

    return new_scn