Skip to content

Commit

Permalink
Increase tolerance on cartopy<0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamron committed Jun 28, 2024
1 parent 046c8c8 commit b4d915e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
4 changes: 3 additions & 1 deletion tests/plots/test_cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

import metpy.plots as mpplots
from metpy.testing import version_check


@pytest.mark.mpl_image_compare(tolerance=0.053, remove_text=True)
Expand Down Expand Up @@ -48,7 +49,8 @@ def test_us_states_defaults(ccrs):
return fig


@pytest.mark.mpl_image_compare(tolerance=0., remove_text=True)
@pytest.mark.mpl_image_compare(tolerance=0.246 if version_check('cartopy<0.23') else 0.,
remove_text=True)
def test_us_states_scales(ccrs):
"""Test the default US States plotting with all scales."""
proj = ccrs.LambertConformal(central_longitude=-85.0, central_latitude=45.0)
Expand Down
55 changes: 37 additions & 18 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def test_declarative_four_dims_error():
pc.draw()


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.09)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.134 if version_check('cartopy<0.23') else 0.09)
@needs_cartopy
def test_declarative_contour():
"""Test making a contour plot."""
Expand Down Expand Up @@ -151,7 +152,8 @@ def test_declarative_titles():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.066)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.126 if version_check('cartopy<0.23') else 0.066)
@needs_cartopy
def test_declarative_smooth_contour():
"""Test making a contour plot using smooth_contour."""
Expand Down Expand Up @@ -180,7 +182,8 @@ def test_declarative_smooth_contour():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.006)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.130 if version_check('cartopy<0.23') else 0.006)
@needs_cartopy
def test_declarative_smooth_contour_calculation():
"""Test making a contour plot using smooth_contour."""
Expand Down Expand Up @@ -222,7 +225,8 @@ def test_declarative_smooth_contour_calculation():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.0038)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.141 if version_check('cartopy<0.23') else 0.0038)
@needs_cartopy
def test_declarative_smooth_contour_order():
"""Test making a contour plot using smooth_contour with tuple."""
Expand Down Expand Up @@ -251,7 +255,8 @@ def test_declarative_smooth_contour_order():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.058)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.098 if version_check('cartopy<0.23') else 0.058)
@needs_cartopy
def test_declarative_figsize():
"""Test having an all float figsize."""
Expand Down Expand Up @@ -279,7 +284,8 @@ def test_declarative_figsize():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.031)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.101 if version_check('cartopy<0.23') else 0.031)
@needs_cartopy
def test_declarative_smooth_field():
"""Test the smoothing of the field with smooth_field trait."""
Expand Down Expand Up @@ -367,7 +373,8 @@ def test_declarative_contour_options():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.009)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.150 if version_check('cartopy<0.23') else 0.009)
@needs_cartopy
def test_declarative_layers_plot_options():
"""Test declarative layer options of edgecolor and linewidth."""
Expand Down Expand Up @@ -397,7 +404,8 @@ def test_declarative_layers_plot_options():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.009)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.051 if version_check('cartopy<0.23') else 0.009)
@needs_cartopy
def test_declarative_additional_layers_plot_options():
"""Test additional declarative layer options of linestyle, zorder, and alpha."""
Expand Down Expand Up @@ -656,7 +664,8 @@ def test_colorfill():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.004)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.237 if version_check('cartopy<0.23') else 0.004)
def test_colorfill_with_image_range(cfeature):
"""Test that we can use ContourFillPlot with image_range bounds."""
data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
Expand All @@ -683,7 +692,9 @@ def test_colorfill_with_image_range(cfeature):


