gurudesh/pytracebugs huggingface dataset:
# Buggy code
def get_dataset(self, key, info, out=None, xslice=slice(None), yslice=slice(None)):
    """Get the data  from the files."""
    res = super(HRITGOMSFileHandler, self).get_dataset(key, info, out, xslice, yslice)

    if res is not None:
        out = res

    self.calibrate(out, key.calibration)
    out.info["units"] = info["units"]
    out.info["standard_name"] = info["standard_name"]
    out.info["platform_name"] = self.platform_name
    out.info["sensor"] = "msu-gs"


# 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)):
    """Get the data  from the files."""
    res = super(HRITGOMSFileHandler, self).get_dataset(key, info)

    res = self.calibrate(res, key.calibration)
    res.attrs["units"] = info["units"]
    res.attrs["standard_name"] = info["standard_name"]
    res.attrs["platform_name"] = self.platform_name
    res.attrs["sensor"] = "msu-gs"
    res.attrs["satellite_longitude"] = self.mda["projection_parameters"][
        "SSP_longitude"
    ]
    res.attrs["satellite_latitude"] = 0
    res.attrs["satellite_altitude"] = 35785831.00

    return res
# Buggy code
def calibrate(self, data, calibration):
    """Calibrate the data."""
    tic = datetime.now()

    if calibration == "counts":
        return

    if calibration == "radiance":
        self._vis_calibrate(data)
    elif calibration == "brightness_temperature":
        self._ir_calibrate(data)
    else:
        raise NotImplementedError("Don't know how to calibrate to " + str(calibration))

    logger.debug("Calibration time " + str(datetime.now() - tic))


# Traceback (AttributeError)
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] Saving datasets to NetCDF4/CF.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No longitude and latitude data to save.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No grid mapping to save.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-58ece08c15f3> in <module>()
----> 1 lcl.save_datasets(writer='cf', filename='/tmp/foo.nc')

/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.pyc in save_datasets(self, writer, datasets, **kwargs)
632             datasets = self.datasets.values()
633         writer = self.get_writer(writer, **kwargs)
--> 634         writer.save_datasets(datasets, **kwargs)
635
636     def get_writer(self, writer="geotiff", **kwargs):

/home/lahtinep/Software/pytroll/packages/satpy/satpy/writers/cf_writer.pyc in save_datasets(self, datasets, filename, **kwargs)
176                     coords = [line_coord, pixel_coord]
177
--> 178                 domain = cf.Domain(dim=coords,
179                                    aux=aux,
180                                    ref=grid_mapping)

AttributeError: 'module' object has no attribute 'Domain'

# Fixed code
def calibrate(self, data, calibration):
    """Calibrate the data."""
    tic = datetime.now()

    if calibration == "counts":
        res = data

    if calibration in ["radiance", "brightness_temperature"]:
        res = self._calibrate(data)
    else:
        raise NotImplementedError("Don't know how to calibrate to " + str(calibration))

    res.attrs["standard_name"] = calibration
    res.attrs["calibration"] = calibration

    logger.debug("Calibration time " + str(datetime.now() - tic))
    return res
# Buggy code
def get_area_extent(self, size, offsets, factors, platform_height):
    """Get the area extent of the file."""
    nlines, ncols = size
    h = platform_height

    loff, coff = offsets
    loff -= nlines
    offsets = loff, coff
    # count starts at 1
    cols = 1 - 0.5
    lines = 1 - 0.5
    ll_x, ll_y = self.get_xy_from_linecol(-lines, cols, offsets, factors)

    cols += ncols
    lines += nlines
    ur_x, ur_y = self.get_xy_from_linecol(-lines, cols, offsets, factors)

    aex = (
        np.deg2rad(ll_x) * h,
        np.deg2rad(ll_y) * h,
        np.deg2rad(ur_x) * h,
        np.deg2rad(ur_y) * h,
    )

    if self.prologue["GeometricProcessing"]["EarthModel"]["TypeOfEarthModel"] < 2:
        xadj = 1500
        yadj = 1500
        aex = (aex[0] + xadj, aex[1] + yadj, aex[2] + xadj, aex[3] + yadj)

    return aex


