Skip to content
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

Relax longitude range in fullsphere projections #2348

Merged
merged 5 commits into from
Feb 3, 2023

Conversation

Carifio24
Copy link
Member

As noticed by Alyssa and Theo, longitude angles in the full-sphere projections of the scatter viewer are currently restricted to [-π, π]. This PR relaxes this restriction by mapping the longitude component into this range as appropriate (for example, 3π/2 is mapped to -π/2).

Additionally, as longitude is defined differently for Earth and sky, this PR adds the ability to reverse the full-sphere axes. Matplotlib doesn't let us change bounds in these projections, so this PR mimics this adding a "flip" option in the UI which negates the relevant values. The intended use case here is for longitude, but I don't see a reason not to offer the same option for latitude as well. The buttons in the UI that allow this flipping are only visible when in a full-sphere projection.

@Carifio24
Copy link
Member Author

@astrofrog @dhomeier I saw there were some recent CI updates so I've rebased this (and 2350) onto the main branch.

self.viewer.state.x_att = self.data.id['a']
self.viewer.state.y_att = self.data.id['b']
self.assert_same(tmpdir)
self._fullsphere_common(tmpdir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are the other projections not tested anymore? Maybe you could make plot_mode an input parameter to _fullsphere_common?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, removing the other projections was not intentional. Will add a parameter as you suggest and check each projection

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like I didn't forget the other projections after all - _fullsphere_common checks each plot type

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry, I only looked at the code as far as rendered in the diff!

Copy link
Member Author

Choose a reason for hiding this comment

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

So did I...I forgot I'd covered all the projections until I opened up my editor 😆

@dhomeier
Copy link
Collaborator

Thanks, good to see all required tests are passing.
The functionality itself looks quite uncontroversial, although I am not sure what practical application flip_lat would have – defining southern latitudes as positive and northern negative (no objections to that ;-)?

@Carifio24
Copy link
Member Author

I'll admit I don't know of an intended use case for flipping the latitude - was purely thinking of flexibility

Copy link
Collaborator

@dhomeier dhomeier left a comment

Choose a reason for hiding this comment

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

Thanks, looks all good – I hope the descriptions are self-explanatory enough.

self.viewer.state.x_att = self.data.id['a']
self.viewer.state.y_att = self.data.id['b']
self.assert_same(tmpdir)
self._fullsphere_common(tmpdir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry, I only looked at the code as far as rendered in the diff!

@@ -29,6 +29,8 @@ class ScatterViewerState(MatplotlibDataViewerState):
dpi = DDCProperty(72, docstring='The resolution (in dots per inch) of density maps, if present')
plot_mode = DDSCProperty(docstring="Whether to plot the data in cartesian, polar or another projection")
angle_unit = DDSCProperty(docstring="Whether to use radians or degrees for any angular coordinates")
flip_lonaxis = DDCProperty(False, docstring="Whether or not to flip x coordinates; used for full-sphere projections")
flip_lataxis = DDCProperty(False, docstring="Whether or not to flip y coordinates; used for full-sphere projections")
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure i understand, how is using these options different to setting an x_min value larger than x_max? If it's different, is there any scope to give these more general names? (e.g. flip_x and flip_y)

Copy link
Member Author

@Carifio24 Carifio24 Jan 30, 2023

Choose a reason for hiding this comment

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

Using these has the same effect as x_min > x_max, in that the axis will run in the opposite direction to usual. I added these in because matplotlib doesn't allow us to change bounds for the full-sphere projections. For the other projections one can just use the bounds instead. But maybe flip_x/flip_y names are more future-proof, in case we someday have other bound-less projections?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could do this without adding new callback properties - what if we just use x_min and x_max but at the point of setting the limits, if one can't actually set the full limits we would still use the order of x_min/x_max to determine whether to flip the limits in the plot. The benefit of this is that if a user uses the flip buttons in the existing axes limits in the UI it should still work?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that it would be nice not to need new callback properties. I'll try reworking this to something along these lines and see how it goes.

@Carifio24
Copy link
Member Author

@astrofrog I've changed the axis-flipping to work essentially how you had suggested. The flip button is now active in full-sphere mode. Using this changes x_min and x_max, but just doesn't pass this along to matplotlib.

Since doing this "flip" involves redrawing the data in this case, I've added some logic to the layer artist to redraw when bounds are changed and we're in a full-sphere projection.

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@astrofrog astrofrog merged commit 864a557 into glue-viz:main Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants