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

Enable to pass a custom function to Scene.aggregate #2497

Merged
merged 6 commits into from
Jun 26, 2023

Conversation

ghiggi
Copy link
Contributor

@ghiggi ghiggi commented Jun 1, 2023

This small PR adds the option to pass a custom function to Scene.aggregate

  • Closes #xxxx
  • Tests added
  • Fully documented
  • Add your name to AUTHORS.md if not there already

@codecov
Copy link

codecov bot commented Jun 1, 2023

Codecov Report

Merging #2497 (dba604e) into main (3b7a477) will increase coverage by 0.01%.
The diff coverage is 90.47%.

@@            Coverage Diff             @@
##             main    #2497      +/-   ##
==========================================
+ Coverage   94.83%   94.85%   +0.01%     
==========================================
  Files         337      337              
  Lines       49430    49658     +228     
==========================================
+ Hits        46875    47101     +226     
- Misses       2555     2557       +2     
Flag Coverage Δ
behaviourtests 4.41% <9.52%> (-0.02%) ⬇️
unittests 95.47% <90.47%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
satpy/scene.py 93.60% <85.71%> (+0.07%) ⬆️
satpy/tests/scene_tests/test_resampling.py 100.00% <100.00%> (ø)

... and 23 files with indirect coverage changes

@coveralls
Copy link

coveralls commented Jun 1, 2023

Pull Request Test Coverage Report for Build 5346938525

  • 19 of 21 (90.48%) changed or added relevant lines in 2 files are covered.
  • 100 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.008%) to 95.422%

Changes Missing Coverage Covered Lines Changed/Added Lines %
satpy/scene.py 12 14 85.71%
Files with Coverage Reduction New Missed Lines %
satpy/composites/init.py 6 91.24%
satpy/readers/avhrr_l1b_gaclac.py 6 95.68%
satpy/readers/olci_nc.py 11 94.2%
satpy/readers/geocat.py 18 88.82%
satpy/readers/seviri_l1b_native.py 21 86.82%
satpy/readers/nwcsaf_nc.py 38 82.0%
Totals Coverage Status
Change from base Build 5141473420: 0.008%
Covered Lines: 47216
Relevant Lines: 49481

💛 - Coveralls

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

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

Seems simple enough. I had one small change to request. Otherwise, I'm wondering if you could refactor the aggregate method into smaller sub-methods (or external functions) to make CodeScene happy?

satpy/scene.py Outdated Show resolved Hide resolved
@ghiggi
Copy link
Contributor Author

ghiggi commented Jun 1, 2023

Complementary note: this method fails if the source area is a SwathDefinition because the "resolution" can't be inferred if not present as attributes to lons/lats

@ghiggi ghiggi requested a review from djhoese June 1, 2023 12:28
@djhoese djhoese added enhancement code enhancements, features, improvements component:scene labels Jun 1, 2023
satpy/scene.py Outdated Show resolved Hide resolved
satpy/scene.py Outdated Show resolved Hide resolved
@ghiggi ghiggi requested a review from djhoese June 1, 2023 14:14
@ghiggi
Copy link
Contributor Author

ghiggi commented Jun 21, 2023

@mraspaud milestone v0.43.0

@mraspaud mraspaud added this to the v0.43.0 milestone Jun 21, 2023
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.

Thanks for adding this! just a couple of comments inline.

satpy/scene.py Outdated
Comment on lines 44 to 50
def _get_area_resolution(area):
"""Attempt to retrieve resolution from AreaDefinition."""
try:
resolution = max(area.pixel_size_x, area.pixel_size_y)
except AttributeError:
resolution = max(area.lats.resolution, area.lons.resolution)
return resolution
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it should already be present somewhere in pyresample. I think we have a method called geocentric_resolution, can it be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do that but it would break the back compatibility !
For AreaDefinition for example, right now (and in the past) the method is/was using pixel_size (in units of projection coordinates). While geocentric_resolution if I understand correctly would provides the geocentric resolution (in degrees)

Copy link
Member

Choose a reason for hiding this comment

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

You are correct that it is not the same, but I do want to clarify it should be in meters...just not the same meters as the projection. I think, especially since you didn't write this code, that it can stay as is (again, my opinion). I do think the .resolution should be .attrs["resolution"] though. If you have other changes to make maybe you could do that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@djhoese you mean the Scene DataArray .attrs['resolution']? But is this always updated? Also when resampling to new area/swaths? And what if the attribute is missing? I guess we should discuss this on a separate issue and do a separate PR ...

Copy link
Member

Choose a reason for hiding this comment

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

No no, sorry. I mean in the except clause it does area.lats.resolution. If I'm understanding this code area is a SwathDefinition in this except block, .lats is a DataArray, and area.lats.resolution is a shortcut to area.lats.attrs["resolution"]. The .attrs form of accessing this information is the preferred way of doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and likely ready to be merged ;)

satpy/scene.py Outdated Show resolved Hide resolved
satpy/scene.py Outdated Show resolved Hide resolved
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

@mraspaud mraspaud merged commit fcea851 into pytroll:main Jun 26, 2023
@ghiggi ghiggi deleted the feature-custom-aggregation branch June 26, 2023 08:37
@mraspaud mraspaud changed the title Enable to pass a custom function to Scene.aggregate Enable to pass a custom function to Scene.aggregate Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:scene enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants