From 36885cc313a27aeb339baafffadedf14cf2f562d Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Fri, 28 Jun 2024 12:32:13 -0600 Subject: [PATCH] Increase tolerance on cartopy<0.23 Bump close existing tolerance inclusively. --- tests/plots/test_cartopy_utils.py | 4 ++- tests/plots/test_declarative.py | 60 ++++++++++++++++++++----------- tests/plots/test_plot_areas.py | 6 ++-- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/tests/plots/test_cartopy_utils.py b/tests/plots/test_cartopy_utils.py index 66328c462d2..1cc864a3683 100644 --- a/tests/plots/test_cartopy_utils.py +++ b/tests/plots/test_cartopy_utils.py @@ -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) @@ -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) diff --git a/tests/plots/test_declarative.py b/tests/plots/test_declarative.py index 99d619f7684..bd2251ceda1 100644 --- a/tests/plots/test_declarative.py +++ b/tests/plots/test_declarative.py @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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)) @@ -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.""" @@ -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)) @@ -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.""" @@ -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() @@ -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() @@ -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() @@ -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), @@ -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), @@ -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.""" @@ -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.""" diff --git a/tests/plots/test_plot_areas.py b/tests/plots/test_plot_areas.py index 71e1e1e82ec..0c3903f8cbc 100644 --- a/tests/plots/test_plot_areas.py +++ b/tests/plots/test_plot_areas.py @@ -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 @@ -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