-
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
Convert AreaDefinitions to odc geoboxes #545
Conversation
… feat_to_odc_geobox
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #545 +/- ##
==========================================
- Coverage 94.06% 94.05% -0.01%
==========================================
Files 85 85
Lines 13250 13276 +26
==========================================
+ Hits 12463 12487 +24
- Misses 787 789 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Love it! I had some requests, but otherwise I think this is an obvious addition. I'd be curious what @ghiggi's opinion is on this as I'm wondering if we could essentially drop our existing boundary stuff (eventually). That assumes I understand what odc-geo's boxes can do which I may not have a great understanding.
pyresample/geometry.py
Outdated
raise ModuleNotFoundError("Please install 'odc-geo' to use this method.") | ||
|
||
return GeoBox.from_bbox(bbox=self.area_extent, crs=self.crs, | ||
resolution=np.mean([self.pixel_size_x, self.pixel_size_y]), tight=True) |
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 resolution can be a 2 element pair using the Resolution
class:
https://odc-geo.readthedocs.io/en/latest/_api/odc.geo.Resolution.html#odc.geo.Resolution
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 know I can't really remember why I didn't use it but will check and change it eventually.
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 changed it to use the Resolution
class. One thing to note is that by default if Resolution
is given one value it is assumed that the second (y) value is -x. Because in Pyresample resolution values are always positive I added a minus sign in front of the y value to keep the behavior I initially implemented. In the GeoBox
this affects where the "anchor" point (i.e. from where the raster is indexed). This is mostly visible in the affine transformation of the GeoBox
. You can also see this in the representation of the GeoBox
as seen below (top is the implemented behavior, bottom is the behavior when both resolution values are positive; look at the small dot on the boundary).
setup.py
Outdated
all_extras.extend(extra_deps) | ||
extras_require['all'] = list(set(all_extras)) | ||
|
||
setup_requires = ['numpy>=1.10.0', 'cython'] |
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.
This isn't actually used anywhere, plus this kind of thing (setup_requires) should be defined in the pyproject.toml build section.
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.
Good point. I have to admit I just copied it to get the different extra install options working.
@@ -403,6 +403,35 @@ def test_cartopy_crs_latlon_bounds(self, create_test_area): | |||
latlong_crs = area_def.to_cartopy_crs() | |||
np.testing.assert_allclose(latlong_crs.bounds, [-180, 180, -90, 90]) | |||
|
|||
def test_to_odc_geobox(self, stere_area, create_test_area): |
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.
Can we xfail or skip if odc is missing? I think pytest has a decorator specifically for skipping if import fails.
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.
That's a good Idea. I will also add a test for missing odc-geo
since that is not tested yet.
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.
And thanks for using the create_test_area
fixture. It makes my work on Pyresample 2.0 much easier.
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 added a test for the case where odc-geo
is not installed and changed the setup to include it as a requirement for testing. I thought about it and I think the test should not be skipped if odc-geo
is not installed instead odc-geo
should be required for testing as it is now.
Glad that you like it was not sure if it is a valuable addition. I just used it because I was to lazy to create Affine transformations from scratch and was thinking that maybe I can test some stuff for rerprojections and maybe for the html representation. |
Cool feature @BENR0. I never used the odc-geo tool. But from a quick look @djhoese:
BTW I just opened the PR #546 to streamline the boundary extraction |
Sure, but I think that's the point. They're projected bounding boxes.
I would suspect they don't currently support the anti-meridian as that is technically not a valid contiguous space on any CRS. If you have data that crosses the anti-meridian of a CRS then your data can't be represented correctly on that CRS. This is strict and difficult to reconcile in real world applications with data crossing the poles, but it is technically true. I know you have workarounds in your other PRs since we do end up having to deal with it, but I just wanted to point this out. As for using odc-geo in other methods of the geometry objects: no thank you. Not yet. Not unless it is a clear win for doing calculations. No need for the extra dependency. |
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
Not that I expected this to happen in this PR, but we really need to come up with a new pattern for conversion of areas to other things. I'm not sure dumping it all in geometry.py is a good idea. |
Convert
AreaDefinitions
to odc geoboxes (https://odc-geo.readthedocs.io/en/latest/).git diff origin/main **/*py | flake8 --diff