Skip to content

Commit 533e5fb

Browse files
committed
geo.py: fix divide-by-zero warning in Aitoff transform
An attempt to do this had been make by masking zero values in the denominator; but at least with current numpy, this is not enough, because the __div__ method of the first argument is used. The solution is to ensure that the first argument is also a masked array.
1 parent 1391ad0 commit 533e5fb

File tree

1 file changed

+6
-6
lines changed
  • lib/matplotlib/projections

1 file changed

+6
-6
lines changed

lib/matplotlib/projections/geo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,16 @@ def transform(self, ll):
271271
cos_latitude = np.cos(latitude)
272272

273273
alpha = np.arccos(cos_latitude * np.cos(half_long))
274-
# Mask this array, or we'll get divide-by-zero errors
274+
# Mask this array or we'll get divide-by-zero errors
275275
alpha = ma.masked_where(alpha == 0.0, alpha)
276+
# The numerators also need to be masked so that masked
277+
# division will be invoked.
276278
# We want unnormalized sinc. numpy.sinc gives us normalized
277279
sinc_alpha = ma.sin(alpha) / alpha
278280

279-
x = (cos_latitude * np.sin(half_long)) / sinc_alpha
280-
y = (np.sin(latitude) / sinc_alpha)
281-
x.set_fill_value(0.0)
282-
y.set_fill_value(0.0)
283-
return np.concatenate((x.filled(), y.filled()), 1)
281+
x = (cos_latitude * ma.sin(half_long)) / sinc_alpha
282+
y = (ma.sin(latitude) / sinc_alpha)
283+
return np.concatenate((x.filled(0), y.filled(0)), 1)
284284
transform.__doc__ = Transform.transform.__doc__
285285

286286
transform_non_affine = transform

0 commit comments

Comments
 (0)