Skip to content

Commit

Permalink
Update get_observer_look calls in VIIRS compositor
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Oct 23, 2019
1 parent 39c8f0e commit 71e2955
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
8 changes: 5 additions & 3 deletions satpy/composites/viirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from satpy.composites import CompositeBase, GenericCompositor
from satpy.config import get_environ_ancpath
from satpy.dataset import combine_metadata
from satpy.utils import get_satpos

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -156,10 +157,11 @@ def get_angles(self, vis):
suna = get_alt_az(vis.attrs['start_time'], lons, lats)[1]
suna = np.rad2deg(suna)
sunz = sun_zenith_angle(vis.attrs['start_time'], lons, lats)
sat_lon, sat_lat, sat_alt = get_satpos(vis)
sata, satel = get_observer_look(
vis.attrs['satellite_longitude'],
vis.attrs['satellite_latitude'],
vis.attrs['satellite_altitude'],
sat_lon,
sat_lat,
sat_alt / 1000.0, # km
vis.attrs['start_time'],
lons, lats, 0)
satz = 90 - satel
Expand Down
48 changes: 46 additions & 2 deletions satpy/tests/compositor_tests/test_viirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import unittest2 as unittest
else:
import unittest
try:
from unittest import mock
except ImportError:
import mock


class TestVIIRSComposites(unittest.TestCase):
Expand Down Expand Up @@ -282,7 +286,7 @@ def test_reflectance_corrector_abi(self):
c01 = xr.DataArray(dnb,
dims=('y', 'x'),
attrs={'satellite_longitude': -89.5, 'satellite_latitude': 0.0,
'satellite_altitude': 35786.0234375, 'platform_name': 'GOES-16',
'satellite_altitude': 35786023.4375, 'platform_name': 'GOES-16',
'calibration': 'reflectance', 'units': '%', 'wavelength': (0.45, 0.47, 0.49),
'name': 'C01', 'resolution': 1000, 'sensor': 'abi',
'start_time': '2017-09-20 17:30:40.800000', 'end_time': '2017-09-20 17:41:17.500000',
Expand All @@ -293,7 +297,7 @@ def test_reflectance_corrector_abi(self):
self.assertIsInstance(res.data, da.Array)
self.assertEqual(res.attrs['satellite_longitude'], -89.5)
self.assertEqual(res.attrs['satellite_latitude'], 0.0)
self.assertEqual(res.attrs['satellite_altitude'], 35786.0234375)
self.assertEqual(res.attrs['satellite_altitude'], 35786023.4375)
self.assertEqual(res.attrs['modifiers'], ('sunz_corrected', 'rayleigh_corrected_crefl',))
self.assertEqual(res.attrs['platform_name'], 'GOES-16')
self.assertEqual(res.attrs['calibration'], 'reflectance')
Expand Down Expand Up @@ -474,6 +478,46 @@ def make_xarray(self, name, calibration, wavelength=None, modifiers=None, resolu
np.testing.assert_allclose(unique, [24.641586, 50.431692, 69.315375])


class ViirsReflectanceCorrectorTest(unittest.TestCase):
def setUp(self):
"""Patch in-class imports."""
self.astronomy = mock.MagicMock()
self.orbital = mock.MagicMock()
modules = {
'pyorbital.astronomy': self.astronomy,
'pyorbital.orbital': self.orbital,
}
self.module_patcher = mock.patch.dict('sys.modules', modules)
self.module_patcher.start()

def tearDown(self):
"""Unpatch in-class imports."""
self.module_patcher.stop()

@mock.patch('satpy.composites.viirs.get_satpos')
def test_get_angles(self, get_satpos):
"""Test sun and satellite angle calculation."""
from satpy.composites.viirs import ReflectanceCorrector

# Patch methods
get_satpos.return_value = 'sat_lon', 'sat_lat', 12345678
self.orbital.get_observer_look.return_value = 0, 0
self.astronomy.get_alt_az.return_value = 0, 0
area = mock.MagicMock()
area.get_lonlats_dask.return_value = 'lons', 'lats'
vis = mock.MagicMock(attrs={'area': area,
'start_time': 'start_time'})

# Compute angles
psp = ReflectanceCorrector(name='dummy')
psp.get_angles(vis)

# Check arguments of get_orbserver_look() call, especially the altitude
# unit conversion from meters to kilometers
self.orbital.get_observer_look.assert_called_with(
'sat_lon', 'sat_lat', 12345.678, 'start_time', 'lons', 'lats', 0)


def suite():
"""Create test suite for test_ahi."""
loader = unittest.TestLoader()
Expand Down

0 comments on commit 71e2955

Please sign in to comment.