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

Fix angle generation not working for StackedAreaDefinitions #1946

Merged
merged 5 commits into from
Dec 17, 2021

Conversation

djhoese
Copy link
Member

@djhoese djhoese commented Dec 17, 2021

The optional caching functionality of the angle generation does not work for geometry types that can't be serialized. This logic was able to serialize StackedAreaDefinitions but was only looking for AreaDefinitions. This PR makes it so StackedAreaDefinitions are also cache-able.

  File "/home/a001673/usr/src/satpy/satpy/modifiers/angles.py", line 220, in _hash_args
    arg_hash.update(json.dumps(tuple(hashable_args)).encode('utf8'))
  File "/home/a001673/mambaforge/envs/satpy-3.10/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/home/a001673/mambaforge/envs/satpy-3.10/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/a001673/mambaforge/envs/satpy-3.10/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/a001673/mambaforge/envs/satpy-3.10/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type StackedAreaDefinition is not JSON serializable
  • Tests added
  • Fully documented

@djhoese
Copy link
Member Author

djhoese commented Dec 17, 2021

@mraspaud I could/should update the configuration documentation about how SwathDefinitions and StackedAreaDefinitions are not cache-able, but maybe StackedAreaDefinition could be updated in pyresample to combine the hashes of its sub-areas to generate its own hash?

@djhoese
Copy link
Member Author

djhoese commented Dec 17, 2021

Oh maybe that is already done. Let me check.

@djhoese
Copy link
Member Author

djhoese commented Dec 17, 2021

Done. Fixed it so StackedAreaDefinitions can be hashed and cached in the angle generation.

@codecov
Copy link

codecov bot commented Dec 17, 2021

Codecov Report

Merging #1946 (482b9e3) into main (2067358) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1946   +/-   ##
=======================================
  Coverage   93.53%   93.53%           
=======================================
  Files         279      279           
  Lines       41276    41317   +41     
=======================================
+ Hits        38606    38647   +41     
  Misses       2670     2670           
Flag Coverage Δ
behaviourtests 4.77% <6.09%> (+<0.01%) ⬆️
unittests 94.07% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
satpy/modifiers/angles.py 96.68% <100.00%> (+0.03%) ⬆️
satpy/tests/test_modifiers.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2067358...482b9e3. Read the comment docs.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a minor styling comment. Thanks for taking the time to clean up a bit also!

Another think (that doesn't need to be adressed in this PR): could _hash_args be replaces with dask's tokenize? otherwise I'm wondering if a try/except would be more future-proof than the series of isinstance checks.

@djhoese
Copy link
Member Author

djhoese commented Dec 17, 2021

Regarding tokenize, I think it could be, but we may have to look into how it handles object types that it doesn't understand. Meaning, does it do hash(obj) or does it just not hash them or something else. I think we can register new types with the tokenize function in dask if we have to.

Regarding a try/except, that would be nice but I'm not sure how to do it cleanly because we are optimistically running hash(obj) if a geometry object otherwise we just tell json to serialize the object which could be containers. I can't put a hash(obj) in a try/except because it would succeed for most objects.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 93.999% when pulling 482b9e3 on djhoese:bugfix-angles-stackedarea into 2067358 on pytroll:main.

@djhoese djhoese merged commit af74ae0 into pytroll:main Dec 17, 2021
@djhoese djhoese deleted the bugfix-angles-stackedarea branch December 17, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants