# Buggy code
def __call__(self, datasets, **info):
    """Create the composite by scaling the DNB data using a histogram equalization method.

    :param datasets: 2-element tuple (Day/Night Band data, Solar Zenith Angle data)
    :param **info: Miscellaneous metadata for the newly produced composite
    """
    if len(datasets) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(datasets),))

    dnb_data = datasets[0]
    sza_data = datasets[1]
    good_mask = ~(dnb_data.mask | sza_data.mask)
    output_dataset = dnb_data.copy()
    output_dataset.mask = ~good_mask
    day_mask, mixed_mask, night_mask = make_day_night_masks(
        sza_data,
        good_mask,
        self.high_angle_cutoff,
        self.low_angle_cutoff,
        stepsDegrees=self.mixed_degree_step,
    )

    did_equalize = False
    if day_mask.any():
        LOG.debug("Histogram equalizing DNB day data...")
        histogram_equalization(dnb_data.data, day_mask, out=output_dataset)
        did_equalize = True
    if mixed_mask:
        for mask in mixed_mask:
            if mask.any():
                LOG.debug("Histogram equalizing DNB mixed data...")
                histogram_equalization(dnb_data.data, mask, out=output_dataset)
                did_equalize = True
    if night_mask.any():
        LOG.debug("Histogram equalizing DNB night data...")
        histogram_equalization(dnb_data.data, night_mask, out=output_dataset)
        did_equalize = True

    if not did_equalize:
        raise RuntimeError("No valid data found to histogram equalize")

    info = dnb_data.info.copy()
    info.update(self.info)
    info["standard_name"] = "equalized_radiance"
    info["mode"] = "L"
    output_dataset.info = info
    return output_dataset


# 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, datasets, **info):
    """Create the composite by scaling the DNB data using a histogram equalization method.

    :param datasets: 2-element tuple (Day/Night Band data, Solar Zenith Angle data)
    :param **info: Miscellaneous metadata for the newly produced composite
    """
    if len(datasets) != 2:
        raise ValueError("Expected 2 datasets, got %d" % (len(datasets),))

    dnb_data = datasets[0]
    sza_data = datasets[1]
    good_mask = ~(dnb_data.mask | sza_data.mask)
    output_dataset = dnb_data.copy()
    output_dataset.mask = ~good_mask
    day_mask, mixed_mask, night_mask = make_day_night_masks(
        sza_data,
        good_mask,
        self.high_angle_cutoff,
        self.low_angle_cutoff,
        stepsDegrees=self.mixed_degree_step,
    )

    did_equalize = False
    if day_mask.any():
        LOG.debug("Histogram equalizing DNB day data...")
        histogram_equalization(dnb_data.data, day_mask, out=output_dataset)
        did_equalize = True
    if mixed_mask:
        for mask in mixed_mask:
            if mask.any():
                LOG.debug("Histogram equalizing DNB mixed data...")
                histogram_equalization(dnb_data.data, mask, out=output_dataset)
                did_equalize = True
    if night_mask.any():
        LOG.debug("Histogram equalizing DNB night data...")
        histogram_equalization(dnb_data.data, night_mask, out=output_dataset)
        did_equalize = True

    if not did_equalize:
        raise RuntimeError("No valid data found to histogram equalize")

    info = dnb_data.info.copy()
    info.update(self.attrs)
    info["standard_name"] = "equalized_radiance"
    info["mode"] = "L"
    output_dataset.info = info
    return output_dataset