Skip to content

Commit

Permalink
Parametrize inline gridliner tests
Browse files Browse the repository at this point in the history
Unlike the old `ImageTesting` decorator, pytest-mpl support parametrized
tests. While this does add a bunch of new tests/images, they are all far
smaller than the single test, and can be run in parallel.

Since they are all generated anew, I switched to the new mpl20 style.
Besides the style, I believe this causes the following changes to
gridline locations for inline:

- EuroPP labels are half the tick interval as before
- OSNI labels latitude every 0.5° instead of every 1°

and for inline USA:

- InterruptedGoodeHomolosine labels longitude every 10° instead of
  every 20°
- LambertConformal labels longitude every 10° instead of every 20°
- NorthPolarStereo labels latitude every 5° instead of every 10°
- Robinson labels longitude every 10° instead of every 20°
- Stereographic labels longitude every 10° instead of every 20°

The automatic display of labels has a few small differences in the
inline results, probably due to different Axes size:

- Geostationary labels 20°W and 40°E instead of 0°
- LambertAzimuthalEqualArea also labels 30°N/30°S somehow
- LambertConformal also labels the inner 60°W
- NearsidePerspective labels 40°E instead of 60°E
- Orthographic also labels 0° longitude
- OSGB also labels 6°W and 2°W on the top, and 4°W on the bottom
- Robinson also labels 60°W

For the inline USA results, there are fewer differences:

- AzimuthalEquidistant also labels 60°N, but somewhat poorly
- EuroPP, OSGB, and OSNI are skipped since their extent is locked
- Geostationary also labels 60°W on the bottom
- Gnomonic also labels 68°W
- NearsidePerspective also labels 60°W on the bottom
- Orthographic also labels 70°W on the bottom
  • Loading branch information
QuLogic committed Oct 7, 2021
1 parent f187916 commit 8c4469a
Show file tree
Hide file tree
Showing 46 changed files with 37 additions and 45 deletions.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 37 additions & 45 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
LATITUDE_FORMATTER, LONGITUDE_FORMATTER,
classic_locator, classic_formatter)


TEST_PROJS = [
ccrs.PlateCarree,
ccrs.AlbersEqualArea,
Expand All @@ -30,21 +31,21 @@
ccrs.Robinson,
ccrs.Sinusoidal,
ccrs.Stereographic,
(ccrs.InterruptedGoodeHomolosine, dict(emphasis='land')),
(ccrs.RotatedPole,
dict(pole_longitude=180.0,
pole_latitude=36.0,
central_rotated_longitude=-106.0,
globe=ccrs.Globe(semimajor_axis=6370000,
semiminor_axis=6370000))),
(ccrs.OSGB, dict(approx=False)),
pytest.param((ccrs.InterruptedGoodeHomolosine, dict(emphasis='land')),
id='InterruptedGoodeHomolosine'),
pytest.param(
(ccrs.RotatedPole,
dict(pole_longitude=180.0, pole_latitude=36.0,
central_rotated_longitude=-106.0)),
id='RotatedPole'),
pytest.param((ccrs.OSGB, dict(approx=False)), id='OSGB'),
ccrs.EuroPP,
ccrs.Geostationary,
ccrs.NearsidePerspective,
ccrs.Gnomonic,
ccrs.LambertAzimuthalEqualArea,
ccrs.NorthPolarStereo,
(ccrs.OSNI, dict(approx=False)),
pytest.param((ccrs.OSNI, dict(approx=False)), id='OSNI'),
ccrs.SouthPolarStereo,
]

Expand Down Expand Up @@ -125,7 +126,6 @@ def test_gridliner_specified_lines():
# The tolerance on these tests are particularly high because of the high number
# of text objects. A new testing strategy is needed for this kind of test.
grid_label_tol = 3.9
grid_label_inline_tol = grid_label_inline_usa_tol = 10.5


@pytest.mark.skipif(geos_version == (3, 9, 0), reason="GEOS intersection bug")
Expand Down Expand Up @@ -251,50 +251,42 @@ def test_grid_labels_tight():

@pytest.mark.skipif(geos_version == (3, 9, 0), reason="GEOS intersection bug")
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='gridliner_labels_inline.png',
tolerance=grid_label_inline_tol)
def test_grid_labels_inline():
fig = plt.figure(figsize=(35, 35))
for i, proj in enumerate(TEST_PROJS, 1):
if isinstance(proj, tuple):
proj, kwargs = proj
else:
kwargs = {}
ax = fig.add_subplot(7, 4, i, projection=proj(**kwargs))
ax.gridlines(draw_labels=True, auto_inline=True)
ax.coastlines(resolution="110m")
ax.set_title(proj, y=1.075)
fig.subplots_adjust(wspace=0.35, hspace=0.35)
@pytest.mark.parametrize('proj', TEST_PROJS)
@pytest.mark.mpl_image_compare(style='mpl20')
def test_grid_labels_inline(proj):
fig = plt.figure()
if isinstance(proj, tuple):
proj, kwargs = proj
else:
kwargs = {}
ax = fig.add_subplot(projection=proj(**kwargs))
ax.gridlines(draw_labels=True, auto_inline=True)
ax.coastlines(resolution="110m")
return fig


@pytest.mark.skipif(geos_version == (3, 9, 0), reason="GEOS intersection bug")
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='gridliner_labels_inline_usa.png',
tolerance=grid_label_inline_usa_tol)
def test_grid_labels_inline_usa():
print(plt.get_backend())
@pytest.mark.parametrize('proj', TEST_PROJS)
@pytest.mark.mpl_image_compare(style='mpl20')
def test_grid_labels_inline_usa(proj):
top = 49.3457868 # north lat
left = -124.7844079 # west long
right = -66.9513812 # east long
bottom = 24.7433195 # south lat
fig = plt.figure(figsize=(35, 35))
for i, proj in enumerate(TEST_PROJS, 1):
if isinstance(proj, tuple):
proj, kwargs = proj
else:
kwargs = {}
ax = fig.add_subplot(7, 4, i, projection=proj(**kwargs))
try:
ax.set_extent([left, right, bottom, top],
crs=ccrs.PlateCarree())
except Exception:
pass
ax.set_title(proj, y=1.075)
ax.gridlines(draw_labels=True, auto_inline=True, clip_on=True)
ax.coastlines(resolution="110m")

fig.subplots_adjust(wspace=0.35, hspace=0.35)
fig = plt.figure()
if isinstance(proj, tuple):
proj, kwargs = proj
else:
kwargs = {}
ax = fig.add_subplot(projection=proj(**kwargs))
try:
ax.set_extent([left, right, bottom, top],
crs=ccrs.PlateCarree())
except Exception:
pytest.skip('Projection does not support changing extent')
ax.gridlines(draw_labels=True, auto_inline=True, clip_on=True)
ax.coastlines(resolution="110m")
return fig


Expand Down

0 comments on commit 8c4469a

Please sign in to comment.