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

Geo divide zero #505

merged 2 commits into from
Oct 4, 2011

Conversation

efiring
Copy link
Member

@efiring efiring commented Oct 2, 2011

The Newton-Raphson iteration converges more slowly near
the poles, and triggers a divide-by-zero at the poles.
Although the previous transform was handling this correctly
in the sense that it was still giving the right answer,
the divide-by-zero warning was non-optimal.

The present version switches to a Taylor-series approximation
for latitudes within 5 degrees of the poles. This avoids
the divide-by-zero, and also runs faster on arrays with a
full range of latitudes.

The Newton-Raphson iteration converges more slowly near
the poles, and triggers a divide-by-zero at the poles.
Although the previous transform was handling this correctly
in the sense that it was still giving the right answer,
the divide-by-zero warning was non-optimal.

The present version switches to a Taylor-series approximation
for latitudes within 5 degrees of the poles.  This avoids
the divide-by-zero, and also runs faster on arrays with a
full range of latitudes.
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.
@efiring
Copy link
Member Author

efiring commented Oct 2, 2011

The second commit takes care of the remaining two divide-by-zero warnings noted in #503.

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.

@jdh2358
Copy link
Collaborator

jdh2358 commented Oct 2, 2011

Thanks Eric, I can confirm that this fixes the warnings on my tests.

efiring added a commit that referenced this pull request Oct 4, 2011
@efiring efiring merged commit 7dda386 into matplotlib:v1.1.x Oct 4, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants