From 4cc89a8cd94731b3e555bbdd857b8ae6100efb2a Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Mon, 21 Jul 2014 11:11:00 -0700 Subject: [PATCH] Suppress invalid argument warnings in inverse Mollweide projection The Mollweide inverse projection generates Numpy invalid value warnings for pixels outside of the projection. For example, the following code: from matplotlib import pyplot as plt plt.subplot(111, projection='mollweide') plt.savefig('test.png') produces this warning: .../matplotlib/projections/geo.py:489: RuntimeWarning: invalid value encountered in arcsin theta = np.arcsin(y / np.sqrt(2)) This patch silences the warning by wrapping the inverse transformation in a `np.errstate` context. --- lib/matplotlib/projections/geo.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index a81dad29782c..b32dace89709 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -484,11 +484,12 @@ def transform_non_affine(self, xy): x = xy[:, 0:1] y = xy[:, 1:2] - # from Equations (7, 8) of - # http://mathworld.wolfram.com/MollweideProjection.html - theta = np.arcsin(y / np.sqrt(2)) - lon = (np.pi / (2 * np.sqrt(2))) * x / np.cos(theta) - lat = np.arcsin((2 * theta + np.sin(2 * theta)) / np.pi) + with np.errstate(invalid='ignore'): + # from Equations (7, 8) of + # http://mathworld.wolfram.com/MollweideProjection.html + theta = np.arcsin(y / np.sqrt(2)) + lon = (np.pi / (2 * np.sqrt(2))) * x / np.cos(theta) + lat = np.arcsin((2 * theta + np.sin(2 * theta)) / np.pi) return np.concatenate((lon, lat), 1) transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__