diff --git a/satpy/composites/__init__.py b/satpy/composites/__init__.py index ced0d00b8d..fd6b6f4d92 100644 --- a/satpy/composites/__init__.py +++ b/satpy/composites/__init__.py @@ -618,7 +618,8 @@ def _get_reflectance(self, projectables, optional_datasets): """Calculate 3.x reflectance with pyspectral.""" _nir, _tb11 = projectables LOG.info('Getting reflective part of %s', _nir.attrs['name']) - + da_nir = _nir.data + da_tb11 = _tb11.data sun_zenith = None tb13_4 = None @@ -626,10 +627,10 @@ def _get_reflectance(self, projectables, optional_datasets): wavelengths = dataset.attrs.get('wavelength', [100., 0, 0]) if (dataset.attrs.get('units') == 'K' and wavelengths[0] <= 13.4 <= wavelengths[2]): - tb13_4 = dataset + tb13_4 = dataset.data elif ("standard_name" in dataset.attrs and dataset.attrs["standard_name"] == "solar_zenith_angle"): - sun_zenith = dataset + sun_zenith = dataset.data # Check if the sun-zenith angle was provided: if sun_zenith is None: @@ -638,7 +639,7 @@ def _get_reflectance(self, projectables, optional_datasets): lons, lats = _nir.attrs["area"].get_lonlats(chunks=CHUNK_SIZE) sun_zenith = sun_zenith_angle(_nir.attrs['start_time'], lons, lats) - return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4) + return self._refl3x.reflectance_from_tbs(sun_zenith, da_nir, da_tb11, tb_ir_co2=tb13_4) class NIREmissivePartFromReflectance(NIRReflectance): diff --git a/satpy/tests/compositor_tests/__init__.py b/satpy/tests/compositor_tests/__init__.py index 5c0f72986f..241652e083 100644 --- a/satpy/tests/compositor_tests/__init__.py +++ b/satpy/tests/compositor_tests/__init__.py @@ -528,8 +528,9 @@ def test_compositor(self, calculator, apply_modifier_info, sza): """Test NIR reflectance compositor.""" import numpy as np import xarray as xr + import dask.array as da refl_arr = np.random.random((2, 2)) - refl = xr.DataArray(refl_arr, dims=['y', 'x']) + refl = da.from_array(refl_arr) refl_from_tbs = mock.MagicMock() refl_from_tbs.return_value = refl calculator.return_value = mock.MagicMock( @@ -538,7 +539,7 @@ def test_compositor(self, calculator, apply_modifier_info, sza): from satpy.composites import NIRReflectance nir_arr = np.random.random((2, 2)) - nir = xr.DataArray(nir_arr, dims=['y', 'x']) + nir = xr.DataArray(da.from_array(nir_arr), dims=['y', 'x']) platform = 'Meteosat-11' sensor = 'seviri' chan_name = 'IR_039' @@ -552,12 +553,11 @@ def test_compositor(self, calculator, apply_modifier_info, sza): start_time = 1 nir.attrs['start_time'] = start_time ir_arr = 100 * np.random.random((2, 2)) - ir_ = xr.DataArray(ir_arr, dims=['y', 'x']) + ir_ = xr.DataArray(da.from_array(ir_arr), dims=['y', 'x']) sunz_arr = 100 * np.random.random((2, 2)) - sunz = xr.DataArray(sunz_arr, dims=['y', 'x']) + sunz = xr.DataArray(da.from_array(sunz_arr), dims=['y', 'x']) sunz.attrs['standard_name'] = 'solar_zenith_angle' - sunz2 = xr.DataArray(sunz_arr, dims=['y', 'x']) - sunz2.attrs['standard_name'] = 'solar_zenith_angle' + sunz2 = da.from_array(sunz_arr) sza.return_value = sunz2 comp = NIRReflectance(name='test') @@ -576,15 +576,15 @@ def test_compositor(self, calculator, apply_modifier_info, sza): res = comp([nir, ir_], optional_datasets=[], **info) get_lonlats.assert_called() sza.assert_called_with(start_time, lons, lats) - refl_from_tbs.assert_called_with(sunz2, nir, ir_, tb_ir_co2=None) + refl_from_tbs.assert_called_with(sunz2, nir.data, ir_.data, tb_ir_co2=None) refl_from_tbs.reset_mock() co2_arr = np.random.random((2, 2)) - co2 = xr.DataArray(co2_arr, dims=['y', 'x']) + co2 = xr.DataArray(da.from_array(co2_arr), dims=['y', 'x']) co2.attrs['wavelength'] = [12.0, 13.0, 14.0] co2.attrs['units'] = 'K' res = comp([nir, ir_], optional_datasets=[co2], **info) - refl_from_tbs.assert_called_with(sunz2, nir, ir_, tb_ir_co2=co2) + refl_from_tbs.assert_called_with(sunz2, nir.data, ir_.data, tb_ir_co2=co2.data) class TestColormapCompositor(unittest.TestCase):