Skip to content

Commit

Permalink
Merge pull request #1089 from mraspaud/fix-sunz-correction-computation
Browse files Browse the repository at this point in the history
Make sunz correction use available sunz dataset
  • Loading branch information
mraspaud committed Mar 26, 2020
2 parents f306388 + 3a29b05 commit 6c11402
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions satpy/composites/__init__.py
Expand Up @@ -376,7 +376,7 @@ def __init__(self, max_sza=95.0, **kwargs):

def __call__(self, projectables, **info):
"""Generate the composite."""
projectables = self.match_data_arrays(projectables)
projectables = self.match_data_arrays(list(projectables) + list(info.get('optional_datasets', [])))
vis = projectables[0]
if vis.attrs.get("sunz_corrected"):
LOG.debug("Sun zen correction already applied")
Expand All @@ -387,7 +387,7 @@ def __call__(self, projectables, **info):
tic = time.time()
LOG.debug("Applying sun zen correction")
coszen = self.coszen.get(key)
if coszen is None and len(projectables) == 1:
if coszen is None and not info.get('optional_datasets'):
# we were not given SZA, generate SZA then calculate cos(SZA)
from pyorbital.astronomy import cos_zen
LOG.debug("Computing sun zenith angles.")
Expand Down
27 changes: 22 additions & 5 deletions satpy/tests/test_composites.py
Expand Up @@ -17,13 +17,15 @@
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Tests for compositors in composites/__init__.py."""

import xarray as xr
import dask.array as da
import dask
import numpy as np
import unittest
from datetime import datetime
from unittest import mock
import unittest

import dask
import dask.array as da
import numpy as np
import pytest
import xarray as xr


class TestMatchDataArrays(unittest.TestCase):
Expand Down Expand Up @@ -233,6 +235,9 @@ def setUp(self):
area = AreaDefinition('test', 'test', 'test',
{'proj': 'merc'}, 2, 2,
(-2000, -2000, 2000, 2000))
bigger_area = AreaDefinition('test', 'test', 'test',
{'proj': 'merc'}, 4, 4,
(-2000, -2000, 2000, 2000))
attrs = {'area': area,
'start_time': datetime(2018, 1, 1, 18),
'modifiers': tuple(),
Expand All @@ -241,6 +246,11 @@ def setUp(self):
attrs=attrs, dims=('y', 'x'),
coords={'y': [0, 1], 'x': [0, 1]})
self.ds1 = ds1
ds2 = xr.DataArray(da.ones((4, 4), chunks=2, dtype=np.float64),
attrs=attrs, dims=('y', 'x'),
coords={'y': [0, 0.5, 1, 1.5], 'x': [0, 0.5, 1, 1.5]})
ds2.attrs['area'] = bigger_area
self.ds2 = ds2
self.sza = xr.DataArray(
np.rad2deg(np.arccos(da.from_array([[0.0149581333, 0.0146694376], [0.0150812684, 0.0147925727]],
chunks=2))),
Expand Down Expand Up @@ -284,6 +294,13 @@ def test_basic_lims_provided(self):
res = comp((self.ds1, self.sza), test_attr='test')
np.testing.assert_allclose(res.values, np.array([[66.853262, 68.168939], [66.30742, 67.601493]]))

def test_imcompatible_areas(self):
"""Test sunz correction on incompatible areas."""
from satpy.composites import SunZenithCorrector, IncompatibleAreas
comp = SunZenithCorrector(name='sza_test', modifiers=tuple(), correction_limit=90)
with pytest.raises(IncompatibleAreas):
comp((self.ds2, self.sza), test_attr='test')


class TestDifferenceCompositor(unittest.TestCase):
"""Test case for the difference compositor."""
Expand Down

0 comments on commit 6c11402

Please sign in to comment.