gurudesh/pytracebugs huggingface dataset:
# Buggy code
def end_time(self):
    """Return the end time of the file."""
    return self.info["end_time"]


# 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 the end time of the file."""
    return self.attrs["end_time"]
# Buggy code
def all_composite_ids(self, sensor_names=None):
    """Get all composite IDs that are configured.

    :return: generator of configured composite names
    """
    if sensor_names is None:
        sensor_names = self.info["sensor"]
    compositors = []
    # Note if we get compositors from the dep tree then it will include
    # modified composites which we don't want
    for sensor_name in sensor_names:
        compositors.extend(self.cpl.compositors.get(sensor_name, {}).keys())
    return sorted(set(compositors))


# 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 all_composite_ids(self, sensor_names=None):
    """Get all composite IDs that are configured.

    :return: generator of configured composite names
    """
    if sensor_names is None:
        sensor_names = self.attrs["sensor"]
    compositors = []
    # Note if we get compositors from the dep tree then it will include
    # modified composites which we don't want
    for sensor_name in sensor_names:
        compositors.extend(self.cpl.compositors.get(sensor_name, {}).keys())
    return sorted(set(compositors))
# Buggy code
def iter_by_area(self):
    """Generate datasets grouped by Area.

    :return: generator of (area_obj, list of dataset objects)
    """
    datasets_by_area = {}
    for ds in self:
        a = ds.info.get("area")
        a_str = str(a) if a is not None else None
        datasets_by_area.setdefault(a_str, (a, []))
        datasets_by_area[a_str][1].append(ds.id)

    for area_name, (area_obj, ds_list) in datasets_by_area.items():
        yield area_obj, ds_list


# 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 iter_by_area(self):
    """Generate datasets grouped by Area.

    :return: generator of (area_obj, list of dataset objects)
    """
    datasets_by_area = {}
    for ds in self:
        a = ds.attrs.get("area")
        a_str = str(a) if a is not None else None
        datasets_by_area.setdefault(a_str, (a, []))
        datasets_by_area[a_str][1].append(DatasetID.from_dict(ds.attrs))

    for area_name, (area_obj, ds_list) in datasets_by_area.items():
        yield area_obj, ds_list
# Buggy code
def __setitem__(self, key, value):
    """Add the item to the scene."""
    if not isinstance(value, Dataset):
        raise ValueError("Only 'Dataset' objects can be assigned")
    self.datasets[key] = value
    ds_id = self.datasets.get_key(key)
    self.wishlist.add(ds_id)
    self.dep_tree.add_leaf(ds_id)


# 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 __setitem__(self, key, value):
    """Add the item to the scene."""
    self.datasets[key] = value
    ds_id = self.datasets.get_key(key)
    self.wishlist.add(ds_id)
    self.dep_tree.add_leaf(ds_id)
# Buggy code
def show(self, dataset_id, overlay=None):
    """Show the *dataset* on screen as an image."""

    from satpy.writers import get_enhanced_image

    get_enhanced_image(self[dataset_id], overlay=overlay).show()


# 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 show(self, dataset_id, overlay=None):
    """Show the *dataset* on screen as an image."""
    from satpy.writers import get_enhanced_image

    img = get_enhanced_image(self[dataset_id].squeeze(), overlay=overlay)
    img.show()
    return img
# Buggy code
def load_writer_config(self, config_files, **kwargs):
    conf = {}
    for conf_fn in config_files:
        with open(conf_fn) as fd:
            conf = recursive_dict_update(conf, yaml.load(fd))
    writer_class = conf["writer"]["writer"]
    writer = writer_class(
        ppp_config_dir=self.ppp_config_dir, config_files=config_files, **kwargs
    )
    return writer


# 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_writer_config(self, config_files, **kwargs):
    """Load the writer config for *config_files*."""
    conf = {}
    for conf_fn in config_files:
        with open(conf_fn) as fd:
            conf = recursive_dict_update(conf, yaml.load(fd))
    writer_class = conf["writer"]["writer"]
    writer = writer_class(
        ppp_config_dir=self.ppp_config_dir, config_files=config_files, **kwargs
    )
    return writer
