-
Notifications
You must be signed in to change notification settings - Fork 98
Convert AreaDefinitions to odc geoboxes #545
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
Changes from 9 commits
8f5fe3b
4b02a02
bb4d79c
5e600a1
fcf296b
ec53f26
9381bff
87b2bf1
acff8b9
84a6deb
28c6f80
c043b97
09c35fd
e560f1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,4 @@ dependencies: | |
| - pytest-lazy-fixture | ||
| - importlib-metadata | ||
| - sphinx-reredirects | ||
| - odc-geo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And thanks for using the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for the case where |
||
| """Test conversion from area definition to odc GeoBox.""" | ||
| from odc.geo.geobox import GeoBox | ||
|
|
||
| europe = stere_area | ||
| seviri = create_test_area( | ||
| { | ||
| 'proj': 'geos', | ||
| 'lon_0': 0.0, | ||
| 'a': 6378169.00, | ||
| 'b': 6356583.80, | ||
| 'h': 35785831.00, | ||
| 'units': 'm'}, | ||
| 123, | ||
| 123, | ||
| (-5500000, -5500000, 5500000, 5500000)) | ||
|
|
||
| for area_def in [europe, seviri]: | ||
| geobox = area_def.to_odc_geobox() | ||
|
|
||
| assert isinstance(geobox, GeoBox) | ||
|
|
||
| # Affine coefficiants | ||
| af = geobox.affine | ||
| assert af.a == area_def.pixel_size_x | ||
| assert af.e == -area_def.pixel_size_y | ||
| assert af.xoff == area_def.area_extent[0] | ||
| assert af.yoff == area_def.area_extent[3] | ||
|
|
||
| def test_dump(self, create_test_area): | ||
| """Test exporting area defs.""" | ||
| from io import StringIO | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,16 @@ | |
| 'cf': ['xarray'], | ||
| 'gradient_search': ['shapely'], | ||
| 'xarray_bilinear': ['xarray', 'dask', 'zarr'], | ||
| 'odc-geo': ['odc-geo'], | ||
| 'tests': test_requires} | ||
|
|
||
| all_extras = [] | ||
| for extra_deps in extras_require.values(): | ||
| all_extras.extend(extra_deps) | ||
| extras_require['all'] = list(set(all_extras)) | ||
|
|
||
| setup_requires = ['numpy>=1.10.0', 'cython'] | ||
|
||
|
|
||
| if sys.platform.startswith("win"): | ||
| extra_compile_args = [] | ||
| else: | ||
|
|
||
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
Resolutionclass: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

Resolutionclass. One thing to note is that by default ifResolutionis 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 theGeoBoxthis affects where the "anchor" point (i.e. from where the raster is indexed). This is mostly visible in the affine transformation of theGeoBox. You can also see this in the representation of theGeoBoxas 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).