# Buggy code
def get_dataset(self, key, info):
    if self.reader is None:
        with open(self.filename) as fdes:
            data = fdes.read(3)
        if data in ["CMS", "NSS", "UKM", "DSS"]:
            reader = GACKLMReader
            self.chn_dict = AVHRR3_CHANNEL_NAMES
        else:
            reader = GACPODReader
            self.chn_dict = AVHRR_CHANNEL_NAMES

        self.reader = reader()
        self.reader.read(self.filename)

    if key.name in ["latitude", "longitude"]:
        if self.reader.lons is None or self.reader.lats is None:
            self.reader.get_lonlat(clock_drift_adjust=False)
        if key.name == "latitude":
            return Dataset(self.reader.lats, id=key, **info)
        else:
            return Dataset(self.reader.lons, id=key, **info)

    if self.channels is None:
        self.channels = self.reader.get_calibrated_channels()

    data = self.channels[:, :, self.chn_dict[key.name]]
    return Dataset(data, id=key, **info)


# 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_dataset(self, key, info):
    if self.reader is None:
        with open(self.filename) as fdes:
            data = fdes.read(3)
        if data in ["CMS", "NSS", "UKM", "DSS"]:
            reader = GACKLMReader
            self.chn_dict = AVHRR3_CHANNEL_NAMES
        else:
            reader = GACPODReader
            self.chn_dict = AVHRR_CHANNEL_NAMES

        self.reader = reader()
        self.reader.read(self.filename)

    if key.name in ["latitude", "longitude"]:
        if self.reader.lons is None or self.reader.lats is None:
            # self.reader.get_lonlat(clock_drift_adjust=False)
            self.reader.get_lonlat()
        if key.name == "latitude":
            return xr.DataArray(
                da.from_array(self.reader.lats, chunks=1000),
                dims=["y", "x"],
                attrs=info,
            )
        else:
            return xr.DataArray(
                da.from_array(self.reader.lons, chunks=1000),
                dims=["y", "x"],
                attrs=info,
            )

    if self.channels is None:
        self.channels = self.reader.get_calibrated_channels()

    data = self.channels[:, :, self.chn_dict[key.name]]
    return xr.DataArray(da.from_array(data, chunks=1000), dims=["y", "x"], attrs=info)