@pytest.mark.mpl_image_compare(
remove_text=True, tolerance=0.004, filename='test_colorfill_with_image_range.png'
remove_text=True,
tolerance=0.237 if version_check('cartopy<0.23') else 0.004,
filename='test_colorfill_with_image_range.png'
)
def test_colorfill_with_normalize_instance_image_range(cfeature):
"""Test that we can use ContourFillPlot with image_range bounds."""
Expand Down Expand Up @@ -761,7 +772,8 @@ def test_colorbar_kwargs(cfeature):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.005)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.370 if version_check('cartopy<0.23') else 0.005)
def test_colorfill_no_colorbar(cfeature):
"""Test that we can use ContourFillPlot with no colorbar."""
data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
Expand Down Expand Up @@ -1039,7 +1051,8 @@ def test_declarative_overlay_projections():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.0094)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.132 if version_check('cartopy<0.23') else 0.0094)
@needs_cartopy
def test_declarative_gridded_scale():
"""Test making a contour plot."""
Expand Down Expand Up @@ -1332,7 +1345,8 @@ def test_plotobs_units_with_formatter(ccrs, pandas_sfc):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.025)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.080 if version_check('cartopy<0.23') else 0.025)
def test_declarative_sfc_obs(ccrs, pandas_sfc):
"""Test making a surface observation plot."""
obs = PlotObs()
Expand Down Expand Up @@ -1361,7 +1375,8 @@ def test_declarative_sfc_obs(ccrs, pandas_sfc):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.074 if version_check('cartopy<0.23') else 0.)
def test_declarative_sfc_obs_args(ccrs, pandas_sfc):
"""Test making a surface observation plot with mpl arguments."""
obs = PlotObs()
Expand Down Expand Up @@ -1422,7 +1437,8 @@ def test_declarative_sfc_text(pandas_sfc):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.081 if version_check('cartopy<0.23') else 0.)
def test_declarative_sfc_obs_changes(ccrs, pandas_sfc):
"""Test making a surface observation plot, changing the field."""
obs = PlotObs()
Expand Down Expand Up @@ -1661,7 +1677,8 @@ def test_attribute_error_station(ccrs, pandas_sfc):
plt.close(pc.figure)


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.081 if version_check('cartopy<0.23') else 0.)
def test_declarative_sfc_obs_change_units(ccrs):
"""Test making a surface observation plot."""
data = parse_metar_file(get_test_data('metar_20190701_1200.txt', as_file_obj=False),
Expand Down Expand Up @@ -1694,7 +1711,8 @@ def test_declarative_sfc_obs_change_units(ccrs):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.0)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=0.124 if version_check('cartopy<0.23') else 0.0)
def test_declarative_multiple_sfc_obs_change_units(ccrs):
"""Test making a surface observation plot."""
data = parse_metar_file(get_test_data('metar_20190701_1200.txt', as_file_obj=False),
Expand Down Expand Up @@ -1759,7 +1777,8 @@ def test_declarative_title_fontsize():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=False, tolerance=0.)
@pytest.mark.mpl_image_compare(remove_text=False,
tolerance=0.951 if version_check('cartopy<0.23') else 0.)
@needs_cartopy
def test_declarative_colorbar_fontsize():
"""Test adjusting the font size of a colorbar."""
Expand Down
6 changes: 4 additions & 2 deletions tests/plots/test_plot_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import matplotlib.pyplot as plt
import pytest

from metpy.testing import version_check

@pytest.mark.mpl_image_compare(tolerance=0.002)

@pytest.mark.mpl_image_compare(tolerance=0.554 if version_check('cartopy<0.23') else 0.002)
def test_uslcc_plotting(ccrs, cfeature):
"""Test plotting the uslcc area with projection."""
from metpy.plots import named_areas
Expand All @@ -27,7 +29,7 @@ def test_uslcc_plotting(ccrs, cfeature):
return fig


@pytest.mark.mpl_image_compare(tolerance=0.)
@pytest.mark.mpl_image_compare(tolerance=0.118 if version_check('cartopy<0.23') else 0.)
def test_au_plotting(ccrs, cfeature):
"""Test plotting the au area with projection."""
from metpy.plots import named_areas
Expand Down

0 comments on commit b4d915e

Please sign in to comment.