# 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_area_extent(self, size, offsets, factors, platform_height):
    """Get the area extent of the file."""
    nlines, ncols = size
    h = platform_height

    loff, coff = offsets
    loff -= nlines
    offsets = loff, coff
    # count starts at 1
    cols = 1 - 0.5
    lines = 1 - 0.5
    ll_x, ll_y = self.get_xy_from_linecol(-lines, cols, offsets, factors)

    cols += ncols
    lines += nlines
    ur_x, ur_y = self.get_xy_from_linecol(-lines, cols, offsets, factors)

    aex = (
        np.deg2rad(ll_x) * h,
        np.deg2rad(ll_y) * h,
        np.deg2rad(ur_x) * h,
        np.deg2rad(ur_y) * h,
    )

    if not self.mda["offset_corrected"]:
        xadj = 1500
        yadj = 1500
        aex = (aex[0] + xadj, aex[1] + yadj, aex[2] + xadj, aex[3] + yadj)

    return aex
# Buggy code
def get_dataset(self, key, info, out=None, xslice=slice(None), yslice=slice(None)):
    res = super(HRITMSGFileHandler, self).get_dataset(key, info, out, xslice, yslice)
    if res is not None:
        out = res

    self.calibrate(out, key.calibration)

    out.info["units"] = info["units"]
    out.info["wavelength"] = info["wavelength"]
    out.info["standard_name"] = info["standard_name"]
    out.info["platform_name"] = self.platform_name
    out.info["sensor"] = "seviri"
    out.info["satellite_longitude"] = self.mda["projection_parameters"]["SSP_longitude"]
    out.info["satellite_latitude"] = self.mda["projection_parameters"]["SSP_latitude"]
    out.info["satellite_altitude"] = self.mda["projection_parameters"]["h"]


# 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):
    res = super(HRITMSGFileHandler, self).get_dataset(key, info)
    res = self.calibrate(res, key.calibration)
    res.attrs["units"] = info["units"]
    res.attrs["wavelength"] = info["wavelength"]
    res.attrs["standard_name"] = info["standard_name"]
    res.attrs["platform_name"] = self.platform_name
    res.attrs["sensor"] = "seviri"
    res.attrs["satellite_longitude"] = self.mda["projection_parameters"][
        "SSP_longitude"
    ]
    res.attrs["satellite_latitude"] = self.mda["projection_parameters"]["SSP_latitude"]
    res.attrs["satellite_altitude"] = self.mda["projection_parameters"]["h"]

    return res
# Buggy code
def calibrate(self, data, calibration):
    """Calibrate the data."""
    tic = datetime.now()

    if calibration == "counts":
        return

    if calibration in ["radiance", "reflectance", "brightness_temperature"]:
        self.convert_to_radiance(data)
    if calibration == "reflectance":
        self._vis_calibrate(data)
    elif calibration == "brightness_temperature":
        self._ir_calibrate(data)

    logger.debug("Calibration time " + str(datetime.now() - tic))


# Traceback (AttributeError)
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] Saving datasets to NetCDF4/CF.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No longitude and latitude data to save.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No grid mapping to save.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-58ece08c15f3> in <module>()
----> 1 lcl.save_datasets(writer='cf', filename='/tmp/foo.nc')

/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.pyc in save_datasets(self, writer, datasets, **kwargs)
632             datasets = self.datasets.values()
633         writer = self.get_writer(writer, **kwargs)
--> 634         writer.save_datasets(datasets, **kwargs)
635
636     def get_writer(self, writer="geotiff", **kwargs):

/home/lahtinep/Software/pytroll/packages/satpy/satpy/writers/cf_writer.pyc in save_datasets(self, datasets, filename, **kwargs)
176                     coords = [line_coord, pixel_coord]
177
--> 178                 domain = cf.Domain(dim=coords,
179                                    aux=aux,
180                                    ref=grid_mapping)

AttributeError: 'module' object has no attribute 'Domain'

# Fixed code
def calibrate(self, data, calibration):
    """Calibrate the data."""
    tic = datetime.now()
    if calibration == "counts":
        res = data
    elif calibration in ["radiance", "reflectance", "brightness_temperature"]:
        res = self.convert_to_radiance(data)
    if calibration == "reflectance":
        res = self._vis_calibrate(res)
    elif calibration == "brightness_temperature":
        res = self._ir_calibrate(res)

    logger.debug("Calibration time " + str(datetime.now() - tic))
    return res
# Buggy code
def convert_to_radiance(self, data):
    """Calibrate to radiance."""
    coeffs = self.prologue["RadiometricProcessing"]
    coeffs = coeffs["Level1_5ImageCalibration"]
    gain = coeffs["Cal_Slope"][self.mda["spectral_channel_id"] - 1]
    offset = coeffs["Cal_Offset"][self.mda["spectral_channel_id"] - 1]

    data.data[:] *= gain
    data.data[:] += offset
    data.data[data.data < 0] = 0


# 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 convert_to_radiance(self, data):
    """Calibrate to radiance."""
    coeffs = self.prologue["RadiometricProcessing"]
    coeffs = coeffs["Level1_5ImageCalibration"]
    gain = coeffs["Cal_Slope"][self.mda["spectral_channel_id"] - 1]
    offset = coeffs["Cal_Offset"][self.mda["spectral_channel_id"] - 1]

    return mb.convert_to_radiance(data, gain, offset)
# Buggy code
def _vis_calibrate(self, data):
    """Visible channel calibration only."""
    solar_irradiance = CALIB[self.platform_id][self.channel_name]["F"]
    data.data[:] *= 100 / solar_irradiance


# 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):
    """Visible channel calibration only."""
    solar_irradiance = CALIB[self.platform_id][self.channel_name]["F"]
    return mb.vis_calibrate(data, solar_irradiance)
# Buggy code
def _erads2bt(self, data):
    """computation based on effective radiance."""
    cal_info = CALIB[self.platform_id][self.channel_name]
    alpha = cal_info["ALPHA"]
    beta = cal_info["BETA"]

    self._tl15(data)

    data.data[:] -= beta
    data.data[:] /= alpha


# 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 _erads2bt(self, data):
    """computation based on effective radiance."""
    cal_info = CALIB[self.platform_id][self.channel_name]
    alpha = cal_info["ALPHA"]
    beta = cal_info["BETA"]
    wavenumber = cal_info["VC"]

    return mb.erads2bt(data, wavenumber, alpha, beta)
# Buggy code
def _srads2bt(self, data):
    """computation based on spectral radiance."""
    coef_a, coef_b, coef_c = BTFIT[self.channel_name]

    self._tl15(data)

    data.data[:] = coef_a * data.data[:] ** 2 + coef_b * data.data[:] + coef_c


# 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 _srads2bt(self, data):
    """computation based on spectral radiance."""
    coef_a, coef_b, coef_c = BTFIT[self.channel_name]
    wavenumber = CALIB[self.platform_id][self.channel_name]["VC"]

    return mb.srads2bt(data, wavenumber, coef_a, coef_b, coef_c)
# Buggy code
def _ir_calibrate(self, data):
    """IR calibration."""
    cal_type = self.prologue["ImageDescription"]["Level1_5ImageProduction"][
        "PlannedChanProcessing"
    ][self.mda["spectral_channel_id"]]

    if cal_type == 1:
        # spectral radiances
        self._srads2bt(data)
    elif cal_type == 2:
        # effective radiances
        self._erads2bt(data)
    else:
        raise NotImplemented("Unknown calibration type")


# 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):
    """IR calibration."""
    cal_type = self.prologue["ImageDescription"]["Level1_5ImageProduction"][
        "PlannedChanProcessing"
    ][self.mda["spectral_channel_id"]]

    if cal_type == 1:
        # spectral radiances
        return self._srads2bt(data)
    elif cal_type == 2:
        # effective radiances
        return self._erads2bt(data)
    else:
        raise NotImplemented("Unknown calibration type")
# Buggy code
def __init__(self, filename, filename_info, filetype_info):
    """Initialize the reader."""

    self.filename = filename
    self.platform_name = None
    self.available_channels = {}
    self.channel_order_list = []
    for item in CHANNEL_LIST:
        self.available_channels[item] = False

    self._get_header()

    for item in CHANNEL_LIST:
        if item in self.available_channels and self.available_channels[item]:
            self.channel_order_list.append(item)

    self.memmap = self._get_memmap()


# 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):
    """Initialize the reader."""

    self.filename = filename
    self.platform_name = None
    self.available_channels = {}
    self.channel_order_list = []
    for item in CHANNEL_LIST:
        self.available_channels[item] = False

    self._get_header()

    for item in CHANNEL_LIST:
        if self.available_channels.get(item):
            self.channel_order_list.append(item)

    self.memmap = self._get_memmap()
# Buggy code
def calibrate(self, data, key):
    """Calibrate the data."""
    tic = datetime.now()

    calibration = key.calibration
    if calibration == "counts":
        return

    if calibration in ["radiance", "reflectance", "brightness_temperature"]:
        self.convert_to_radiance(data, key.name)
    if calibration == "reflectance":
        self._vis_calibrate(data, key.name)
    elif calibration == "brightness_temperature":
        self._ir_calibrate(data, key.name)

    logger.debug("Calibration time " + str(datetime.now() - tic))


# Traceback (AttributeError)
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] Saving datasets to NetCDF4/CF.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No longitude and latitude data to save.
[INFO: 2017-12-12 08:14:04 : satpy.writers.cf_writer] No grid mapping to save.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-58ece08c15f3> in <module>()
----> 1 lcl.save_datasets(writer='cf', filename='/tmp/foo.nc')

/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.pyc in save_datasets(self, writer, datasets, **kwargs)
632             datasets = self.datasets.values()
633         writer = self.get_writer(writer, **kwargs)
--> 634         writer.save_datasets(datasets, **kwargs)
635
636     def get_writer(self, writer="geotiff", **kwargs):

/home/lahtinep/Software/pytroll/packages/satpy/satpy/writers/cf_writer.pyc in save_datasets(self, datasets, filename, **kwargs)
176                     coords = [line_coord, pixel_coord]
177
--> 178                 domain = cf.Domain(dim=coords,
179                                    aux=aux,
180                                    ref=grid_mapping)

AttributeError: 'module' object has no attribute 'Domain'

# Fixed code
def calibrate(self, data, key):
    """Calibrate the data."""
    tic = datetime.now()

    calibration = key.calibration
    if calibration == "counts":
        return

    if calibration in ["radiance", "reflectance", "brightness_temperature"]:
        res = self.convert_to_radiance(data, key.name)
    if calibration == "reflectance":
        res = self._vis_calibrate(res, key.name)
    elif calibration == "brightness_temperature":
        res = self._ir_calibrate(res, key.name)

    logger.debug("Calibration time " + str(datetime.now() - tic))

    return res
# Buggy code
def convert_to_radiance(self, data, key_name):
    """Calibrate to radiance."""

    coeffs = self.header["15_DATA_HEADER"]["RadiometricProcessing"][
        "Level15ImageCalibration"
    ]

    channel_index = self.channel_order_list.index(key_name)

    gain = coeffs["CalSlope"][0][channel_index]
    offset = coeffs["CalOffset"][0][channel_index]

    data.data[:] *= gain
    data.data[:] += offset
    data.data[data.data < 0] = 0


# 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 convert_to_radiance(self, data, key_name):
    """Calibrate to radiance."""

    coeffs = self.header["15_DATA_HEADER"]["RadiometricProcessing"][
        "Level15ImageCalibration"
    ]

    channel_index = self.channel_order_list.index(key_name)

    gain = coeffs["CalSlope"][0][channel_index]
    offset = coeffs["CalOffset"][0][channel_index]

    return mb.convert_to_radiance(data, gain, offset)
