gurudesh/pytracebugs huggingface dataset:
# Buggy code
def __eq__(self, other):
    if isinstance(other, str):
        return self.name_match(self.name, other)
    elif (
        isinstance(other, numbers.Number)
        or isinstance(other, (tuple, list))
        and len(other) == 3
    ):
        return self.wavelength_match(self.wavelength, other)
    else:
        return super(DatasetID, self).__eq__(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 __eq__(self, other):
    """Check for equality."""
    if isinstance(other, str):
        return self.name_match(self.name, other)
    elif (
        isinstance(other, numbers.Number)
        or isinstance(other, (tuple, list))
        and len(other) == 3
    ):
        return self.wavelength_match(self.wavelength, other)
    else:
        return super(DatasetID, self).__eq__(other)
# Buggy code
def __hash__(self):
    return tuple.__hash__(self)


# 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 __hash__(self):
    """Generate the hash of the ID."""
    return tuple.__hash__(self)
# Buggy code
def from_dict(cls, d, **kwargs):
    args = []
    for k in DATASET_KEYS:
        val = kwargs.get(k, d.get(k))
        # force modifiers to tuple
        if k == "modifiers" and val is not None:
            val = tuple(val)
        args.append(val)

    return cls(*args)


# 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 from_dict(cls, d, **kwargs):
    """Convert a dict to an ID."""
    args = []
    for k in DATASET_KEYS:
        val = kwargs.get(k, d.get(k))
        # force modifiers to tuple
        if k == "modifiers" and val is not None:
            val = tuple(val)
        args.append(val)

    return cls(*args)
# Buggy code
def to_dict(self, trim=True):
    if trim:
        return self._to_trimmed_dict()
    else:
        return dict(zip(DATASET_KEYS, self))


# 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 to_dict(self, trim=True):
    """Convert the ID to a dict."""
    if trim:
        return self._to_trimmed_dict()
    else:
        return dict(zip(DATASET_KEYS, self))
# Buggy code
def __init__(self, **attributes):
    self.info = attributes


# 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__(self, **attributes):
    """Initialize the class with *attributes*."""
    self.attrs = attributes
# Buggy code
def id(self):
    return DatasetID.from_dict(self.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 id(self):
    """Return the DatasetID of the object."""
    return DatasetID.from_dict(self.attrs)
# Buggy code
def __init__(self, filename, filename_info, filetype_info):
    super(NC_ABI_L1B, self).__init__(filename, filename_info, filetype_info)
    self.nc = h5netcdf.File(filename, "r")

    platform_shortname = filename_info["platform_shortname"]
    self.platform_name = PLATFORM_NAMES.get(platform_shortname)
    self.sensor = "abi"
    self.nlines, self.ncols = self.nc["Rad"].shape


# 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__(self, filename, filename_info, filetype_info):
    super(NC_ABI_L1B, self).__init__(filename, filename_info, filetype_info)
    self.nc = xr.open_dataset(
        filename,
        decode_cf=True,
        mask_and_scale=True,
        engine="h5netcdf",
        chunks={"x": 1000, "y": 1000},
    )
    self.nc = self.nc.rename({"t": "time"})
    platform_shortname = filename_info["platform_shortname"]
    self.platform_name = PLATFORM_NAMES.get(platform_shortname)
    self.sensor = "abi"
    self.nlines, self.ncols = self.nc["Rad"].shape
# Buggy code
def _vis_calibrate(self, data):
    """Calibrate visible channels to reflectance."""
    solar_irradiance = self.nc["esun"][()]
    esd = self.nc["earth_sun_distance_anomaly_in_AU"][()]

    factor = np.pi * esd * esd / solar_irradiance
    data.data[:] *= factor

    return "1"


# 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 _vis_calibrate(self, data):
    """Calibrate visible channels to reflectance."""
    solar_irradiance = self.nc["esun"]
    esd = self.nc["earth_sun_distance_anomaly_in_AU"].astype(float)

    factor = np.pi * esd * esd / solar_irradiance

    res = data * factor
    res.attrs = data.attrs
    res.attrs["units"] = "1"

    return res
# Buggy code
def _ir_calibrate(self, data):
    """Calibrate IR channels to BT."""
    fk1 = self.nc["planck_fk1"][()]
    fk2 = self.nc["planck_fk2"][()]
    bc1 = self.nc["planck_bc1"][()]
    bc2 = self.nc["planck_bc2"][()]

    np.divide(fk1, data, out=data.data)
    data.data[:] += 1
    np.log(data, out=data.data)
    np.divide(fk2, data, out=data.data)
    data.data[:] -= bc1
    data.data[:] /= bc2

    return "K"


# 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 _ir_calibrate(self, data):
    """Calibrate IR channels to BT."""
    fk1 = float(self.nc["planck_fk1"])
    fk2 = float(self.nc["planck_fk2"])
    bc1 = float(self.nc["planck_bc1"])
    bc2 = float(self.nc["planck_bc2"])

    res = (fk2 / xu.log(fk1 / data + 1) - bc1) / bc2
    res.attrs = data.attrs
    res.attrs["units"] = "K"

    return res
# Buggy code
def calibrate(self, data):
    """Calibrate the data."""
    logger.debug("Calibrate")

    ch = self.nc["band_id"][()]
    if ch < 7:
        return self._vis_calibrate(data)
    else:
        return self._ir_calibrate(data)


# 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 calibrate(self, data):
    """Calibrate the data."""
    logger.debug("Calibrate")

    ch = int(self.nc["band_id"])

    if ch < 7:
        return self._vis_calibrate(data)
    else:
        return self._ir_calibrate(data)
# Buggy code
def start_time(self):
    return datetime.strptime(
        self.nc.attrs["time_coverage_start"].decode(), "%Y-%m-%dT%H:%M:%S.%fZ"
    )


# 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 start_time(self):
    return datetime.strptime(
        self.nc.attrs["time_coverage_start"], "%Y-%m-%dT%H:%M:%S.%fZ"
    )
# Buggy code
def end_time(self):
    return datetime.strptime(
        self.nc.attrs["time_coverage_end"].decode(), "%Y-%m-%dT%H:%M:%S.%fZ"
    )


# 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 end_time(self):
    return datetime.strptime(
        self.nc.attrs["time_coverage_end"], "%Y-%m-%dT%H:%M:%S.%fZ"
    )
# Buggy code
def get_shape(self, ds_id, ds_info):
    """Get numpy array shape for the specified dataset.

    Args:
        ds_id (DatasetID): ID of dataset that will be loaded
        ds_info (dict): Dictionary of dataset information from config file

    Returns:
        tuple: (rows, cols)

    """
    var_path = ds_info.get("file_key", "{}".format(ds_id.name))
    s = self[var_path + "/shape"]
    if len(s) == 3:
        # time is first dimension of 1
        s = s[1:]
    return s


# 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_shape(self, ds_id, ds_info):
    """Get numpy array shape for the specified dataset.

    Args:
        ds_id (DatasetID): ID of dataset that will be loaded
        ds_info (dict): Dictionary of dataset information from config file

    Returns:
        tuple: (rows, cols)

    """
    var_path = ds_info.get("file_key", "{}".format(ds_id.name))
    if var_path + "/shape" not in self:
        # loading a scalar value
        shape = 1
    else:
        shape = self[var_path + "/shape"]
        if len(shape) == 3:
            if shape[0] != 1:
                raise ValueError(
                    "Not sure how to load 3D Dataset with more than 1 time"
                )
            else:
                shape = shape[1:]
    return shape
# Buggy code
def get_metadata(self, m_key):
    raise NotImplementedError()


# 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_metadata(self, ds_id, ds_info):
    var_path = ds_info["file_key"]
    info = getattr(self[var_path], "attrs", {})
    info.update(ds_info)
    info.update(
        {
            "shape": self.get_shape(ds_id, ds_info),
            "units": self[var_path + "/attr/UNIT"],
            "platform": self["/attr/PlatformShortName"].item(),
            "sensor": self["/attr/SensorShortName"].item(),
            "start_orbit": int(self["/attr/StartOrbitNumber"].item()),
            "end_orbit": int(self["/attr/StopOrbitNumber"].item()),
        }
    )
    info.update(ds_id.to_dict())
    return info
# Buggy code
def __init__(self, filename, filename_info, filetype_info):
    super(FCIFDHSIFileHandler, self).__init__(filename, filename_info, filetype_info)
    logger.debug("Reading: {}".format(filename))
    logger.debug("Start: {}".format(self.start_time))
    logger.debug("End: {}".format(self.end_time))

    self.nc = h5netcdf.File(filename, "r")
    self.filename = filename
    self.cache = {}


# 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__(self, filename, filename_info, filetype_info):
    super(FCIFDHSIFileHandler, self).__init__(filename, filename_info, filetype_info)
    logger.debug("Reading: {}".format(filename))
    logger.debug("Start: {}".format(self.start_time))
    logger.debug("End: {}".format(self.end_time))

    self.nc = h5py.File(filename, "r")
    self.filename = filename
    self.cache = {}
# Buggy code
def get_dataset(self, key, info=None):
    """Load a dataset"""
    if key in self.cache:
        return self.cache[key]

    logger.debug("Reading {}".format(key.name))
    # Get the dataset
    # Get metadata for given dataset
    variable = self.nc["/data/{}/measured/effective_radiance".format(key.name)]
    ds = np.ma.masked_equal(variable[:], variable.attrs["_FillValue"]) * (
        variable.attrs["scale_factor"] * 1.0
    ) + variable.attrs.get("add_offset", 0)

    self.calibrate(ds, key)

    out = Dataset(ds, dtype=np.float32)

    self.cache[key] = out
    self.nlines, self.ncols = ds.shape

    return out


# 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=None):
    """Load a dataset"""
    if key in self.cache:
        return self.cache[key]

    logger.debug("Reading {}".format(key.name))
    # Get the dataset
    # Get metadata for given dataset
    variable = self.nc["/data/{}/measured/effective_radiance".format(key.name)]
    # Convert to xarray
    radiances = xr.DataArray(np.asarray(variable, np.float32), dims=["y", "x"])
    radiances.attrs["scale_factor"] = variable.attrs["scale_factor"]
    radiances.attrs["offset"] = variable.attrs.get("add_offset", 0)
    radiances.attrs["FillValue"] = variable.attrs["_FillValue"]
    # Set invalid values to NaN
    radiances.values[radiances == radiances.attrs["FillValue"]] = np.nan
    # Apply scale factor and offset
    radiances = (
        radiances * (radiances.attrs["scale_factor"] * 1.0) + radiances.attrs["offset"]
    )

    # TODO Calibration is disabled, waiting for calibration parameters from EUMETSAT
    res = self.calibrate(radiances, key)

    self.cache[key] = res
    self.nlines, self.ncols = res.shape

    return res
# Buggy code
def calibrate(self, data, key):
    """Data calibration."""

    #        logger.debug('Calibration: %s' % key.calibration)
    logger.warning("Calibration disabled!")
    if key.calibration == "brightness_temperature":
        pass
    #            self._ir_calibrate(data, key)
    elif key.calibration == "reflectance":
        pass
    #            self._vis_calibrate(data, key)
    else:
        pass


# 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 calibrate(self, data, key):
    """Data calibration."""

    #        logger.debug('Calibration: %s' % key.calibration)
    logger.warning("Calibration disabled!")
    if key.calibration == "brightness_temperature":
        pass
    #            self._ir_calibrate(data, key)
    elif key.calibration == "reflectance":
        pass
    #            self._vis_calibrate(data, key)
    else:
        pass

    return data
# Buggy code
def get_metadata(self, dataset_id, ds_info):
    var_name = ds_info.get("file_key", dataset_id.name)
    i = {}
    i.update(ds_info)
    for a in [
        "standard_name",
        "units",
        "long_name",
        "flag_meanings",
        "flag_values",
        "flag_masks",
    ]:
        attr_path = var_name + "/attr/" + a
        if attr_path in self:
            i[a] = self[attr_path]

    u = i.get("units")
    if u in CF_UNITS:
        # CF compliance
        i["units"] = CF_UNITS[u]

    i["sensor"] = self.get_sensor(self["/attr/Sensor_Name"])
    i["platform"] = self.get_platform(self["/attr/Platform_Name"])
    i["resolution"] = dataset_id.resolution
    if var_name == "pixel_longitude":
        i["standard_name"] = "longitude"
    elif var_name == "pixel_latitude":
        i["standard_name"] = "latitude"

    return i


# 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_metadata(self, dataset_id, ds_info):
    var_name = ds_info.get("file_key", dataset_id.name)
    shape = self.get_shape(dataset_id, ds_info)
    info = getattr(self[var_name], "attrs", {})
    info["shape"] = shape
    info.update(ds_info)
    u = info.get("units")
    if u in CF_UNITS:
        # CF compliance
        info["units"] = CF_UNITS[u]

    info["sensor"] = self.get_sensor(self["/attr/Sensor_Name"])
    info["platform"] = self.get_platform(self["/attr/Platform_Name"])
    info["resolution"] = dataset_id.resolution
    if var_name == "pixel_longitude":
        info["standard_name"] = "longitude"
    elif var_name == "pixel_latitude":
        info["standard_name"] = "latitude"

    return info
# Buggy code
def get_dataset(
    self, dataset_id, ds_info, out=None, xslice=slice(None), yslice=slice(None)
):
    var_name = ds_info.get("file_key", dataset_id.name)
    # FUTURE: Metadata retrieval may be separate
    i = self.get_metadata(dataset_id, ds_info)
    data = self[var_name][yslice, xslice]
    fill = self[var_name + "/attr/_FillValue"]
    factor = self.get(var_name + "/attr/scale_factor")
    offset = self.get(var_name + "/attr/add_offset")
    valid_range = self.get(var_name + "/attr/valid_range")

    mask = data == fill
    if valid_range is not None:
        mask |= (data < valid_range[0]) | (data > valid_range[1])
    data = data.astype(out.data.dtype)
    if factor is not None and offset is not None:
        data *= factor
        data += offset

    out.data[:] = data
    out.mask[:] |= mask
    out.info.update(i)
    return out


# 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, dataset_id, ds_info, xslice=slice(None), yslice=slice(None)):
    var_name = ds_info.get("file_key", dataset_id.name)
    # FUTURE: Metadata retrieval may be separate
    info = self.get_metadata(dataset_id, ds_info)
    data = self[var_name][yslice, xslice]
    fill = self[var_name + "/attr/_FillValue"]
    factor = self.get(var_name + "/attr/scale_factor")
    offset = self.get(var_name + "/attr/add_offset")
    valid_range = self.get(var_name + "/attr/valid_range")

    data = data.where(data != fill)
    if valid_range is not None:
        data = data.where((data >= valid_range[0]) & (data <= valid_range[1]))
    if factor is not None and offset is not None:
        data = data * factor + offset

    data.attrs.update(info)
    return data
# Buggy code
def _collect_attrs(self, name, attrs):
    for key, value in six.iteritems(attrs):
        value = np.squeeze(value)
        self.file_content["{}/attr/{}".format(name, key)] = np2str(value)


# 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 _collect_attrs(self, name, attrs):
    for key, value in six.iteritems(attrs):
        value = np.squeeze(value)
        fc_key = "{}/attr/{}".format(name, key)
        try:
            self.file_content[fc_key] = np2str(value)
        except ValueError:
            self.file_content[fc_key] = value
# Buggy code
def __getitem__(self, key):
    val = self.file_content[key]
    if isinstance(val, h5py.Dataset):
        # these datasets are closed and inaccessible when the file is
        # closed, need to reopen
        return h5py.File(self.filename, "r")[key].value
    return val


# 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 __getitem__(self, key):
    val = self.file_content[key]
    if isinstance(val, h5py.Dataset):
        # these datasets are closed and inaccessible when the file is closed, need to reopen
        dset = h5py.File(self.filename, "r")[key]
        dset = da.from_array(dset, chunks=CHUNK_SIZE)
        if dset.ndim > 1:
            return xr.DataArray(dset, dims=["y", "x"])
        else:
            return xr.DataArray(dset)

    return val
# Buggy code
def load(self, keys, interpolate=True, raw=False):
    """Load the data."""
    projectables = []
    for key in keys:
        dataset = self.sd.select(key.name.capitalize())
        fill_value = dataset.attributes()["_FillValue"]
        try:
            scale_factor = dataset.attributes()["scale_factor"]
        except KeyError:
            scale_factor = 1
        data = np.ma.masked_equal(dataset.get(), fill_value) * scale_factor

        # TODO: interpolate if needed
        if (
            key.resolution is not None
            and key.resolution < self.resolution
            and interpolate
        ):
            data = self._interpolate(data, self.resolution, key.resolution)
        if raw:
            projectables.append(data)
        else:
            projectables.append(Dataset(data, id=key))

    return projectables


# 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 load(self, keys, interpolate=True, raw=False):
    """Load the data."""
    projectables = []
    for key in keys:
        dataset = self.sd.select(key.name.capitalize())
        fill_value = dataset.attributes()["_FillValue"]
        try:
            scale_factor = dataset.attributes()["scale_factor"]
        except KeyError:
            scale_factor = 1
        data = np.ma.masked_equal(dataset.get(), fill_value) * scale_factor

        # TODO: interpolate if needed
        if (
            key.resolution is not None
            and key.resolution < self.resolution
            and interpolate
        ):
            data = self._interpolate(data, self.resolution, key.resolution)
        if not raw:
            data = data.filled(np.nan)
            data = xr.DataArray(
                da.from_array(data, chunks=(CHUNK_SIZE, CHUNK_SIZE)), dims=["y", "x"]
            )
        projectables.append(data)

    return projectables
# Buggy code
def get_dataset(self, key, info, out=None, xslice=slice(None), yslice=slice(None)):
    to_return = out is None
    if out is None:
        nlines = int(self.mda["number_of_lines"])
        ncols = int(self.mda["number_of_columns"])
        out = Dataset(np.ma.empty((nlines, ncols), dtype=np.float32))

    self.read_band(key, info, out, xslice, yslice)

    if to_return:
        from satpy.yaml_reader import Shuttle

        return Shuttle(out.data, out.mask, out.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, out=None, xslice=slice(None), yslice=slice(None)):
    """Load a dataset."""
    # Read bands
    data = self.read_band(key, info)
    # Convert to xarray
    xdata = xr.DataArray(data, dims=["y", "x"])
    # Mask invalid values
    return xdata