-
-
Notifications
You must be signed in to change notification settings - Fork 573
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
Adds ValueError to mapbase.submap() when Helioprojection coordinate contains NaN values. #7543
base: main
Are you sure you want to change the base?
Conversation
801e624
to
db50a75
Compare
sunpy/map/mapbase.py
Outdated
msg = ( | ||
"The {quadrant} input contains NaN values. " | ||
"It is possible the coordinates are off-disk. " | ||
"Consider using Helioprojective.assume_spherical_screen" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we merge #7115, this should change to SphericalScreen
sunpy/map/mapbase.py
Outdated
"The {quadrant} input contains NaN values. " | ||
"It is possible the coordinates are off-disk. " | ||
"Consider using Helioprojective.assume_spherical_screen" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads more like a warning than an exception. My issue with it is it doesn't really say why an exception is being raised. Why am I not being allowed to crop my map when one of my coordinates is off disk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why am I not allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more text to the message, see if you like it.
@@ -0,0 +1 @@ | |||
Updated :meth:`sunpy.map.Map.submap` to check if it is about to work on locations with NaNs now errors and informs the user that they likely want to use :meth:`~sunpy.coordinates.Helioprojective.assume_spherical_screen` so that the off-disk 2D coordinate can be converted to a 3D coordinate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below. Should be updated to use SphericalScreen
once that PR is merged.
TODO:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I guess I haven't looked at this PR before. As guessed by the author, this PR doesn't actually address the common use case of #5598 because the implementation is at the "wrong" place in the code. (The included unit tests do not reflect common usage.) I'll try to provide better guidance soon if someone else doesn't do so first.
Here's an example of the common use case: >>> import astropy.units as u
>>> from astropy.coordinates import SkyCoord
>>> import sunpy.map
>>> from sunpy.data.sample import AIA_171_IMAGE
>>> aiamap = sunpy.map.Map(AIA_171_IMAGE) The following submap that includes off-disk pixels works fine because it is in the native coordinate frame, so 2D coordinates do not need to be promoted: >>> coord_native = SkyCoord(0*u.arcsec, 0*u.arcsec, frame=aiamap.coordinate_frame)
>>> aiamap.submap(coord_native, width=1000*u.arcsec, height=1000*u.arcsec) The following, very similar submap fails because the observer is slightly different, so 2D coordinates need to be transformed to the native coordinate frame, and thus the off-disk 2D corners get a NaN distance when internally promoted. >>> coord_other = SkyCoord(0*u.arcsec, 0*u.arcsec, frame='helioprojective', observer='earth', obstime=aiamap.date)
>>> aiamap.submap(coord_other, width=1000*u.arcsec, height=1000*u.arcsec)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
...
ValueError: cannot convert float NaN to integer The check needs to be on the output of Lines 1912 to 1913 in e7536b1
|
…inates contain NaN values. Added tests to test_mapbase.py.
This pull request produces a value error when Helioprojection coordinates that have NaN distance values are input as bottom_left or top_right to the submap() function.
Fixes #5598
Additional Info:
I'm unsure if this solution fully addresses the common user issue presented in #5598. A testcase that mimics one of these specific user issues could be useful to determine what other situations should result in the ValueError. Any suggestions would be greatly appreciated!