# Buggy code
def _vis_calibrate(self, data, key_name):
    """Visible channel calibration only."""
    solar_irradiance = CALIB[self.platform_id][key_name]["F"]
    data.data[:] *= 100 / solar_irradiance


# 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, key_name):
    """Visible channel calibration only."""
    solar_irradiance = CALIB[self.platform_id][key_name]["F"]
    return mb.vis_calibrate(data, solar_irradiance)
# Buggy code
def _erads2bt(self, data, key_name):
    """computation based on effective radiance."""
    cal_info = CALIB[self.platform_id][key_name]
    alpha = cal_info["ALPHA"]
    beta = cal_info["BETA"]

    self._tl15(data, key_name)

    data.data[:] -= beta
    data.data[:] /= alpha


# 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 _erads2bt(self, data, key_name):
    """computation based on effective radiance."""
    cal_info = CALIB[self.platform_id][key_name]
    alpha = cal_info["ALPHA"]
    beta = cal_info["BETA"]
    wavenumber = CALIB[self.platform_id][key_name]["VC"]

    return mb.erads2bt(data, wavenumber, alpha, beta)
# Buggy code
def _srads2bt(self, data, key_name):
    """computation based on spectral radiance."""
    coef_a, coef_b, coef_c = BTFIT[key_name]

    self._tl15(data, key_name)

    data.data[:] = coef_a * data.data[:] ** 2 + coef_b * data.data[:] + coef_c


# 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 _srads2bt(self, data, key_name):
    """computation based on spectral radiance."""
    coef_a, coef_b, coef_c = BTFIT[key_name]
    wavenumber = CALIB[self.platform_id][key_name]["VC"]

    return mb.srads2bt(data, wavenumber, coef_a, coef_b, coef_c)
# Buggy code
def _ir_calibrate(self, data, key_name):
    """IR calibration."""

    channel_index = self.channel_order_list.index(key_name)

    cal_type = self.header["15_DATA_HEADER"]["ImageDescription"][
        "Level15ImageProduction"
    ]["PlannedChanProcessing"][0][channel_index]

    if cal_type == 1:
        # spectral radiances
        self._srads2bt(data, key_name)
    elif cal_type == 2:
        # effective radiances
        self._erads2bt(data, key_name)
    else:
        raise NotImplementedError("Unknown calibration type")


# 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, key_name):
    """IR calibration."""

    channel_index = self.channel_order_list.index(key_name)

    cal_type = self.header["15_DATA_HEADER"]["ImageDescription"][
        "Level15ImageProduction"
    ]["PlannedChanProcessing"][0][channel_index]

    if cal_type == 1:
        # spectral radiances
        return self._srads2bt(data, key_name)
    elif cal_type == 2:
        # effective radiances
        return self._erads2bt(data, key_name)
    else:
        raise NotImplementedError("Unknown calibration type")
# Buggy code
def __init__(self, filename, filename_info, filetype_info):
    """Init method"""
    super(NcNWCSAF, self).__init__(filename, filename_info, filetype_info)
    self.nc = h5netcdf.File(filename, "r")
    self.pps = False

    try:
        # MSG:
        sat_id = self.nc.attrs["satellite_identifier"]
        self.platform_name = PLATFORM_NAMES[sat_id]
    except KeyError:
        # PPS:
        self.platform_name = self.nc.attrs["platform"]
        self.pps = True

    self.sensor = SENSOR.get(self.platform_name, "seviri")


# 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):
    """Init method."""
    super(NcNWCSAF, self).__init__(filename, filename_info, filetype_info)
    self.nc = xr.open_dataset(
        filename, decode_cf=True, mask_and_scale=False, engine="h5netcdf", chunks=1000
    )

    self.nc = self.nc.rename({"nx": "x", "ny": "y"})

    self.pps = False

    try:
        # MSG:
        sat_id = self.nc.attrs["satellite_identifier"]
        try:
            self.platform_name = PLATFORM_NAMES[sat_id]
        except KeyError:
            self.platform_name = PLATFORM_NAMES[sat_id.astype(str)]
    except KeyError:
        # PPS:
        self.platform_name = self.nc.attrs["platform"]
        self.pps = True

    self.sensor = SENSOR.get(self.platform_name, "seviri")
