diff --git a/ci/extra_requirements.txt b/ci/extra_requirements.txt index d0bdb81369..154dd75d69 100644 --- a/ci/extra_requirements.txt +++ b/ci/extra_requirements.txt @@ -1,3 +1,3 @@ -cartopy==0.22.0 +cartopy==0.23.0 dask==2024.7.1 shapely==2.0.5 diff --git a/src/metpy/testing.py b/src/metpy/testing.py index a46a5ea805..46f62805fd 100644 --- a/src/metpy/testing.py +++ b/src/metpy/testing.py @@ -9,7 +9,7 @@ """ import contextlib import functools -from importlib.metadata import requires, version +from importlib.metadata import PackageNotFoundError, requires, version import operator as op import re @@ -55,7 +55,12 @@ def version_check(version_spec): metadata_spec = _get_metadata_spec(module_name) _, _, minimum_version_number = _parse_version_spec(metadata_spec) - installed_version = Version(version(module_name)) + try: + installed_version = Version(version(module_name)) + except PackageNotFoundError: + # Package not installed considered false condition for spec + return False + specified_version = Version(version_number) minimum_version = Version(minimum_version_number) diff --git a/tests/plots/baseline/test_au_plotting.png b/tests/plots/baseline/test_au_plotting.png index 9482df16ed..3eb0a6c819 100644 Binary files a/tests/plots/baseline/test_au_plotting.png and b/tests/plots/baseline/test_au_plotting.png differ diff --git a/tests/plots/baseline/test_colorfill_no_colorbar.png b/tests/plots/baseline/test_colorfill_no_colorbar.png index 4ad1399db1..32d257b0a6 100644 Binary files a/tests/plots/baseline/test_colorfill_no_colorbar.png and b/tests/plots/baseline/test_colorfill_no_colorbar.png differ diff --git a/tests/plots/baseline/test_colorfill_with_image_range.png b/tests/plots/baseline/test_colorfill_with_image_range.png index e88380af7d..a51da521cf 100644 Binary files a/tests/plots/baseline/test_colorfill_with_image_range.png and b/tests/plots/baseline/test_colorfill_with_image_range.png differ diff --git a/tests/plots/baseline/test_declarative_additional_layers_plot_options.png b/tests/plots/baseline/test_declarative_additional_layers_plot_options.png index 5f6deadf56..066d1e1865 100644 Binary files a/tests/plots/baseline/test_declarative_additional_layers_plot_options.png and b/tests/plots/baseline/test_declarative_additional_layers_plot_options.png differ diff --git a/tests/plots/baseline/test_declarative_barb_gfs.png b/tests/plots/baseline/test_declarative_barb_gfs.png index 40aa33185c..143adf3e45 100644 Binary files a/tests/plots/baseline/test_declarative_barb_gfs.png and b/tests/plots/baseline/test_declarative_barb_gfs.png differ diff --git a/tests/plots/baseline/test_declarative_barb_gfs_knots.png b/tests/plots/baseline/test_declarative_barb_gfs_knots.png index a21c640e99..2c1af561ec 100644 Binary files a/tests/plots/baseline/test_declarative_barb_gfs_knots.png and b/tests/plots/baseline/test_declarative_barb_gfs_knots.png differ diff --git a/tests/plots/baseline/test_declarative_colorbar_fontsize.png b/tests/plots/baseline/test_declarative_colorbar_fontsize.png index 0ce9d419b7..75a94ca188 100644 Binary files a/tests/plots/baseline/test_declarative_colorbar_fontsize.png and b/tests/plots/baseline/test_declarative_colorbar_fontsize.png differ diff --git a/tests/plots/baseline/test_declarative_contour.png b/tests/plots/baseline/test_declarative_contour.png index c3eebe6fba..1d88789801 100644 Binary files a/tests/plots/baseline/test_declarative_contour.png and b/tests/plots/baseline/test_declarative_contour.png differ diff --git a/tests/plots/baseline/test_declarative_contour_convert_units.png b/tests/plots/baseline/test_declarative_contour_convert_units.png index 9674f0bc63..fbe1aa4c42 100644 Binary files a/tests/plots/baseline/test_declarative_contour_convert_units.png and b/tests/plots/baseline/test_declarative_contour_convert_units.png differ diff --git a/tests/plots/baseline/test_declarative_contour_options.png b/tests/plots/baseline/test_declarative_contour_options.png index 9c819ce0f6..86667e72c1 100644 Binary files a/tests/plots/baseline/test_declarative_contour_options.png and b/tests/plots/baseline/test_declarative_contour_options.png differ diff --git a/tests/plots/baseline/test_declarative_figsize.png b/tests/plots/baseline/test_declarative_figsize.png index fbd85e7551..f4a7d181c5 100644 Binary files a/tests/plots/baseline/test_declarative_figsize.png and b/tests/plots/baseline/test_declarative_figsize.png differ diff --git a/tests/plots/baseline/test_declarative_gridded_scale.png b/tests/plots/baseline/test_declarative_gridded_scale.png index 70781118c6..25cefa83be 100644 Binary files a/tests/plots/baseline/test_declarative_gridded_scale.png and b/tests/plots/baseline/test_declarative_gridded_scale.png differ diff --git a/tests/plots/baseline/test_declarative_layers_plot_options.png b/tests/plots/baseline/test_declarative_layers_plot_options.png index f40a6e24ea..2a5d63f9b2 100644 Binary files a/tests/plots/baseline/test_declarative_layers_plot_options.png and b/tests/plots/baseline/test_declarative_layers_plot_options.png differ diff --git a/tests/plots/baseline/test_declarative_multiple_sfc_obs_change_units.png b/tests/plots/baseline/test_declarative_multiple_sfc_obs_change_units.png index 79386be01d..199b79ee5d 100644 Binary files a/tests/plots/baseline/test_declarative_multiple_sfc_obs_change_units.png and b/tests/plots/baseline/test_declarative_multiple_sfc_obs_change_units.png differ diff --git a/tests/plots/baseline/test_declarative_region_modifier_zoom_out.png b/tests/plots/baseline/test_declarative_region_modifier_zoom_out.png index 49fcc6a2c1..c3197fce60 100644 Binary files a/tests/plots/baseline/test_declarative_region_modifier_zoom_out.png and b/tests/plots/baseline/test_declarative_region_modifier_zoom_out.png differ diff --git a/tests/plots/baseline/test_declarative_sfc_obs.png b/tests/plots/baseline/test_declarative_sfc_obs.png index 1ccac8450e..1f6178006e 100644 Binary files a/tests/plots/baseline/test_declarative_sfc_obs.png and b/tests/plots/baseline/test_declarative_sfc_obs.png differ diff --git a/tests/plots/baseline/test_declarative_sfc_obs_args.png b/tests/plots/baseline/test_declarative_sfc_obs_args.png index b4b74e9df7..9fad66b598 100644 Binary files a/tests/plots/baseline/test_declarative_sfc_obs_args.png and b/tests/plots/baseline/test_declarative_sfc_obs_args.png differ diff --git a/tests/plots/baseline/test_declarative_sfc_obs_change_units.png b/tests/plots/baseline/test_declarative_sfc_obs_change_units.png index cb35fd6811..b975ef13cf 100644 Binary files a/tests/plots/baseline/test_declarative_sfc_obs_change_units.png and b/tests/plots/baseline/test_declarative_sfc_obs_change_units.png differ diff --git a/tests/plots/baseline/test_declarative_sfc_obs_changes.png b/tests/plots/baseline/test_declarative_sfc_obs_changes.png index 3743446613..b15e7fe5db 100644 Binary files a/tests/plots/baseline/test_declarative_sfc_obs_changes.png and b/tests/plots/baseline/test_declarative_sfc_obs_changes.png differ diff --git a/tests/plots/baseline/test_declarative_smooth_contour.png b/tests/plots/baseline/test_declarative_smooth_contour.png index 42a69bc10d..2d6406d4d1 100644 Binary files a/tests/plots/baseline/test_declarative_smooth_contour.png and b/tests/plots/baseline/test_declarative_smooth_contour.png differ diff --git a/tests/plots/baseline/test_declarative_smooth_contour_calculation.png b/tests/plots/baseline/test_declarative_smooth_contour_calculation.png index 448162c0f9..aa09ebbfad 100644 Binary files a/tests/plots/baseline/test_declarative_smooth_contour_calculation.png and b/tests/plots/baseline/test_declarative_smooth_contour_calculation.png differ diff --git a/tests/plots/baseline/test_declarative_smooth_contour_order.png b/tests/plots/baseline/test_declarative_smooth_contour_order.png index fa32a930ce..7618ebeb3e 100644 Binary files a/tests/plots/baseline/test_declarative_smooth_contour_order.png and b/tests/plots/baseline/test_declarative_smooth_contour_order.png differ diff --git a/tests/plots/baseline/test_declarative_smooth_field.png b/tests/plots/baseline/test_declarative_smooth_field.png index 7e52df2d2c..57b14c36ce 100644 Binary files a/tests/plots/baseline/test_declarative_smooth_field.png and b/tests/plots/baseline/test_declarative_smooth_field.png differ diff --git a/tests/plots/baseline/test_us_states_scales.png b/tests/plots/baseline/test_us_states_scales.png index 5f12b9dd36..5945b68353 100644 Binary files a/tests/plots/baseline/test_us_states_scales.png and b/tests/plots/baseline/test_us_states_scales.png differ diff --git a/tests/plots/baseline/test_uslcc_plotting.png b/tests/plots/baseline/test_uslcc_plotting.png index aed4966dca..287053a737 100644 Binary files a/tests/plots/baseline/test_uslcc_plotting.png and b/tests/plots/baseline/test_uslcc_plotting.png differ diff --git a/tests/plots/test_cartopy_utils.py b/tests/plots/test_cartopy_utils.py index 83e9508826..1cc864a368 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.092, 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 48588101f8..0947b1544a 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.096) +@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.101) +@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.121) +@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.034) +@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.063) +@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.039) +@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.085) +@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.021) +@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,9 @@ 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.""" @@ -468,7 +478,6 @@ def test_declarative_contour_convert_units(): def test_declarative_events(): """Test that resetting traitlets properly propagates.""" data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) - contour = ContourPlot() contour.data = data contour.field = 'Temperature' @@ -658,7 +667,8 @@ def test_colorfill(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.02) +@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)) @@ -685,7 +695,9 @@ def test_colorfill_with_image_range(cfeature): @pytest.mark.mpl_image_compare( - remove_text=True, tolerance=0.02, 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.""" @@ -763,7 +775,8 @@ def test_colorbar_kwargs(cfeature): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.02) +@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)) @@ -1041,7 +1054,8 @@ def test_declarative_overlay_projections(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.047) +@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.""" @@ -1099,7 +1113,7 @@ def test_declarative_global_gfs(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=1.05) +@pytest.mark.mpl_image_compare(remove_text=True, tolerance=1.42) @needs_cartopy def test_declarative_barb_gfs(): """Test making a contour plot.""" @@ -1128,7 +1142,7 @@ def test_declarative_barb_gfs(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.607) +@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.665) @needs_cartopy def test_declarative_barb_scale(): """Test making a contour plot.""" @@ -1158,7 +1172,7 @@ def test_declarative_barb_scale(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.668) +@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.722) @needs_cartopy def test_declarative_barb_gfs_knots(): """Test making a contour plot.""" @@ -1334,7 +1348,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() @@ -1363,7 +1378,8 @@ def test_declarative_sfc_obs(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.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() @@ -1424,7 +1440,8 @@ def test_declarative_sfc_text(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.) def test_declarative_sfc_obs_changes(ccrs, pandas_sfc): """Test making a surface observation plot, changing the field.""" obs = PlotObs() @@ -1486,7 +1503,7 @@ def test_declarative_colored_barbs(ccrs, pandas_sfc): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.305) +@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.314) def test_declarative_sfc_obs_full(ccrs, pandas_sfc): """Test making a full surface observation plot.""" obs = PlotObs() @@ -1663,7 +1680,8 @@ def test_attribute_error_station(ccrs, pandas_sfc): plt.close(pc.figure) -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.024) +@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), @@ -1696,7 +1714,8 @@ def test_declarative_sfc_obs_change_units(ccrs): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.022) +@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), @@ -1761,7 +1780,8 @@ def test_declarative_title_fontsize(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=False, tolerance=0.607) +@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.""" @@ -1933,7 +1953,7 @@ def test_declarative_region_modifier_zoom_in(): return pc.figure -@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.338) +@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_mapping.py b/tests/plots/test_mapping.py index 8992112b79..271c29fc65 100644 --- a/tests/plots/test_mapping.py +++ b/tests/plots/test_mapping.py @@ -5,6 +5,8 @@ import pytest +from metpy.testing import version_check + ccrs = pytest.importorskip('cartopy.crs') from metpy.plots.mapping import CFProjection # noqa: E402 @@ -147,6 +149,7 @@ def test_lcc(): assert crs.globe.to_proj4_params()['ellps'] == 'sphere' +@pytest.mark.xfail(version_check('cartopy==0.23.0'), reason='SciTools/cartopy#2377') def test_lcc_minimal(): """Test handling lambert conformal conic projection with minimal attributes.""" attrs = {'grid_mapping_name': 'lambert_conformal_conic'} @@ -154,6 +157,7 @@ def test_lcc_minimal(): assert isinstance(crs, ccrs.LambertConformal) +@pytest.mark.xfail(version_check('cartopy==0.23.0'), reason='SciTools/cartopy#2377') def test_lcc_single_std_parallel(): """Test lambert conformal projection with one standard parallel.""" attrs = {'grid_mapping_name': 'lambert_conformal_conic', 'standard_parallel': 25} diff --git a/tests/plots/test_plot_areas.py b/tests/plots/test_plot_areas.py index 6328bcb88a..0c3903f8cb 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.023) + +@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.016) +@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