Skip to content

Commit

Permalink
Increase tolerance on cartopy<0.23
Browse files Browse the repository at this point in the history
Bump close existing tolerance inclusively.
  • Loading branch information
dcamron committed Jul 24, 2024
1 parent 046c8c8 commit 6c11dc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 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.248 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
60 changes: 40 additions & 20 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.163 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.159 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.155 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.142 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.114 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.104 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.152 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.055 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 @@ -432,7 +440,8 @@ def test_declarative_additional_layers_plot_options():

@pytest.mark.mpl_image_compare(
remove_text=True,
tolerance=2.74 if version_check('matplotlib<3.8') else 1.91)
tolerance=3.34 if version_check('cartopy<0.23') else
2.74 if version_check('matplotlib<3.8') else 1.91)
@needs_cartopy
def test_declarative_contour_convert_units():
"""Test making a contour plot."""
Expand Down Expand Up @@ -656,7 +665,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.238 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 +693,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.238 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 +773,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 +1052,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.133 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 +1346,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.081 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 +1376,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.075 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 +1438,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 +1678,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.082 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 +1712,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.125 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 +1778,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 Expand Up @@ -1931,7 +1951,7 @@ def test_declarative_region_modifier_zoom_in():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.332)
@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.377)
@needs_cartopy
def test_declarative_region_modifier_zoom_out():
"""Test that '-' suffix on area string properly expands extent of map."""
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.555 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.119 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 6c11dc1

Please sign in to comment.