Thanks to visit codestin.com
Credit goes to github.com

Skip to content

3.2.0 may break some Cartopy tests #15806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
QuLogic opened this issue Dec 2, 2019 · 6 comments · Fixed by #15903
Closed

3.2.0 may break some Cartopy tests #15806

QuLogic opened this issue Dec 2, 2019 · 6 comments · Fixed by #15903
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@QuLogic
Copy link
Member

QuLogic commented Dec 2, 2019

Bug report

I've started trying to get Cartopy working with the latest Matplotlib releases. Currently a lot of things fail, but there are some new things in 3.2.0rc1 that we may want to fix before releasing. Unfortunately, all those existing failures make it difficult to determine what's new, but I believe the following are introduced by 3.2.0rc1.

Code for reproduction

$ conda create -p /tmp/cpmpl matplotlib-base cartopy filelock
$ conda activate /tmp/cpmpl
$ pip install matplotlib==3.2.0rc1
$ pytest --pyargs cartopy -k 'test_limits_contour or test_contour_plot_bounds or test_global_contourf_wrap_no_transform or test_pcolormesh_goode_wrap or test_pcolormesh_mercator_wrap'

Actual outcome
For test_limits_contour:

E           AssertionError: 
E           Arrays are not almost equal to 6 decimals
E           
E           x and y +inf location mismatch:
E            x: array([[ inf,  inf],
E                  [-inf, -inf]])
E            y: array([[ 70., -45.],
E                  [170.,  45.]])

For test_contour_plot_bounds:

E       AssertionError: 
E       Arrays are not almost equal to 6 decimals
E       
E       Mismatch: 100%
E       Max absolute difference: 3230840.45
E       Max relative difference: 0.99999998
E        x: array([-0.05,  0.05, -0.05,  0.05])
E        y: array([-2763217.  ,  2681906.  ,  -263790.62,  3230840.5 ])

For test_global_contourf_wrap_no_transform:
The test image is cropped into a very small area.

For test_pcolormesh_goode_wrap, and test_pcolormesh_mercator_wrap:
The left edge of the image is visibly cropped.

Expected outcome

Tests pass.

Matplotlib version

  • Operating system: Fedora 30
  • Matplotlib version: 3.2.0rc1
  • Matplotlib backend (print(matplotlib.get_backend())): Agg
  • Python version: 3.7
  • Other libraries: Cartopy 0.17.0
@QuLogic QuLogic added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 2, 2019
@QuLogic QuLogic added this to the v3.2.0 milestone Dec 2, 2019
@QuLogic
Copy link
Member Author

QuLogic commented Dec 2, 2019

test_limits_contour bisects to:

commit b03370a04537fec9ed153850cf0d73cbc839bd78
Author: Jody Klymak <[email protected]>
Date:   Fri Jul 19 13:50:57 2019 -0700

    FIX: get_datalim for collection (#13642)
    
    * FIX: change autolim exclude shapes not in data co-ordinates
    
    * Update doc/api/next_api_changes/2019-03-04-AL.rst
    
    Co-Authored-By: Elliott Sales de Andrade <[email protected]>

test_contour_plot_bounds bisects to:

commit aa87937c38be95a5efad0a0a8c30717ffd8931fb
Author: Paul Ivanov <[email protected]>
Date:   Wed Oct 2 13:07:01 2019 -0700

    Backport PR #15258: Don't fallback to view limits when autoscale()ing no data.

test_global_contourf_wrap_no_transform is changed slightly (zoomed in a bit) by b03370a, and then broken entirely by aa87937.

test_pcolormesh_goode_wrap and test_pcolormesh_mercator_wrap both fail starting with b03370a.

b03370a comes from #13642 and aa87937 from #15258.

@QuLogic
Copy link
Member Author

QuLogic commented Dec 2, 2019

I just realized the conda-forge packages of Cartopy do not include the test images, so you will need to grab them from GitHub or install via source if you want to test test_global_contourf_wrap_no_transform, test_pcolormesh_goode_wrap, and test_pcolormesh_mercator_wrap

@jklymak
Copy link
Member

jklymak commented Dec 3, 2019

@QuLogic, Happy to look at this, but I'm not 100% clear if the problem is just that an image test broke, which is expected if it used auto limits, or if the image looks really bad.

@QuLogic
Copy link
Member Author

QuLogic commented Dec 10, 2019

Well, the problem is that the test limits are now 0 (or maybe whatever nonsingular outputs), so there's nothing in the image. Some tests don't do that, and are just cropped a little bit, but I haven't figured out why that is.

In Cartopy, artists can have an arbitrary transform that is unrelated to the transform of the Axes (which is fundamental to how it works since data and map may come from different coordinate systems.) For contourf, Cartopy grabs the collection's datalim and reapplies autoscaling based on it. I think the new check for transData fails in this case, returning a null bbox, but I could be wrong.

Please excuse any errors I may have made; I have no internet and am trying to answer the specifics from memory.

@anntzer
Copy link
Contributor

anntzer commented Dec 10, 2019

@QuLogic Looks like you may need the following as well, due to #13581:

diff --git a/lib/cartopy/tests/mpl/__init__.py b/lib/cartopy/tests/mpl/__init__.py
index 6ba66cc..bc9fe42 100644
--- a/lib/cartopy/tests/mpl/__init__.py
+++ b/lib/cartopy/tests/mpl/__init__.py
@@ -31,7 +31,6 @@ import matplotlib.pyplot as plt
 import matplotlib.patches as mpatches
 from matplotlib.testing import setup as mpl_setup
 import matplotlib.testing.compare as mcompare
-import matplotlib._pylab_helpers as pyplot_helpers
 
 
 MPL_VERSION = distutils.version.LooseVersion(mpl.__version__)
@@ -211,12 +210,12 @@ class ImageTesting(object):
             plt.switch_backend('agg')
             mpl_setup()
 
-            if pyplot_helpers.Gcf.figs:
+            if plt.get_fignums():
                 warnings.warn('Figures existed before running the %s %s test.'
                               ' All figures should be closed after they run. '
                               'They will be closed automatically now.' %
                               (mod_name, test_name))
-                pyplot_helpers.Gcf.destroy_all()
+                plt.close('all')
 
             if MPL_VERSION >= '2':
                 style_context = mpl.style.context
@@ -228,14 +227,12 @@ class ImageTesting(object):
             with style_context(self.style):
                 r = test_func(*args, **kwargs)
 
-                fig_managers = pyplot_helpers.Gcf._activeQue
-                figures = [manager.canvas.figure for manager in fig_managers]
-
+                figures = [plt.figure(num) for num in plt.get_fignums()]
                 try:
                     self.run_figure_comparisons(figures, test_name=mod_name)
                 finally:
                     for figure in figures:
-                        pyplot_helpers.Gcf.destroy_fig(figure)
+                        plt.close(figure)
                     plt.switch_backend(orig_backend)
             return r

@QuLogic
Copy link
Member Author

QuLogic commented Dec 12, 2019

Isn't that in 3.3.0, only? I'll look into that some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants