-
Notifications
You must be signed in to change notification settings - Fork 391
Changed default CRS for set_extent so it is no longer the geodetic version. #131
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6c4985a
Changed default CRS for set_extent so it is no longer geodetic versio…
esc24 9a1e9e3
Correction to get_extent doctring regarding default CRS.
esc24 8c1cdfd
Changed extents to extent.
esc24 cb1f697
Added tests for GeoAxes.get_extent() and GeoAxes.set_extent().
esc24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+67.7 KB
lib/cartopy/tests/mpl/baseline_images/mpl/test_set_extent/set_extent_wrapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # (C) British Crown Copyright 2011 - 2012, Met Office | ||
| # | ||
| # This file is part of cartopy. | ||
| # | ||
| # cartopy is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the | ||
| # Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # cartopy is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with cartopy. If not, see <http://www.gnu.org/licenses/>. | ||
| import unittest | ||
| import warnings | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| from numpy.testing import assert_array_almost_equal | ||
|
|
||
| import cartopy.crs as ccrs | ||
|
|
||
| class TestGetExtent(unittest.TestCase): | ||
| def test_get_extent(self): | ||
| # Set up known extent around the UK. | ||
| uk = (-12.5, 4., 49., 60.) | ||
| uk_crs = ccrs.Geodetic() | ||
| projection = ccrs.Mollweide() | ||
| ax = plt.axes(projection=projection) | ||
| ax.set_extent(uk, crs=uk_crs) | ||
|
|
||
| # Result of get_extent with no specified coordinate system should be | ||
| # in the projection of the axes (Mollweide in this case). | ||
| assert_array_almost_equal(ax.get_extent(), ax.get_extent(projection)) | ||
|
|
||
| # Obtain the extent in a range of projections and check against | ||
| # expected values. | ||
|
|
||
| # Mollweide | ||
| expected = (-963125.8421709834, 308200.26949471474, | ||
| 5768352.350108459, 6876758.993328802) | ||
| extent = ax.get_extent(ccrs.Mollweide()) | ||
| assert_array_almost_equal(extent, expected) | ||
|
|
||
| # Geodetic (should raise warning, but still give the PlateCarree result). | ||
| expected_plate_carree = (-14.850129, 4.752041, 49., 60.) | ||
| expected = expected_plate_carree | ||
| with warnings.catch_warnings(): | ||
| # Check for warning. | ||
| warnings.simplefilter('error') | ||
| with self.assertRaises(UserWarning): | ||
| ax.get_extent(ccrs.Geodetic()) | ||
| # Check result. | ||
| warnings.simplefilter('ignore') | ||
| extent = ax.get_extent(ccrs.Geodetic()) | ||
| assert_array_almost_equal(extent, expected) | ||
|
|
||
| # PlateCarree | ||
| expected = expected_plate_carree | ||
| extent = ax.get_extent(ccrs.PlateCarree()) | ||
| assert_array_almost_equal(extent, expected) | ||
|
|
||
| # PlateCarree with nonzero central_longitude | ||
| central_longitude = 20 | ||
| expected = (expected_plate_carree[0] - central_longitude, | ||
| expected_plate_carree[1] - central_longitude, | ||
| expected_plate_carree[2], | ||
| expected_plate_carree[3]) | ||
| extent = ax.get_extent(ccrs.PlateCarree(central_longitude)) | ||
| assert_array_almost_equal(extent, expected) | ||
|
|
||
| # NorthPolarStereo | ||
| expected = (-1034046.2256626057, 333263.47741164186, | ||
| -4765889.766015143, -3311994.6422885) | ||
| extent = ax.get_extent(ccrs.NorthPolarStereo()) | ||
| assert_array_almost_equal(extent, expected) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,7 +307,7 @@ def test_pcolormesh_limited_area_wrap(): | |
| ax = plt.subplot(223, projection=ccrs.PlateCarree(180)) | ||
| plt.pcolormesh(x, y, data, transform=rp, cmap='Set1') | ||
| ax.coastlines() | ||
| ax.set_extent([-70, 0, 0, 80]) | ||
| ax.set_extent([-70, 0, 0, 80], ccrs.Geodetic()) | ||
|
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. I just don't agree that this is preferable. 95% of the time, the user will want to define the extent of their map in "lons and lats" not in the native coordinate system. |
||
|
|
||
| ax = plt.subplot(224, projection=rp) | ||
| plt.pcolormesh(xbnds, ybnds, data, transform=rp, cmap='Set1') | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Because this is such a common requirement, I'm tempted to ask to to expose a context manager which has the following syntax:
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.
Note: this does exist on python3: http://docs.python.org/3.3/library/unittest.html#unittest.TestCase.assertWarns