# Buggy code
def get_area_def(self, dsid):
    """Get the area definition of the datasets in the file.
    Only applicable for MSG products!"""
    if self.pps:
        # PPS:
        raise NotImplementedError

    if dsid.name.endswith("_pal"):
        raise NotImplementedError

    proj_str = self.nc.attrs["gdal_projection"] + " +units=km"

    nlines, ncols = self.nc[dsid.name].shape

    area_extent = (
        float(self.nc.attrs["gdal_xgeo_up_left"]) / 1000,
        float(self.nc.attrs["gdal_ygeo_low_right"]) / 1000,
        float(self.nc.attrs["gdal_xgeo_low_right"]) / 1000,
        float(self.nc.attrs["gdal_ygeo_up_left"]) / 1000,
    )

    area = get_area_def(
        "some_area_name",
        "On-the-fly area",
        "geosmsg",
        proj_str,
        ncols,
        nlines,
        area_extent,
    )

    return area


# 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_area_def(self, dsid):
    """Get the area definition of the datasets in the file.

    Only applicable for MSG products!
    """
    if self.pps:
        # PPS:
        raise NotImplementedError

    if dsid.name.endswith("_pal"):
        raise NotImplementedError

    try:
        proj_str = self.nc.attrs["gdal_projection"] + " +units=km"
    except TypeError:
        proj_str = self.nc.attrs["gdal_projection"].decode() + " +units=km"

    nlines, ncols = self.nc[dsid.name].shape

    area_extent = (
        float(self.nc.attrs["gdal_xgeo_up_left"]) / 1000,
        float(self.nc.attrs["gdal_ygeo_low_right"]) / 1000,
        float(self.nc.attrs["gdal_xgeo_low_right"]) / 1000,
        float(self.nc.attrs["gdal_ygeo_up_left"]) / 1000,
    )

    area = get_area_def(
        "some_area_name",
        "On-the-fly area",
        "geosmsg",
        proj_str,
        ncols,
        nlines,
        area_extent,
    )

    return area
# Buggy code
def start_time(self):
    try:
        # MSG:
        return datetime.strptime(
            self.nc.attrs["time_coverage_start"], "%Y-%m-%dT%H:%M:%SZ"
        )
    except ValueError:
        # PPS:
        return datetime.strptime(
            self.nc.attrs["time_coverage_start"], "%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 the start time of the object."""
    try:
        # MSG:
        try:
            return datetime.strptime(
                self.nc.attrs["time_coverage_start"], "%Y-%m-%dT%H:%M:%SZ"
            )
        except TypeError:
            return datetime.strptime(
                self.nc.attrs["time_coverage_start"].astype(str), "%Y-%m-%dT%H:%M:%SZ"
            )
    except ValueError:
        # PPS:
        return datetime.strptime(
            self.nc.attrs["time_coverage_start"], "%Y%m%dT%H%M%S%fZ"
        )
# Buggy code
def end_time(self):
    try:
        # MSG:
        return datetime.strptime(
            self.nc.attrs["time_coverage_end"], "%Y-%m-%dT%H:%M:%SZ"
        )
    except ValueError:
        # PPS:
        return datetime.strptime(self.nc.attrs["time_coverage_end"], "%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 the end time of the object."""
    try:
        # MSG:
        try:
            return datetime.strptime(
                self.nc.attrs["time_coverage_end"], "%Y-%m-%dT%H:%M:%SZ"
            )
        except TypeError:
            return datetime.strptime(
                self.nc.attrs["time_coverage_end"].astype(str), "%Y-%m-%dT%H:%M:%SZ"
            )
    except ValueError:
        # PPS:
        return datetime.strptime(self.nc.attrs["time_coverage_end"], "%Y%m%dT%H%M%S%fZ")