# Buggy code
def save_dataset(self, dataset_id, filename=None, writer=None, overlay=None, **kwargs):
    """Save the *dataset_id* to file using *writer* (geotiff by default)."""
    if writer is None:
        if filename is None:
            writer = self.get_writer("geotiff", **kwargs)
        else:
            writer = self.get_writer_by_ext(os.path.splitext(filename)[1], **kwargs)
    else:
        writer = self.get_writer(writer, **kwargs)
    writer.save_dataset(self[dataset_id], filename=filename, overlay=overlay, **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 save_dataset(self, dataset_id, filename=None, writer=None, overlay=None, **kwargs):
    """Save the *dataset_id* to file using *writer* (default: geotiff)."""
    if writer is None:
        if filename is None:
            writer = self.get_writer("geotiff", **kwargs)
        else:
            writer = self.get_writer_by_ext(os.path.splitext(filename)[1], **kwargs)
    else:
        writer = self.get_writer(writer, **kwargs)
    writer.save_dataset(self[dataset_id], filename=filename, overlay=overlay, **kwargs)
# Buggy code
def get_writer(self, writer="geotiff", **kwargs):
    config_fn = writer + ".yaml" if "." not in writer else writer
    config_files = config_search_paths(
        os.path.join("writers", config_fn), self.ppp_config_dir
    )
    kwargs.setdefault("config_files", config_files)
    return self.load_writer_config(**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 get_writer(self, writer="geotiff", **kwargs):
    """Get the writer instance."""
    config_fn = writer + ".yaml" if "." not in writer else writer
    config_files = config_search_paths(
        os.path.join("writers", config_fn), self.ppp_config_dir
    )
    kwargs.setdefault("config_files", config_files)
    return self.load_writer_config(**kwargs)
# Buggy code
def get_writer_by_ext(self, extension, **kwargs):
    mapping = {".tiff": "geotiff", ".tif": "geotiff", ".nc": "cf"}
    return self.get_writer(mapping.get(extension.lower(), "simple_image"), **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 get_writer_by_ext(self, extension, **kwargs):
    """Find the writer matching the *extension*."""
    mapping = {".tiff": "geotiff", ".tif": "geotiff", ".nc": "cf"}
    return self.get_writer(mapping.get(extension.lower(), "simple_image"), **kwargs)
# Buggy code
def lonlat2xyz(lon, lat):
    """Convert lon lat to cartesian."""
    lat = np.deg2rad(lat)
    lon = np.deg2rad(lon)
    x = np.cos(lat) * np.cos(lon)
    y = np.cos(lat) * np.sin(lon)
    z = np.sin(lat)
    return x, y, z


# 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 lonlat2xyz(lon, lat):
    """Convert lon lat to cartesian."""
    lat = xu.deg2rad(lat)
    lon = xu.deg2rad(lon)
    x = xu.cos(lat) * xu.cos(lon)
    y = xu.cos(lat) * xu.sin(lon)
    z = xu.sin(lat)
    return x, y, z
# Buggy code
def xyz2lonlat(x, y, z):
    """Convert cartesian to lon lat."""
    lon = np.rad2deg(np.arctan2(y, x))
    lat = np.rad2deg(np.arctan2(z, np.sqrt(x**2 + y**2)))
    return lon, lat


# 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 xyz2lonlat(x, y, z):
    """Convert cartesian to lon lat."""
    lon = xu.rad2deg(xu.arctan2(y, x))
    lat = xu.rad2deg(xu.arctan2(z, xu.sqrt(x**2 + y**2)))
    return lon, lat
# Buggy code
def angle2xyz(azi, zen):
    """Convert azimuth and zenith to cartesian."""
    azi = np.deg2rad(azi)
    zen = np.deg2rad(zen)
    x = np.sin(zen) * np.sin(azi)
    y = np.sin(zen) * np.cos(azi)
    z = np.cos(zen)
    return x, y, z


# 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 angle2xyz(azi, zen):
    """Convert azimuth and zenith to cartesian."""
    azi = xu.deg2rad(azi)
    zen = xu.deg2rad(zen)
    x = xu.sin(zen) * xu.sin(azi)
    y = xu.sin(zen) * xu.cos(azi)
    z = xu.cos(zen)
    return x, y, z
# Buggy code
def xyz2angle(x, y, z):
    """Convert cartesian to azimuth and zenith."""
    azi = np.rad2deg(np.arctan2(x, y))
    zen = 90 - np.rad2deg(np.arctan2(z, np.sqrt(x**2 + y**2)))
    return azi, zen


# 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 xyz2angle(x, y, z):
    """Convert cartesian to azimuth and zenith."""
    azi = xu.rad2deg(xu.arctan2(x, y))
    zen = 90 - xu.rad2deg(xu.arctan2(z, xu.sqrt(x**2 + y**2)))
    return azi, zen
# Buggy code
def _determine_mode(dataset):
    if "mode" in dataset.info:
        return dataset.info["mode"]

    if dataset.ndim == 2:
        return "L"
    elif dataset.shape[0] == 2:
        return "LA"
    elif dataset.shape[0] == 3:
        return "RGB"
    elif dataset.shape[0] == 4:
        return "RGBA"
    else:
        raise RuntimeError("Can't determine 'mode' of dataset: %s" % (dataset.id,))


# 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 _determine_mode(dataset):
    if "mode" in dataset.attrs:
        return dataset.attrs["mode"]

    if dataset.ndim == 2:
        return "L"
    elif dataset.shape[0] == 2:
        return "LA"
    elif dataset.shape[0] == 3:
        return "RGB"
    elif dataset.shape[0] == 4:
        return "RGBA"
    else:
        raise RuntimeError("Can't determine 'mode' of dataset: %s" % str(dataset))
# Buggy code
def show(dataset, **kwargs):
    """Display the dataset as an image."""
    if not dataset.is_loaded():
        raise ValueError("Dataset not loaded, cannot display.")

    img = get_enhanced_image(dataset, **kwargs)
    img.show()


# 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 show(dataset, **kwargs):
    """Display the dataset as an image."""
    img = get_enhanced_image(dataset.squeeze(), **kwargs)
    img.show()
    return img
# Buggy code
def to_image(dataset, copy=True, **kwargs):
    # Only add keywords if they are present
    for key in ["mode", "fill_value", "palette"]:
        if key in dataset.info:
            kwargs.setdefault(key, dataset.info[key])

    if dataset.ndim == 2:
        return Image([dataset], copy=copy, **kwargs)
    elif dataset.ndim == 3:
        return Image([band for band in dataset], copy=copy, **kwargs)
    else:
        raise ValueError(
            "Don't know how to convert array with ndim %d to image" % dataset.ndim
        )


# 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_image(dataset, copy=False, **kwargs):
    # Only add keywords if they are present
    for key in ["mode", "fill_value", "palette"]:
        if key in dataset.attrs:
            kwargs.setdefault(key, dataset.attrs[key])
    dataset = dataset.squeeze()

    if "bands" in dataset.dims:
        return Image(
            [
                np.ma.masked_invalid(dataset.sel(bands=band).values)
                for band in dataset["bands"]
            ],
            copy=copy,
            **kwargs,
        )
    elif dataset.ndim < 2:
        raise ValueError("Need at least a 2D array to make an image.")
    else:
        return Image([np.ma.masked_invalid(dataset.values)], copy=copy, **kwargs)
# Buggy code
def save_dataset(
    self, dataset, filename=None, fill_value=None, overlay=None, decorate=None, **kwargs
):
    """Saves the *dataset* to a given *filename*."""
    fill_value = fill_value if fill_value is not None else self.fill_value
    img = get_enhanced_image(
        dataset, self.enhancer, fill_value, overlay=overlay, decorate=decorate
    )
    self.save_image(img, filename=filename, **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 save_dataset(
    self, dataset, filename=None, fill_value=None, overlay=None, decorate=None, **kwargs
):
    """Saves the *dataset* to a given *filename*."""
    fill_value = fill_value if fill_value is not None else self.fill_value
    img = get_enhanced_image(
        dataset.squeeze(), self.enhancer, fill_value, overlay=overlay, decorate=decorate
    )
    self.save_image(img, filename=filename, **kwargs)
# Buggy code
def omerc2cf(proj_dict):
    """Return the cf grid mapping for the omerc projection."""
    grid_mapping_name = "oblique_mercator"

    if "no_rot" in proj_dict:
        no_rotation = " "
    else:
        no_rotation = None

    args = dict(
        azimuth_of_central_line=proj_dict.get("alpha"),
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lonc"),
        # longitude_of_projection_origin=0.,
        no_rotation=no_rotation,
        # reference_ellipsoid_name=proj_dict.get('ellps'),
        semi_major_axis=6378137.0,
        semi_minor_axis=6356752.3142,
        false_easting=0.0,
        false_northing=0.0,
        crtype="grid_mapping",
        coords=["projection_x_coordinate", "projection_y_coordinate"],
    )
    return cf.CoordinateReference(grid_mapping_name, **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 omerc2cf(proj_dict):
    """Return the cf grid mapping for the omerc projection."""
    if "no_rot" in proj_dict:
        no_rotation = " "
    else:
        no_rotation = None

    args = dict(
        azimuth_of_central_line=proj_dict.get("alpha"),
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lonc"),
        grid_mapping_name="oblique_mercator",
        # longitude_of_projection_origin=0.,
        no_rotation=no_rotation,
        # reference_ellipsoid_name=proj_dict.get('ellps'),
        semi_major_axis=6378137.0,
        semi_minor_axis=6356752.3142,
        false_easting=0.0,
        false_northing=0.0,
    )
    return args
# Buggy code
def geos2cf(proj_dict):
    """Return the cf grid mapping for the geos projection."""
    grid_mapping_name = "geostationary"

    args = dict(
        perspective_point_height=proj_dict.get("h"),
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lon_0"),
        semi_major_axis=proj_dict.get("a"),
        semi_minor_axis=proj_dict.get("b"),
        sweep_axis=proj_dict.get("sweep"),
        crtype="grid_mapping",
        coords=["projection_x_coordinate", "projection_y_coordinate"],
    )
    return cf.CoordinateReference(grid_mapping_name, **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 geos2cf(proj_dict):
    """Return the cf grid mapping for the geos projection."""
    args = dict(
        perspective_point_height=proj_dict.get("h"),
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lon_0"),
        grid_mapping_name="geostationary",
        semi_major_axis=proj_dict.get("a"),
        semi_minor_axis=proj_dict.get("b"),
        sweep_axis=proj_dict.get("sweep"),
    )
    return args
# Buggy code
def laea2cf(proj_dict):
    """Return the cf grid mapping for the laea projection."""
    grid_mapping_name = "lambert_azimuthal_equal_area"

    args = dict(
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lon_0"),
        crtype="grid_mapping",
        coords=["projection_x_coordinate", "projection_y_coordinate"],
    )
    return cf.CoordinateReference(grid_mapping_name, **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 laea2cf(proj_dict):
    """Return the cf grid mapping for the laea projection."""
    args = dict(
        latitude_of_projection_origin=proj_dict.get("lat_0"),
        longitude_of_projection_origin=proj_dict.get("lon_0"),
        grid_mapping_name="lambert_azimuthal_equal_area",
    )
    return args
# Buggy code
def create_grid_mapping(area):
    """Create the grid mapping instance for `area`."""

    try:
        grid_mapping = mappings[area.proj_dict["proj"]](area.proj_dict)
    except KeyError:
        raise NotImplementedError

    return grid_mapping


# 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 create_grid_mapping(area):
    """Create the grid mapping instance for `area`."""
    try:
        grid_mapping = mappings[area.proj_dict["proj"]](area.proj_dict)
        grid_mapping["name"] = area.proj_dict["proj"]
    except KeyError:
        raise NotImplementedError

    return grid_mapping
# Buggy code
def _get_calibration_params(self):
    """Get the calibration parameters from the metadata."""
    params = {}
    idx_table = []
    val_table = []
    for elt in self.mda["image_data_function"].split("\r\n"):
        try:
            key, val = elt.split(":=")
            try:
                idx_table.append(int(key))
                val_table.append(float(val))
            except ValueError:
                params[key] = val
        except ValueError:
            pass
    params["indices"] = np.array(idx_table)
    params["values"] = np.array(val_table, dtype=np.float32)
    return params


# Traceback (AttributeError)
Traceback (most recent call last):
File "test_hrit_goes.py", line 19, in <module>
scn.load([composite])
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 566, in load
self.read(**kwargs)
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 507, in read
return self.read_datasets(nodes, **kwargs)
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 377, in read_datasets
new_datasets = reader_instance.load(ds_ids, **kwargs)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 850, in load
ds = self._load_dataset_with_area(dsid, coords)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 794, in _load_dataset_with_area
ds = self._load_dataset_data(file_handlers, dsid, **slice_kwargs)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 648, in _load_dataset_data
proj = self._load_dataset(dsid, ds_info, file_handlers)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 619, in _load_dataset
projectable = fh.get_dataset(dsid, ds_info)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 425, in get_dataset
self.calibrate(out, key.calibration)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 460, in calibrate
self._calibrate(data)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 473, in _calibrate
data.mask[:] = data.data == 0
File "/home/a001673/.local/lib/python2.7/site-packages/xarray/core/common.py", line 176, in __getattr__
(type(self).__name__, name))
AttributeError: 'DataArray' object has no attribute 'mask'

# Fixed code
def _get_calibration_params(self):
    """Get the calibration parameters from the metadata."""
    params = {}
    idx_table = []
    val_table = []
    for elt in self.mda["image_data_function"].split(b"\r\n"):
        try:
            key, val = elt.split(b":=")
            try:
                idx_table.append(int(key))
                val_table.append(float(val))
            except ValueError:
                params[key] = val
        except ValueError:
            pass
    params["indices"] = np.array(idx_table)
    params["values"] = np.array(val_table, dtype=np.float32)
    return params
# Buggy code
def _calibrate(self, data):
    """Calibrate *data*."""
    idx = self.mda["calibration_parameters"]["indices"]
    val = self.mda["calibration_parameters"]["values"]
    ddata = data.data.map_blocks(
        lambda block: np.interp(block, idx, val), dtype=val.dtype
    )
    res = xr.DataArray(ddata, dims=data.dims, attrs=data.attrs, coords=data.coords)
    res = res.clip(min=0)
    units = {"percent": "%"}
    unit = self.mda["calibration_parameters"]["_UNIT"]
    res.attrs["units"] = units.get(unit, unit)
    return res


# Traceback (AttributeError)
Traceback (most recent call last):
File "test_hrit_goes.py", line 19, in <module>
scn.load([composite])
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 566, in load
self.read(**kwargs)
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 507, in read
return self.read_datasets(nodes, **kwargs)
File "/home/a001673/usr/src/satpy/satpy/scene.py", line 377, in read_datasets
new_datasets = reader_instance.load(ds_ids, **kwargs)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 850, in load
ds = self._load_dataset_with_area(dsid, coords)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 794, in _load_dataset_with_area
ds = self._load_dataset_data(file_handlers, dsid, **slice_kwargs)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 648, in _load_dataset_data
proj = self._load_dataset(dsid, ds_info, file_handlers)
File "/home/a001673/usr/src/satpy/satpy/readers/yaml_reader.py", line 619, in _load_dataset
projectable = fh.get_dataset(dsid, ds_info)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 425, in get_dataset
self.calibrate(out, key.calibration)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 460, in calibrate
self._calibrate(data)
File "/home/a001673/usr/src/satpy/satpy/readers/hrit_goes.py", line 473, in _calibrate
data.mask[:] = data.data == 0
File "/home/a001673/.local/lib/python2.7/site-packages/xarray/core/common.py", line 176, in __getattr__
(type(self).__name__, name))
AttributeError: 'DataArray' object has no attribute 'mask'

# Fixed code
def _calibrate(self, data):
    """Calibrate *data*."""
    idx = self.mda["calibration_parameters"]["indices"]
    val = self.mda["calibration_parameters"]["values"]
    ddata = data.data.map_blocks(
        lambda block: np.interp(block, idx, val), dtype=val.dtype
    )
    res = xr.DataArray(ddata, dims=data.dims, attrs=data.attrs, coords=data.coords)
    res = res.clip(min=0)
    units = {"percent": "%"}
    unit = self.mda["calibration_parameters"][b"_UNIT"]
    res.attrs["units"] = units.get(unit, unit)
    return res