Skip to content

Improved handling of longitude wrap angles in frames - #3223

Merged
Cadair merged 1 commit into
sunpy:masterfrom
ayshih:wrap
Jun 18, 2019
Merged

Cadair merged 1 commit into
sunpy:masterfrom
ayshih:wrap

Conversation

@ayshih

@ayshih ayshih commented Jun 17, 2019

Copy link
Copy Markdown
Member

(This was originally part of #3212, but I feel that it qualifies as a bug fix to get into 1.0.2 rather than wait until 1.1.)

We intend to have all of our frames wrap longitudes at 180 degrees (i.e., the range is -180 deg to +180 deg, rather than 0 deg to +360 deg). Prior to this PR, the longitude wrap angle would get set to the desired value if a frame was created with a (Unit)SphericalRepresentation. However, that meant that if the frame was created with a CartesianRepresentation, and then converted to a SphericalRepresentation, the longitude wrap angle would not get set. This happens frequently after frame transformations, such as for AIAMap.observer_coordinate, which gets converted from HEC coordinates and often shows HGS longitudes of ~359.99 deg rather than a small negative number.

This PR takes a different approach. Rather than modifying the representation as it goes into the frame, the approach is to modify the representation as it comes out. That is, the internal data can be whatever, but whenever the user asks for it as a (Unit)SphericalRepresentation, it is provided with the desired wrap angle.

@ayshih ayshih added the coordinates Affects the coordinates submodule label Jun 17, 2019
@ayshih
ayshih requested a review from Cadair June 17, 2019 01:15
@ghost

This comment has been minimized.

1 similar comment
@ghost

This comment has been minimized.

@Cadair Cadair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a clever way of doing it. Presuming that represent_as is always called when we need it to be?

If a frame wrap angle is set, use that wrap angle for any spherical representations.
"""
data = super().represent_as(base, s, in_frame_units=in_frame_units)
if self._wrap_angle is not None and \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

line break using () rather than \?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I originally had it that way, but when using the (, the way that I want to indent the following line becomes exactly 4 spaces, so it's easy to confuse for an actual indention (and the bot complained as well). So, I changed it to the \ so that I could indent the folllowing line only 3 spaces and break that confusion. It's admittedly silly. How would you indent it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair enough. I just have a pathological hatred for \ lol

@nabobalis

Copy link
Copy Markdown
Member

This fixes the 32bit build error!

@ayshih

ayshih commented Jun 18, 2019

Copy link
Copy Markdown
Member Author

This looks like a clever way of doing it. Presuming that represent_as is always called when we need it to be?

It bears repeating in this PR that the cleverness is not mine; I copied it from here: astropy/astropy#7462 (comment).

As far as I've seen, yes, represent_as is called when needed. It isn't called when using BaseCoordinateFrame.data (i.e., asking for the raw coordinate data), but arguably a user shouldn't rely on the raw coordinate data having a particular representation, much less wrap angle, and should always ask for the desired representation.

@ayshih ayshih added the Needs Review Needs review(s) before merge. label Jun 18, 2019
@nabobalis
nabobalis requested a review from Cadair June 18, 2019 09:30
@Cadair Cadair added [BugFix] and removed Needs Review Needs review(s) before merge. labels Jun 18, 2019
@Cadair
Cadair merged commit 5017201 into sunpy:master Jun 18, 2019
@ayshih
ayshih deleted the wrap branch June 26, 2019 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coordinates Affects the coordinates submodule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants