Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide only dask arrays to pyspectral's nir reflectance computation #1011

Merged
merged 1 commit into from Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions satpy/composites/__init__.py
Expand Up @@ -618,18 +618,19 @@ 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

for dataset in 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:
Expand All @@ -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):
Expand Down
18 changes: 9 additions & 9 deletions satpy/tests/compositor_tests/__init__.py
Expand Up @@ -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(
Expand All @@ -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'
Expand All @@ -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')
Expand All @@ -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):
Expand Down