Skip to content

Geo divide zero #505

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

Merged
merged 2 commits into from
Oct 4, 2011
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
efiring committed Oct 2, 2011
commit 533e5fba0bee341bec31bb2987c19e86b05cb631
12 changes: 6 additions & 6 deletions lib/matplotlib/projections/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,16 @@ def transform(self, ll):
cos_latitude = np.cos(latitude)

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

x = (cos_latitude * np.sin(half_long)) / sinc_alpha
y = (np.sin(latitude) / sinc_alpha)
x.set_fill_value(0.0)
y.set_fill_value(0.0)
return np.concatenate((x.filled(), y.filled()), 1)
x = (cos_latitude * ma.sin(half_long)) / sinc_alpha
y = (ma.sin(latitude) / sinc_alpha)
return np.concatenate((x.filled(0), y.filled(0)), 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right that we have np.cos(latitude) in the numerator on 282 but ma.sin(latitude) in the numerator on 283?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
http://en.wikipedia.org/wiki/Aitoff_projection
The one difference is the factor of 2 in x; but it is handed via set_aspect in the init() method.

transform.__doc__ = Transform.transform.__doc__

transform_non_affine = transform
Expand Down