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 a function to join/enclose areas. #306

Merged
merged 10 commits into from
Mar 12, 2021

Conversation

gerritholl
Copy link
Collaborator

Add a function to calculate an area enclosing one or more other areas.

Add a function to calculate an area enclosing one or more other areas.
@ghost
Copy link

ghost commented Oct 22, 2020

Congratulations 🎉. DeepCode analyzed your code in 2.783 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

I disagree with deepcodes suggestion.  Explicit is better than implicit.
PEP 8 does NOT recommend against ``if len(x) == 0``, it recommends
against ``if not len(x)``.  According to "Explicit is better than
implicit", ``if len(x) == 0`` should be preferable and clearer.
However, I will adapt it anyway as deepcode is the boss here?
@gerritholl
Copy link
Collaborator Author

gerritholl commented Oct 22, 2020

The AppVeyor build failure appears unrelated to this PR.

@djhoese
Copy link
Member

djhoese commented Oct 22, 2020

This reminds me of gdal_merge.py, maybe merge is another word for this functionality?

@djhoese
Copy link
Member

djhoese commented Oct 22, 2020

Also what are your thoughts on this being a method on the AreaDefinition itself? We could even overload the __add__ method so you could do area1 + area2 + area3 and get the enclosing area.

@gerritholl
Copy link
Collaborator Author

Merge could be another word. I chose enclose because the resulting area includes not only the area covered by the input areas, but also the area in-between. I borrowed this word from the portion library.

I'm open to add it as a classmethod/constructor on the AreaDefinition, but I'm not sure about overloading + because I'm not sure the rules usually associated with addition necessarily hold here. For example, for regular addition, if a + b + c == a + c, then a + b == a. This does not hold for merging or enclosing areas.

@djhoese
Copy link
Member

djhoese commented Oct 22, 2020

Good points. Maybe |, but regardless this is "extra" and not something that needs to be done.

@gerritholl
Copy link
Collaborator Author

| is like joining sets, which also doesn't really hold, because A | B in sets should only include what is in either A or B, but an enclosure may include areas in neither A nor B. I would reserve those operators for other operations which might be more appropriate in the future (for example, returning a StackedAreaDefinition).

@gerritholl
Copy link
Collaborator Author

If Python had range literals that would be an appropriate syntax for this. Wild idea: create a special object enc (or named otherwise) which overloads slice syntax: enc[A:B] producing an AreaDefinition that is the enclosure of A and B. ☺

@djhoese
Copy link
Member

djhoese commented Oct 22, 2020

Alright, fine. I suppose the | doesn't completely line up with set operations. I was more thinking the "opposite" of an intersection (&) where the result would be only the overlapping portions of the image.

I wonder if we can or should come up with notation for these types of operations for a pyresample 2.0 kind of interface.

@mraspaud
Copy link
Member

How about union vs intersection for clarity?

@gerritholl
Copy link
Collaborator Author

@mraspaud The enclosure is neither a union nor an intersection. It's the geo-2d equivalent of what pyinterval calls the enclosure. The union {2, 4} | {6, 8} does not include 5, but if we have the intervals (2, 4] and (6, 8], then their span (2, 8] does include 5. This is the 2-dimensional equivalent of such a span/range/enclosure.

Any actual union or intersection function would either need to be very restrictive on its inputs (such as combine_area_extents_vertical), or (allow to) return a StackedAreaDefinition, or we would need to allow for non-rectangular and even non-contiguous areas. The latter option would seem quite involved.

@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #306 (bdb6ccb) into master (3869ce8) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   92.97%   92.99%   +0.02%     
==========================================
  Files          48       48              
  Lines        9764     9798      +34     
==========================================
+ Hits         9078     9112      +34     
  Misses        686      686              
Flag Coverage Δ
unittests 92.99% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
pyresample/geometry.py 85.32% <100.00%> (+0.22%) ⬆️
pyresample/test/test_geometry.py 98.49% <100.00%> (+0.02%) ⬆️

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 3869ce8...bdb6ccb. Read the comment docs.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 92.66% when pulling 25542c5 on gerritholl:area-join-utility into bbd8054 on pytroll:master.

@coveralls
Copy link

coveralls commented Oct 28, 2020

Coverage Status

Coverage increased (+0.02%) to 92.988% when pulling bdb6ccb on gerritholl:area-join-utility into 3869ce8 on pytroll:master.

Copy link
Member

@pnuu pnuu left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

Small request to use CRS. Otherwise for the name, I found this https://en.wikipedia.org/wiki/Minimum_bounding_box

So enclosing is definitely the right concept. However, should a function name use a verb? Or indicate an action? Something like "enclose_areas" or "enclosed_area" or "enclosing_area_box" (nah maybe not this one). I suppose "area_enclosure" works, I'm just worried I'm not going to find it later. Should something be added to the documentation? I'm not sure where given the current (terrible) organization of the sphinx docs.


return create_area_def(
area_id=area_id,
projection=first.proj_dict,
Copy link
Member

Choose a reason for hiding this comment

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

After #332, this should be changed to .crs. Actually, it could be done now and should still work. Passing PROJ dicts in is fine, using them after is not. Ah you also use proj_dict below to get the units. This shouldn't be necessary as create_area_def should determine the units from the CRS information.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I change first.proj_dict to first.crs the test fails with TypeError: Wrong type for projection: <class 'pyproj.crs.crs.CRS'>. Expected dict or string. in _get_proj_data, which verifies that the projection is either a dict or a string.

Copy link
Member

Choose a reason for hiding this comment

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

🤔 I think in #332 that should work. Once some of my more recent PRs are merged maybe we can test this idea again.

Copy link
Collaborator Author

@gerritholl gerritholl Mar 10, 2021

Choose a reason for hiding this comment

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

Should I wait for merger of #332 and then adapt the code here?

Copy link
Member

Choose a reason for hiding this comment

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

Merged just now. If you have the time to merge master into this PR and test some things that'd be great. Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced proj_dict by crs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed name to enclose_areas.

@gerritholl gerritholl requested a review from djhoese March 12, 2021 13:39
Remove duplicate "import pytest" in test_geometry.py.
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, nice feature!

@mraspaud mraspaud merged commit 6d2e8bb into pytroll:master Mar 12, 2021
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.

None yet

5 participants