# Buggy code
def calc_area_extent(self, key):
    """Calculate area extent for a dataset."""
    # Calculate the area extent of the swath based on start line and column
    # information, total number of segments and channel resolution
    xyres = {500: 22272, 1000: 11136, 2000: 5568}
    chkres = xyres[key.resolution]

    # Get metadata for given dataset
    measured = self.nc["/data/{}/measured".format(key.name)]
    variable = self.nc["/data/{}/measured/effective_radiance".format(key.name)]
    # Get start/end line and column of loaded swath.
    self.startline = int(measured.variables["start_position_row"][...])
    self.endline = int(measured.variables["end_position_row"][...])
    self.startcol = int(measured.variables["start_position_column"][...])
    self.endcol = int(measured.variables["end_position_column"][...])
    self.nlines, self.ncols = variable[:].shape

    logger.debug("Channel {} resolution: {}".format(key.name, chkres))
    logger.debug("Row/Cols: {} / {}".format(self.nlines, self.ncols))
    logger.debug("Start/End row: {} / {}".format(self.startline, self.endline))
    logger.debug("Start/End col: {} / {}".format(self.startcol, self.endcol))
    total_segments = 70

    # Calculate full globe line extent
    max_y = 5432229.9317116784
    min_y = -5429229.5285458621
    full_y = max_y + abs(min_y)
    # Single swath line extent
    res_y = full_y / chkres  # Extent per pixel resolution
    startl = min_y + res_y * self.startline - 0.5 * (res_y)
    endl = min_y + res_y * self.endline + 0.5 * (res_y)
    logger.debug("Start / end extent: {} / {}".format(startl, endl))

    chk_extent = (-5432229.9317116784, endl, 5429229.5285458621, startl)
    return chk_extent


# 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 calc_area_extent(self, key):
    """Calculate area extent for a dataset."""
    # Calculate the area extent of the swath based on start line and column
    # information, total number of segments and channel resolution
    xyres = {500: 22272, 1000: 11136, 2000: 5568}
    chkres = xyres[key.resolution]

    # Get metadata for given dataset
    measured = self.nc["/data/{}/measured".format(key.name)]
    variable = self.nc["/data/{}/measured/effective_radiance".format(key.name)]
    # Get start/end line and column of loaded swath.
    self.startline = int(measured["start_position_row"][...])
    self.endline = int(measured["end_position_row"][...])
    self.startcol = int(measured["start_position_column"][...])
    self.endcol = int(measured["end_position_column"][...])
    self.nlines, self.ncols = variable[:].shape

    logger.debug("Channel {} resolution: {}".format(key.name, chkres))
    logger.debug("Row/Cols: {} / {}".format(self.nlines, self.ncols))
    logger.debug("Start/End row: {} / {}".format(self.startline, self.endline))
    logger.debug("Start/End col: {} / {}".format(self.startcol, self.endcol))
    total_segments = 70

    # Calculate full globe line extent
    max_y = 5432229.9317116784
    min_y = -5429229.5285458621
    full_y = max_y + abs(min_y)
    # Single swath line extent
    res_y = full_y / chkres  # Extent per pixel resolution
    startl = min_y + res_y * self.startline - 0.5 * (res_y)
    endl = min_y + res_y * self.endline + 0.5 * (res_y)
    logger.debug("Start / end extent: {} / {}".format(startl, endl))

    chk_extent = (-5432229.9317116784, endl, 5429229.5285458621, startl)
    return chk_extent