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

Add 'preference' option to 'get_satpos' utility #2030

Merged
merged 5 commits into from
Feb 24, 2022

Conversation

djhoese
Copy link
Member

@djhoese djhoese commented Feb 20, 2022

As part of the discussion on slack regarding AHI HSD performance and optimizations I've created this PR to allow modifiers and other users hoping to get satellite position information to have control over what precision or quality of data they prefer. This will be useful in the AHI HSD case as the reader can be updated to include a "nominal" satellite position and (hopefully) share calculations of things like sensor zenith/azimuth angles because the satellite position will be the same between bands rather than the "actual" position which differs between bands and even differs between segments of a band.

Related #2029 #2012

  • Closes #xxxx
  • Tests added
  • Fully documented

@djhoese djhoese added the enhancement code enhancements, features, improvements label Feb 20, 2022
@codecov
Copy link

codecov bot commented Feb 20, 2022

Codecov Report

Merging #2030 (21ed4e4) into main (a3fa4c4) will decrease coverage by 0.01%.
The diff coverage is 44.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2030      +/-   ##
==========================================
- Coverage   93.65%   93.63%   -0.02%     
==========================================
  Files         282      282              
  Lines       41878    41880       +2     
==========================================
- Hits        39220    39214       -6     
- Misses       2658     2666       +8     
Flag Coverage Δ
behaviourtests 4.76% <10.71%> (+<0.01%) ⬆️
unittests 94.17% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
satpy/tests/modifier_tests/test_crefl.py 99.48% <ø> (-0.01%) ⬇️
satpy/utils.py 26.61% <16.21%> (-0.17%) ⬇️
satpy/tests/test_utils.py 100.00% <100.00%> (ø)
satpy/_compat.py 68.18% <0.00%> (-6.82%) ⬇️
satpy/tests/writer_tests/test_ninjogeotiff.py 96.49% <0.00%> (-1.35%) ⬇️
satpy/readers/vii_base_nc.py 94.44% <0.00%> (-0.11%) ⬇️
satpy/readers/vii_l1b_nc.py 96.07% <0.00%> (-0.08%) ⬇️
satpy/readers/mviri_l1b_fiduceo_nc.py 100.00% <0.00%> (ø)
satpy/readers/seviri_l1b_native_hdr.py 100.00% <0.00%> (ø)
satpy/tests/reader_tests/test_vii_l1b_nc.py 100.00% <0.00%> (ø)
... and 7 more

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 a3fa4c4...21ed4e4. Read the comment docs.

def get_satpos(dataset):
def get_satpos(
data_arr: xr.DataArray,
preference: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Could this preference be also fetched from the central satpy configuration if not provided?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Sorry I missed this. I commented on slack. This is exactly the idea I had, but I think the preference should be use case specific. Meaning, the config option would be for controlling sensor angle generation and how it uses this versus a global/generic "whenever satellite position is requested prefer 'X'".

Copy link
Member

Choose a reason for hiding this comment

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

I still think there should be a central config for this that can be undefined by default, and still allow this flag to be present. But this is good enough for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not completely against this idea, but I'm not sure what purpose it serves. Users don't typically use get_satpos, only other Satpy components do. Those satpy components (ex. angle generation) should be the things with the config options for the preference.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed on slack, what @mraspaud is going discussing something like a group of configuration parameters or a "profile" where you can say satpy.config.set_group("image_optimizations") and the various time or satellite positions or other parameters would be set to specific values that would be allow for the fastest generation of images. Of course I just made up the name for that parameter group, but hopefully the idea is clear. This would be a big feature and is not part of this PR, but I wanted to mention it here as something that would be affected by this type of configuration grouping.

Copy link
Member

@sfinkens sfinkens left a comment

Choose a reason for hiding this comment

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

Nice work, that's a very useful feature! Two comments:

  1. Looks like this drops support for legacy attributes (satellite_longitude/latitude/altitude). However, there might be some readers around that still provide only the legacy attributes. I know you asked about that but I thought this was about AHI HSD only.
  2. If none of the preferred keys are available and also the fallback is missing, this will fail with a plain KeyError (not your fault, that's the current behaviour). If you have time, I think you could copy the following block from Improve error reporting of get_satpos #1925:
    try:
        return _get_satpos(dataset)
    except KeyError:
        warnings.warn('Failed to get satellite position from orbital '
                      'parameters, using legacy attributes instead.')
        try:
            return _get_satpos_legacy(dataset)
        except KeyError:
            raise KeyError("Unable to determine satellite position. Either"
                           "the reader doesn't provide that information or"
                           "geolocation datasets are not available.")

@djhoese
Copy link
Member Author

djhoese commented Feb 24, 2022

@sfinkens

  1. What if I removed the legacy stuff from the other readers?
  2. Absolutely.

@djhoese
Copy link
Member Author

djhoese commented Feb 24, 2022

@sfinkens So the only two readers I found that use the legacy keys and don't also have orbital_parameters are the scmi reader and the abi_l2_nc reader. I can update those in a separate PR along with removing the usage and mention of the legacy position metadata in other places.

@djhoese
Copy link
Member Author

djhoese commented Feb 24, 2022

@sfinkens Your concerns have been addressed (at least I think so). In order to continue work on other things I'm going to merge this, but if you have any additional issues let me know and I'll make them.

@djhoese djhoese merged commit 09f13d0 into pytroll:main Feb 24, 2022
@djhoese djhoese deleted the feature-satpos-preference branch February 24, 2022 17:58
@sfinkens
Copy link
Member

sfinkens commented Mar 1, 2022

Thanks for removing the legacy position!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants