-
Notifications
You must be signed in to change notification settings - Fork 287
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
Enable solar zenith angle caching for the DayNightCompositor #2105
Conversation
7ef5511
to
e58657d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple changes...and what do you think about tests? Maybe add an RGB case to the existing angles tests?
Yeah, this probably needs some new tests (at least the new helper function). I don't have a huge amount of time right now but can try to add some next week. |
Ok, I think this is done. It didn't actually work the way you had it (something I didn't notice either). The test cases don't have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The self = {'name': 'dn_test', 'optional_prerequisites': [], 'prerequisites': []}
projectables = [<xarray.DataArray 'array-4105b65f4b41e351f1402df7e0f94aca' (bands: 3, y: 2, x: 2)>
dask.array<array, shape=(3, 2, 2),...
Attributes:
test: b
start_time: 2018-01-01 18:00:00
area: <MagicMock id='139787571969568'>]
kwargs = {}
foreground_data = <xarray.DataArray 'array-4105b65f4b41e351f1402df7e0f94aca' (bands: 3, y: 2, x: 2)>
dask.array<array, shape=(3, 2, 2), ...x
Attributes:
test: a
start_time: 2018-01-01 18:00:00
area: <MagicMock id='139787571969568'>
lim_low = 0.08715574274765814, lim_high = 0.03489949670250108
get_cos_sza = <function get_cos_sza at 0x7f22fdc6c790>
def __call__(self, projectables, **kwargs):
"""Generate the composite."""
projectables = self.match_data_arrays(projectables)
# At least one composite is requested.
foreground_data = projectables[0]
lim_low = np.cos(np.deg2rad(self.lim_low))
lim_high = np.cos(np.deg2rad(self.lim_high))
try:
> coszen = np.cos(np.deg2rad(projectables[2 if self.day_night == "day_night" else 1]))
E IndexError: list index out of range
satpy/composites/__init__.py:632: IndexError
During handling of the above exception, another exception occurred:
self = <satpy.tests.test_composites.TestDayNightCompositor testMethod=test_daynight_area>
def test_daynight_area(self):
"""Test compositor both day and night portions when SZA data is not provided."""
from satpy.composites import DayNightCompositor
comp = DayNightCompositor(name='dn_test', day_night="day_night")
> res = comp((self.data_a, self.data_b))
satpy/tests/test_composites.py:351:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
satpy/composites/__init__.py:637: in __call__
coszen = get_cos_sza(foreground_data)
satpy/modifiers/angles.py:369: in get_cos_sza
lons, lats = _get_valid_lonlats(data_arr.attrs["area"], chunks)
satpy/modifiers/angles.py:142: in __call__
arg_hash = _hash_args(*new_args, unhashable_types=self._uncacheable_arg_types)
satpy/modifiers/angles.py:258: in _hash_args
arg_hash.update(json.dumps(tuple(hashable_args)).encode('utf8'))
/usr/share/miniconda3/envs/test-environment/lib/python3.9/json/__init__.py:231: in dumps
return _default_encoder.encode(obj)
/usr/share/miniconda3/envs/test-environment/lib/python3.9/json/encoder.py:199: in encode
chunks = self.iterencode(o, _one_shot=True)
/usr/share/miniconda3/envs/test-environment/lib/python3.9/json/encoder.py:257: in iterencode
return _iterencode(o, 0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <json.encoder.JSONEncoder object at 0x7f231941a700>
o = <MagicMock id='139787571969568'>
def default(self, o):
"""Implement this method in a subclass such that it returns
a serializable object for ``o``, or calls the base implementation
(to raise a ``TypeError``).
For example, to support arbitrary iterators, you could
implement default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
"""
> raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')
E TypeError: Object of type MagicMock is not JSON serializable |
MOCKING!?!?!?! Edit: ...I'll see what I can do. |
Codecov Report
@@ Coverage Diff @@
## main #2105 +/- ##
==========================================
+ Coverage 93.92% 93.95% +0.02%
==========================================
Files 283 283
Lines 42715 42877 +162
==========================================
+ Hits 40120 40285 +165
+ Misses 2595 2592 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Ok with Panu's approval and the simple fix I've made since then, I think this is good to go. Merging... |
At present, the DayNightCompositor does not use the new lat/lon cacheing feature, which slows down processing of this type of composite.
This PR switches the compositor to use the ready-made cache features in
angles.py
. It requires a small modification to theget_cos_sza
in that file to deal with chunking of RGB composites.