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

Smart formatting of tick labels in WCSAxes #7215

Merged
merged 14 commits into from
Mar 21, 2018

Conversation

astrofrog
Copy link
Member

@astrofrog astrofrog commented Feb 19, 2018

This fixes the formatting of tick labels when used with a right ascension axis, in which case the hh:mm:ss format should be used (not dd:mm:ss). This is done by making it so that AngleFormatterLocator takes a format_unit (like ScalarFormatterLocator). This also fixes the use of set_format_unit with angle coordinates.

This is a bordeline bug/enhancement case, but I'd argue that the fact that set_format_unit didn't work correctly for angle coordinates previously was a bug.

Here's what an RA/Dec plot now looks like by default:

wcsaxes

Remaining to-dos:

  • Improve auto-determination of ticks when using hh:mm:ss as above (which shows the default spacing is not ideal)
  • Update existing image tests
  • Add new image tests, including with LaTeX tick labels

Fixes #7209

@astropy-bot
Copy link

astropy-bot bot commented Feb 19, 2018

Hi there @astrofrog 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

I noticed the following issue with this pull request:

  • Changelog entry section (v3.1) inconsistent with milestone (v3.0.2)

Would it be possible to fix this? Thanks!

If there are any issues with this message, please report them here.

@Cadair
Copy link
Member

Cadair commented Feb 20, 2018

Does it make any sense to add u.arcsec as a format unit? I am not quite sure I am following all the code in here, but for all the sunpy plots being in u.arcsec is the same as formatting the axes with s.s.

@astrofrog
Copy link
Member Author

@Cadair - with this PR, you can use ax.coords[0].set_format_unit(u.arcsec) and this will then automatically use decimal formatting but will choose the number of decimal places automatically (unlike e.g. s.ss which would pick two).

@Cadair
Copy link
Member

Cadair commented Feb 20, 2018

Nice!

@astrofrog
Copy link
Member Author

At least that's the theory ;) Feel free to try it out!

Copy link
Contributor

@lpsinger lpsinger left a comment

Choose a reason for hiding this comment

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

How would this code work with plots that have axes that are angle offsets rather than absolute angles?

return self._format_unit

@format_unit.setter
def format_unit(self, unit):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the setter also take a string like 'hourangle' or 'deg'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I've updated this and set_format_unit to accept anything that can initialize Unit

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

@@ -109,6 +109,9 @@ def test_contour_overlay(self):
ax.set_xlim(0., 720.)
ax.set_ylim(0., 720.)

# For backward-compatibility with previous reference images
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe explain in this comment what change required this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@astrofrog
Copy link
Member Author

@lpsinger:

How would this code work with plots that have axes that are angle offsets rather than absolute angles?

This code will only enable hh:mm:ss notation if CTYPE[:4] is RA-- which I think likely won't be the case for offset coordinates? Basically the only output that is changed with this PR is when CTYPE[:4] is RA--``, and the rest should be the same I think? Do you have examples of files with offset coordinates?

@bsipocz
Copy link
Member

bsipocz commented Feb 20, 2018

@astrofrog - If this is an enhancement rather than a bugfix, ultimately it should be 3.1 rather than 3.0.1 isn't it?

@astrofrog
Copy link
Member Author

@bsipocz - I think it's a borderline case - see my comment at the top of this PR:

This is a bordeline bug/enhancement case, but I'd argue that the fact that set_format_unit didn't work correctly for angle coordinates previously was a bug.

I'm happy to re-milestone this to 3.1 though as I don't feel strongly about it.

@bsipocz
Copy link
Member

bsipocz commented Feb 21, 2018

@astrofrog - I'm just playing the gatekeeper role with no real preference, and I'm actually happy to backport borderline cases if anyone makes a decision about them.

Copy link
Member

@larrybradley larrybradley left a comment

Choose a reason for hiding this comment

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

Thanks, @astrofrog. LGTM except for a couple minor comments.

It's borderline, but let's leave this as 3.0.1.


if not isinstance(values, u.Quantity) and values is not None:
raise TypeError("values should be a Quantities array")

if len(values) > 0:

Copy link
Member

Choose a reason for hiding this comment

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

Why the blank line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

----------
value : float
The value to format
format : { 'auto' | 'ascii' | 'latex' }, optional
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: shouldn't this be a comma-separated list (that's what numpydoc uses) instead of pipe-separated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@larrybradley larrybradley added 💤 merge-when-ci-passes Do not use: We have auto-merge option now. and removed Ready-for-final-review labels Feb 26, 2018
@larrybradley
Copy link
Member

LGTM. Thanks, @astrofrog. This will need to be rebased once #7234 is merged.

…ault. This also generalizes the AngleFormatterLocator so that it can take default units as well as having a way to specify to use decimal formatting by default.
@drdavella
Copy link
Contributor

@larrybradley I just rebased this in the hopes that it can be merged in the near future.

@astrofrog
Copy link
Member Author

There are real test failures due to @Cadair's commit :) I need to investigate and fix them, I'll try and take a look now.

fmt = None

decimal = False
sep = 'fromunit'
Copy link
Member Author

Choose a reason for hiding this comment

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

@Cadair - can you explain this change? Why set decimal to False here and then change sep when it was set to None on line 354?

@astrofrog
Copy link
Member Author

Since this PR was functional and approved prior to @Cadair's commit, I've removed that commit and will add it (and fix the failures) in a separate PR.

@astrofrog
Copy link
Member Author

It looks like I moved this to 3.1 in the last commit before merging, but the astropy bot didn't have time to catch the inconsistency in the milestone. I'm going to change the milestone to 3.1 as I don't really feel strongly that this really should be backported and these are non-trivial changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visualization.wcsaxes 💤 merge-when-ci-passes Do not use: We have auto-merge option now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better default units/format for WCSAxes
6 participants