Skip to content

Suppress invalid argument warnings in inverse Mollweide projection #3283

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

Conversation

lpsinger
Copy link
Contributor

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.

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.
@jenshnielsen
Copy link
Member

I also fixed the issue in #3282

I think this is a slightly better place to fix it since in only silences the warnings thrown when calculating the ticks which causes the warning above. Matploblib tries to calculate ticks slightly outside the plot limits which causes the warning above since the limits are equal to the allowed limits.

If you silence it here you might also silence it for a transformation where it actually is a valid issue. But perhaps the use of numpys warning filters is better that the generic python one.

@tacaswell tacaswell added this to the v1.5.x milestone Jul 21, 2014
@lpsinger
Copy link
Contributor Author

I think this is a slightly better place to fix it since in only silences the warnings thrown when calculating the ticks which causes the warning above. Matploblib tries to calculate ticks slightly outside the plot limits which causes the warning above since the limits are equal to the allowed limits.

I agree. Thanks for sharing your solution. Closing this PR.

If you silence it here you might also silence it for a transformation where it actually is a valid issue. But perhaps the use of numpys warning filters is better that the generic python one.

See PR jenshnielsen#2, which you can merge into your own PR against matplotlib itself.

@lpsinger lpsinger closed this Jul 21, 2014
@lpsinger lpsinger deleted the ignore_invalid_value_encountered_in_arcsin branch July 21, 2014 18:44
@jenshnielsen
Copy link
Member

Great, I have merged your pull request

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.

3 participants