# Buggy code
def read_band(self, key, info, out=None, xslice=slice(None), yslice=slice(None)):
    """Read the data"""
    # TODO slicing !
    tic = datetime.now()

    with open(self.filename, "rb") as fp_:
        fp_.seek(self.mda["total_header_length"])
        if self.mda["number_of_bits_per_pixel"] == 10:
            data = np.fromfile(
                fp_,
                dtype=np.uint8,
                count=int(np.ceil(self.mda["data_field_length"] / 8.0)),
            )
            out.data[:] = (
                dec10216(data).reshape(
                    (self.mda["number_of_lines"], self.mda["number_of_columns"])
                )[yslice, xslice]
                * 1.0
            )
        elif self.mda["number_of_bits_per_pixel"] == 16:
            data = np.fromfile(
                fp_,
                dtype=">u2",
                count=int(np.ceil(self.mda["data_field_length"] / 8.0)),
            )
            out.data[:] = (
                data.reshape(
                    (self.mda["number_of_lines"], self.mda["number_of_columns"])
                )[yslice, xslice]
                * 1.0
            )
        elif self.mda["number_of_bits_per_pixel"] == 8:
            data = np.fromfile(
                fp_,
                dtype=">u1",
                count=int(np.ceil(self.mda["data_field_length"] / 8.0)),
            )
            out.data[:] = (
                data.reshape(
                    (self.mda["number_of_lines"], self.mda["number_of_columns"])
                )[yslice, xslice]
                * 1.0
            )
        out.mask[:] = out.data == 0
    logger.debug("Reading time " + str(datetime.now() - tic))


# 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 read_band(self, key, info):
    """Read the data"""
    # TODO slicing !
    tic = datetime.now()

    if self.mda["number_of_bits_per_pixel"] == 16:
        dtype = ">u2"
    elif self.mda["number_of_bits_per_pixel"] in [8, 10]:
        dtype = np.uint8
    shape = (int(np.ceil(self.mda["data_field_length"] / 8.0)),)

    data = np.memmap(
        self.filename,
        mode="r",
        offset=self.mda["total_header_length"],
        dtype=dtype,
        shape=shape,
    )
    data = da.from_array(data, chunks=shape[0])
    if self.mda["number_of_bits_per_pixel"] == 10:
        data = dec10216(data)
    data = data.reshape(
        (self.mda["number_of_lines"], self.mda["number_of_columns"])
    ).astype(np.float32)
    logger.debug("Reading time " + str(datetime.now() - tic))
    return data