-
Notifications
You must be signed in to change notification settings - Fork 94
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
Allow cropping non-geos areas #516
Conversation
@ameraner you might want to have a look at this also |
Codecov Report
@@ Coverage Diff @@
## main #516 +/- ##
==========================================
- Coverage 94.34% 94.25% -0.10%
==========================================
Files 82 82
Lines 13026 13030 +4
==========================================
- Hits 12290 12282 -8
- Misses 736 748 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
|
If I'm not mistaken this will mean that |
Yep, this NotImplementedError handling here: |
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, thank you for "unlocking" this useful feature! I left just a clarification question.
On a side note, the code for SwathDef data now falls into here
pyresample/pyresample/geometry.py
Line 2597 in 4e245a9
area_boundary = AreaDefBoundary(area_to_cover, 100) |
pyresample/pyresample/boundary.py
Lines 119 to 131 in 3fa9529
class AreaDefBoundary(AreaBoundary): | |
"""Boundaries for area definitions (pyresample).""" | |
def __init__(self, area, frequency=1): | |
lons, lats = area.get_bbox_lonlats() | |
warnings.warn("'AreaDefBoundary' will be removed in the future. " + | |
"Use the Swath/AreaDefinition 'boundary' method instead!.", | |
PendingDeprecationWarning, stacklevel=2) | |
AreaBoundary.__init__(self, | |
*zip(lons, lats)) | |
if frequency != 1: | |
self.decimate(frequency) |
pyresample/geometry.py
Outdated
"equal.") | ||
|
||
data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self)) | ||
data_boundary = self.boundary(frequency=100) |
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.
what is the rationale for choosing 100
here? (we also hardcode it a bit later
pyresample/pyresample/geometry.py
Line 2597 in 4e245a9
area_boundary = AreaDefBoundary(area_to_cover, 100) |
frequency
here pyresample/pyresample/geometry.py
Lines 1559 to 1569 in 4e245a9
def _get_geo_boundary_sides(self, frequency=None): | |
"""Retrieve the boundary sides list for geostationary projections.""" | |
# Define default frequency | |
if frequency is None: | |
frequency = 50 | |
# Ensure at least 4 points are used | |
if frequency < 4: | |
frequency = 4 | |
# Ensure an even number of vertices for side creation | |
if (frequency % 2) != 0: | |
frequency = frequency + 1 |
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.
We set that default just to restrict the number of vertices (several thousands)... otherwise the polygon intersection would takes too long
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.
Yes, we want to keep the number of vertices low to speed up the process.
So maybe we should check that the it is an areadef not swathdef here? or should that be done in satpy to keeps things cleaner here? |
Oh I'm wrong. There is an AreaDefinition check at the top of the method. This is probably good then. |
@mraspaud: FYI there are several edge cases where this method currently fails:
If you implement |
pyresample/geometry.py
Outdated
data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self)) | ||
data_boundary = self.boundary(frequency=100) | ||
else: | ||
data_boundary = Boundary(*get_geostationary_bounding_box_in_lonlats(self)) |
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.
If we add/call get_geostationary_bounding_box_in_lonlats
in https://github.com/mraspaud/pyresample/blob/4e245a906bf3aeff072f6b61febdd1df298fb425/pyresample/geometry.py#L299 get_bbox_lonlats
when is geostationary you can simplify all the if_else conditions here just do self.boundary()
with a sensible frequency defaults ...
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.
Here below:
AreaDefBoundary(area_to_cover, 100)
fails if area_to_cover
is SwathDefinition
.
Maybe use area_to_cover.boundary()
also here in all cases (with sensible frequency defaults)
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.
I think this simplification is better suited for another PR
I can't see it, could you point me to it please? |
Here: pyresample/pyresample/geometry.py Lines 2570 to 2571 in 3fa9529
|
Hhhmmm maybe I should have merged this before my big config PR. Sorry, but I've caused some conflicts. |
Fixed. |
@djhoese please review my two last commits to see if you agree with the refactoring I made. This refactoring took me some time because I found a bug/inconsistency in the usage of the |
I remember I noticed such inconsistencies already a while ago. For GEO areas is the total number of vertices, while for swath and other areas is the number of steps on each boundary side right? I personally would really like to have this as the number of vertices per boundary side, and allow to specify a tuple (y,x) or (x,y) instead of a single value for all dimensions. I also remember somewhat that quite ago, by using the step approach, we were discarding boundary corners values, but I think this was fixed by one of mine or your PR @mraspaud. |
@ghiggi I think both approaches are valid, the usage just depends on what the user needs at that point. in #526 I have now just replaced |
Indeed, this is now fixed. |
@mraspaud I think I understand the last 2 commits. I assume the main motivation was to:
So if that is true then 👍 from me. |
git diff origin/main **/*py | flake8 --diff