gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _init_refl3x(self, projectables):
    """Initiate the 3.x reflectance derivations"""
    try:
        from pyspectral.near_infrared_reflectance import Calculator
    except ImportError:
        LOG.info("Couldn't load pyspectral")
        raise

    _nir, _tb11 = projectables
    self._refl3x = Calculator(
        _nir.info["platform_name"], _nir.info["sensor"], _nir.id.name
    )


# 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 _init_refl3x(self, projectables):
    """Initiate the 3.x reflectance derivations"""
    try:
        from pyspectral.near_infrared_reflectance import Calculator
    except ImportError:
        LOG.info("Couldn't load pyspectral")
        raise

    _nir, _tb11 = projectables
    self._refl3x = Calculator(
        _nir.attrs["platform_name"], _nir.attrs["sensor"], _nir.attrs["name"]
    )
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    """Get the emissive part an NIR channel after having derived the reflectance.
    Not supposed to be used for wavelength outside [3, 4] µm.
    """
    self._init_refl3x(projectables)
    # Derive the sun-zenith angles, and use the nir and thermal ir
    # brightness tempertures and derive the reflectance using
    # PySpectral. The reflectance is stored internally in PySpectral and
    # needs to be derived first in order to get the emissive part.
    _ = self._get_reflectance(projectables, optional_datasets)
    _nir, _ = projectables
    proj = Dataset(self._refl3x.emissive_part_3x(), **_nir.info)

    proj.info["units"] = "K"
    self.apply_modifier_info(_nir, proj)

    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, optional_datasets=None, **info):
    """Get the emissive part an NIR channel after having derived the reflectance.
    Not supposed to be used for wavelength outside [3, 4] µm.
    """
    self._init_refl3x(projectables)
    # Derive the sun-zenith angles, and use the nir and thermal ir
    # brightness tempertures and derive the reflectance using
    # PySpectral. The reflectance is stored internally in PySpectral and
    # needs to be derived first in order to get the emissive part.
    _ = self._get_reflectance(projectables, optional_datasets)
    _nir, _ = projectables
    proj = Dataset(self._refl3x.emissive_part_3x(), **_nir.attrs)

    proj.attrs["units"] = "K"
    self.apply_modifier_info(_nir, proj)

    return proj
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    """CO2 correction of the brightness temperature of the MSG 3.9um
    channel.

    .. math::

      T4_CO2corr = (BT(IR3.9)^4 + Rcorr)^0.25
      Rcorr = BT(IR10.8)^4 - (BT(IR10.8)-dt_CO2)^4
      dt_CO2 = (BT(IR10.8)-BT(IR13.4))/4.0
    """
    (ir_039, ir_108, ir_134) = projectables
    LOG.info("Applying CO2 correction")
    dt_co2 = (ir_108 - ir_134) / 4.0
    rcorr = ir_108**4 - (ir_108 - dt_co2) ** 4
    t4_co2corr = ir_039**4 + rcorr
    t4_co2corr = np.ma.where(t4_co2corr > 0.0, t4_co2corr, 0)
    t4_co2corr = t4_co2corr**0.25

    info = ir_039.info.copy()

    proj = Dataset(t4_co2corr, mask=t4_co2corr.mask, **info)

    self.apply_modifier_info(ir_039, proj)

    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, optional_datasets=None, **info):
    """CO2 correction of the brightness temperature of the MSG 3.9um
    channel.

    .. math::

      T4_CO2corr = (BT(IR3.9)^4 + Rcorr)^0.25
      Rcorr = BT(IR10.8)^4 - (BT(IR10.8)-dt_CO2)^4
      dt_CO2 = (BT(IR10.8)-BT(IR13.4))/4.0
    """
    (ir_039, ir_108, ir_134) = projectables
    LOG.info("Applying CO2 correction")
    dt_co2 = (ir_108 - ir_134) / 4.0
    rcorr = ir_108**4 - (ir_108 - dt_co2) ** 4
    t4_co2corr = ir_039**4 + rcorr
    t4_co2corr = np.ma.where(t4_co2corr > 0.0, t4_co2corr, 0)
    t4_co2corr = t4_co2corr**0.25

    info = ir_039.attrs.copy()

    proj = Dataset(t4_co2corr, mask=t4_co2corr.mask, **info)

    self.apply_modifier_info(ir_039, proj)

    return proj
# Buggy code
def __call__(self, projectables, nonprojectables=None, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))
    info = combine_info(*projectables)
    info["name"] = self.info["name"]

    return Dataset(projectables[0] - projectables[1], **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 __call__(self, projectables, nonprojectables=None, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))
    info = combine_metadata(*projectables)
    info["name"] = self.attrs["name"]

    return Dataset(projectables[0] - projectables[1], **info)
# Buggy code
def build_colormap(palette, dtype, info):
    """Create the colormap from the `raw_palette` and the valid_range."""

    from trollimage.colormap import Colormap

    if dtype == np.dtype("uint8"):
        tups = [(val, tuple(tup)) for (val, tup) in enumerate(palette[:-1])]
        colormap = Colormap(*tups)

    elif "valid_range" in info:
        tups = [(val, tuple(tup)) for (val, tup) in enumerate(palette[:-1])]
        colormap = Colormap(*tups)

        sf = info["scale_factor"]
        colormap.set_range(*info["valid_range"] * sf + info["add_offset"])

    return colormap


# 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 build_colormap(palette, dtype, info):
    """Create the colormap from the `raw_palette` and the valid_range."""

    from trollimage.colormap import Colormap

    palette = np.asanyarray(palette).squeeze()
    if dtype == np.dtype("uint8"):
        tups = [(val, tuple(tup)) for (val, tup) in enumerate(palette[:-1])]
        colormap = Colormap(*tups)

    elif "valid_range" in info:
        tups = [(val, tuple(tup)) for (val, tup) in enumerate(palette[:-1])]
        colormap = Colormap(*tups)

        sf = info["scale_factor"]
        colormap.set_range(*info["valid_range"] * sf + info["add_offset"])

    return colormap
# Buggy code
def __call__(self, projectables, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    # TODO: support datasets with palette to delegate this to the image
    # writer.

    data, palette = projectables
    colormap = self.build_colormap(palette / 255.0, data.dtype, data.info)

    r, g, b = colormap.colorize(data)
    r[data.mask] = palette[-1][0]
    g[data.mask] = palette[-1][1]
    b[data.mask] = palette[-1][2]
    r = Dataset(r, copy=False, mask=data.mask, **data.info)
    g = Dataset(g, copy=False, mask=data.mask, **data.info)
    b = Dataset(b, copy=False, mask=data.mask, **data.info)

    return super(ColorizeCompositor, self).__call__((r, g, b), **data.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 __call__(self, projectables, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    # TODO: support datasets with palette to delegate this to the image
    # writer.

    data, palette = projectables
    palette = np.asanyarray(palette).squeeze()
    colormap = self.build_colormap(palette / 255.0, data.dtype, data.attrs)

    r, g, b = colormap.colorize(np.asanyarray(data))
    r[data.mask] = palette[-1][0]
    g[data.mask] = palette[-1][1]
    b[data.mask] = palette[-1][2]
    r = Dataset(r, copy=False, mask=data.mask, **data.attrs)
    g = Dataset(g, copy=False, mask=data.mask, **data.attrs)
    b = Dataset(b, copy=False, mask=data.mask, **data.attrs)

    return super(ColorizeCompositor, self).__call__((r, g, b), **data.attrs)
# Buggy code
def __call__(self, projectables, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    # TODO: support datasets with palette to delegate this to the image
    # writer.

    data, palette = projectables
    palette = palette / 255.0
    colormap = self.build_colormap(palette, data.dtype, data.info)

    channels, colors = colormap.palettize(data)
    channels = palette[channels]

    r = Dataset(channels[:, :, 0], copy=False, mask=data.mask, **data.info)
    g = Dataset(channels[:, :, 1], copy=False, mask=data.mask, **data.info)
    b = Dataset(channels[:, :, 2], copy=False, mask=data.mask, **data.info)

    return super(PaletteCompositor, self).__call__((r, g, b), **data.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 __call__(self, projectables, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    # TODO: support datasets with palette to delegate this to the image
    # writer.

    data, palette = projectables
    palette = np.asanyarray(palette).squeeze() / 255.0
    colormap = self.build_colormap(palette, data.dtype, data.attrs)

    channels, colors = colormap.palettize(np.asanyarray(data.squeeze()))
    channels = palette[channels]

    r = xr.DataArray(
        channels[:, :, 0].reshape(data.shape), dims=data.dims, coords=data.coords
    )
    g = xr.DataArray(
        channels[:, :, 1].reshape(data.shape), dims=data.dims, coords=data.coords
    )
    b = xr.DataArray(
        channels[:, :, 2].reshape(data.shape), dims=data.dims, coords=data.coords
    )

    return super(PaletteCompositor, self).__call__((r, g, b), **data.attrs)
# Buggy code
def __call__(self, projectables, *args, **kwargs):
    try:
        vis06 = projectables[0]
        vis08 = projectables[1]
        hrv = projectables[2]

        ndvi = (vis08 - vis06) / (vis08 + vis06)
        ndvi = np.where(ndvi < 0, 0, ndvi)

        # info = combine_info(*projectables)
        # info['name'] = self.info['name']
        # info['standard_name'] = self.info['standard_name']

        ch1 = Dataset(ndvi * vis06 + (1 - ndvi) * vis08, copy=False, **vis06.info)
        ch2 = Dataset(ndvi * vis08 + (1 - ndvi) * vis06, copy=False, **vis08.info)
        ch3 = Dataset(3 * hrv - vis06 - vis08, copy=False, **hrv.info)

        res = RGBCompositor.__call__(self, (ch1, ch2, ch3), *args, **kwargs)
    except ValueError:
        raise IncompatibleAreas
    return res


# 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, *args, **kwargs):
    try:
        vis06 = projectables[0]
        vis08 = projectables[1]
        hrv = projectables[2]

        try:
            ch3 = 3 * hrv - vis06 - vis08
            ch3.attrs = hrv.attrs
        except ValueError as err:
            raise IncompatibleAreas

        ndvi = (vis08 - vis06) / (vis08 + vis06)
        ndvi = np.where(ndvi < 0, 0, ndvi)

        ch1 = ndvi * vis06 + (1 - ndvi) * vis08
        ch1.attrs = vis06.attrs
        ch2 = ndvi * vis08 + (1 - ndvi) * vis06
        ch2.attrs = vis08.attrs

        res = RGBCompositor.__call__(self, (ch1, ch2, ch3), *args, **kwargs)
    except ValueError:
        raise IncompatibleAreas
    return res
# Buggy code
def __call__(self, projectables, **info):
    c01, c02, c03 = projectables

    r = c02
    b = c01
    g = simulated_green(c01, c02, c03)

    return super(TrueColor2km, self).__call__((r, g, b), **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 __call__(self, projectables, **info):
    c01, c02, c03 = projectables

    # c02 = c02.sel(x=c01.coords['x'], y=c01.coords[
    #               'y'], method='nearest', tolerance=0.1)

    r = c02[::2, ::2]
    b = c01
    r.coords["x"] = b.coords["x"]
    r.coords["y"] = b.coords["y"]
    r.data = r.data.rechunk(b.chunks)
    g = simulated_green(c01, c02, c03)
    g.attrs = b.attrs
    g.coords["t"] = b.coords["t"]
    del g.attrs["wavelength"]

    return super(TrueColor2km, self).__call__((r, g, b), **info)
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    factor = self.info.get("factor", 2)

    (band,) = projectables

    LOG.info("Expanding datasize by a factor %d.", factor)

    proj = Dataset(
        np.repeat(np.repeat(band, factor, axis=0), factor, axis=1),
        copy=False,
        **band.info,
    )

    old_area = proj.info["area"]
    proj.info["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size * factor,
        old_area.y_size * factor,
        old_area.area_extent,
    )
    proj.info["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    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, optional_datasets=None, **info):
    factor = self.attrs.get("factor", 2)

    (band,) = projectables

    LOG.info("Expanding datasize by a factor %d.", factor)

    proj = Dataset(
        np.repeat(np.repeat(band, factor, axis=0), factor, axis=1),
        copy=False,
        **band.info,
    )

    old_area = proj.info["area"]
    proj.info["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size * factor,
        old_area.y_size * factor,
        old_area.area_extent,
    )
    proj.info["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    return proj
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    (band,) = projectables

    factor = 2

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = Dataset(band[::factor, ::factor], copy=False, **band.info)
    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.info["area"]
    proj.info["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.info["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    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, optional_datasets=None, **info):
    (band,) = projectables

    factor = 2

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = band[::factor, ::factor]
    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.attrs["area"]
    proj.attrs["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.attrs["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    return proj
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    (band,) = projectables

    factor = 4

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = Dataset(band[::factor, ::factor], copy=False, **band.info)
    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.info["area"]
    proj.info["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.info["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    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, optional_datasets=None, **info):
    (band,) = projectables

    factor = 4

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = band[::factor, ::factor]

    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.attrs["area"]
    proj.attrs["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.attrs["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    return proj
# Buggy code
def __call__(self, projectables, optional_datasets=None, **info):
    (band,) = projectables

    factor = 8

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = Dataset(band[::factor, ::factor], copy=False, **band.info)
    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.info["area"]
    proj.info["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.info["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    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, optional_datasets=None, **info):
    (band,) = projectables

    factor = 8

    LOG.info("Reducing datasize by a factor %d.", factor)

    proj = band[::factor, ::factor]

    # newshape = (band.shape[0] / factor, factor,
    #            band.shape[1] / factor, factor)
    # proj = Dataset(band.reshape(newshape).mean(axis=3).mean(axis=1),
    #               copy=False, **band.info)

    old_area = proj.attrs["area"]
    proj.attrs["area"] = AreaDefinition(
        old_area.area_id,
        old_area.name,
        old_area.proj_id,
        old_area.proj_dict,
        old_area.x_size / factor,
        old_area.y_size / factor,
        old_area.area_extent,
    )
    proj.attrs["resolution"] *= factor
    self.apply_modifier_info(band, proj)
    return proj
# Buggy code
def __call__(self, projectables, *args, **kwargs):
    """Create the SAR Ice composite."""
    (mhh, mhv) = projectables
    green = overlay(mhh, mhv)
    green.info = combine_info(mhh, mhv)

    return super(SARIce, self).__call__((mhv, green, mhh), *args, **kwargs)


# 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, *args, **kwargs):
    """Create the SAR Ice composite."""
    (mhh, mhv) = projectables
    green = overlay(mhh, mhv)
    green.info = combine_metadata(mhh, mhv)

    return super(SARIce, self).__call__((mhv, green, mhh), *args, **kwargs)
# Buggy code
def __call__(self, projectables, nonprojectables=None, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    p1, p2 = projectables
    fog = p1 - p2
    fog.info.update(self.info)
    fog.info["area"] = p1.info["area"]
    fog.info["start_time"] = p1.info["start_time"]
    fog.info["end_time"] = p1.info["end_time"]
    fog.info["name"] = self.info["name"]
    fog.info["wavelength"] = None
    fog.info.setdefault("mode", "L")
    return fog


# 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, nonprojectables=None, **info):
    if len(projectables) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

    p1, p2 = projectables
    fog = p1 - p2
    fog.info.update(self.attrs)
    fog.info["area"] = p1.info["area"]
    fog.info["start_time"] = p1.info["start_time"]
    fog.info["end_time"] = p1.info["end_time"]
    fog.info["name"] = self.attrs["name"]
    fog.info["wavelength"] = None
    fog.info.setdefault("mode", "L")
    return fog
# Buggy code
def __call__(self, projectables, nonprojectables=None, **info):
    if len(projectables) != 3:
        raise ValueError("Expected 3 datasets, got %d" % (len(projectables),))

    # Collect information that is the same between the projectables
    info = combine_info(*projectables)
    # Update that information with configured information (including name)
    info.update(self.info)
    # Force certain pieces of metadata that we *know* to be true
    info["wavelength"] = None
    info["mode"] = self.info.get("mode", "RGB")
    return Dataset(
        data=np.rollaxis(
            np.ma.dstack([projectable for projectable in projectables]), axis=2
        ),
        **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 __call__(self, projectables, nonprojectables=None, **info):
    if len(projectables) != 3:
        raise ValueError("Expected 3 datasets, got %d" % (len(projectables),))

    # Collect information that is the same between the projectables
    info = combine_metadata(*projectables)
    # Update that information with configured information (including name)
    info.update(self.attrs)
    # Force certain pieces of metadata that we *know* to be true
    info["wavelength"] = None
    info["mode"] = self.attrs.get("mode", "RGB")
    return Dataset(
        data=np.rollaxis(
            np.ma.dstack([projectable for projectable in projectables]), axis=2
        ),
        **info,
    )
# Buggy code
def name_match(a, b):
    """Return if two string names are equal

    Args:
        a (str): DatasetID.name or other string
        b (str): DatasetID.name or other string
    """
    return a == b


# 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 name_match(a, b):
    """Return if two string names are equal.

    Args:
        a (str): DatasetID.name or other string
        b (str): DatasetID.name or other string
    """
    return a == b
# Buggy code
def wavelength_match(a, b):
    """Return if two wavelengths are equal

    Args:
        a (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
        b (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
    """
    if (
        type(a) == type(b)
        or isinstance(a, numbers.Number)
        and isinstance(b, numbers.Number)
    ):
        return a == b
    elif a is None or b is None:
        return False
    elif isinstance(a, (list, tuple)) and len(a) == 3:
        return a[0] <= b <= a[2]
    elif isinstance(b, (list, tuple)) and len(b) == 3:
        return b[0] <= a <= b[2]
    else:
        raise ValueError("Can only compare wavelengths of length 1 or 3")


# 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 wavelength_match(a, b):
    """Return if two wavelengths are equal.

    Args:
        a (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
        b (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
    """
    if type(a) == (
        type(b) or isinstance(a, numbers.Number) and isinstance(b, numbers.Number)
    ):
        return a == b
    elif a is None or b is None:
        return False
    elif isinstance(a, (list, tuple)) and len(a) == 3:
        return a[0] <= b <= a[2]
    elif isinstance(b, (list, tuple)) and len(b) == 3:
        return b[0] <= a <= b[2]
    else:
        raise ValueError("Can only compare wavelengths of length 1 or 3")
# Buggy code
def __lt__(self, other):
    """Compare DatasetIDs with special handling of `None` values"""
    # modifiers should never be None when sorted, should be tuples
    if isinstance(other, DatasetID):
        other = other._comparable()
    return super(DatasetID, self._comparable()).__lt__(other)


# 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 __lt__(self, other):
    """Less than."""
    """Compare DatasetIDs with special handling of `None` values"""
    # modifiers should never be None when sorted, should be tuples
    if isinstance(other, DatasetID):
        other = other._comparable()
    return super(DatasetID, self._comparable()).__lt__(other)