Skip to content

Minor cleanup for Astrometric#4992

Merged
mhvk merged 1 commit intoastropy:masterfrom
cdeil:astrometric
Jun 2, 2016
Merged

Minor cleanup for Astrometric#4992
mhvk merged 1 commit intoastropy:masterfrom
cdeil:astrometric

Conversation

@cdeil
Copy link
Copy Markdown
Member

@cdeil cdeil commented May 31, 2016

This PR does some minor cleanup (typos, whitespace) for the Astrometric frame code recently added by @alexrudy and @eteq .

@alexrudy @eteq - How about adding the rotation option to SkyCoord.astrometric_frame and pass it along to AstrometricFrame? Would it be OK with you if I add that as a convenience?
I think it would be nice, but if it's controversial I'll just leave this PR as-is.

@astrofrog astrofrog added this to the v1.2.0 milestone May 31, 2016
@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented May 31, 2016

Looks like the from __future__ import unicode_literals lead to this error on Python 2:
https://travis-ci.org/astropy/astropy/jobs/134089896#L2088

Putting this in every file is part of the Astropy coding guidelines (see here).
Should it be omitted for this file? Or does someone know how to modify the AstrometricFrame class implementation to make it work with from __future__ import unicode_literals on Python 2?

@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented Jun 1, 2016

This is the error that happens on Python 2 for this branch, where from __future__ import unicode_literals was added to astrometric.py:

>>> from astropy.coordinates import AstrometricFrame, SkyCoord
>>> origin = SkyCoord(1, 2, unit='deg')
>>> AstrometricFrame(origin=origin)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "astropy/coordinates/builtin_frames/astrometric.py", line 197, in __new__
    newcls = make_astrometric_cls(origin_frame.__class__)
  File "astropy/coordinates/builtin_frames/astrometric.py", line 108, in make_astrometric_cls
    {'__doc__': AstrometricFrame.__doc__})
  File "astropy/coordinates/builtin_frames/astrometric.py", line 71, in __new__
    res = super(AstrometricMeta, cls).__new__(cls, newname, bases, members)
  File "astropy/coordinates/baseframe.py", line 77, in __new__
    tmp_cls = super(FrameMeta, mcls).__new__(mcls, name, bases, members)
TypeError: type() argument 1 must be string, not unicode

I don't know how to resolve it.
Does anyone have a suggestion?
(For now, I'll remove from __future__ import unicode_literals again so that this PR can move forward.)

@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented Jun 1, 2016

There were some comments in the code left that talked about adding "d" to the "lon" and "lat" names, which is no longer the case. I tried to fix the comments in 9505058, but @eteq and @alexrudy, could you please check the comments and code in AstrometricMeta.__new__ that handles the component names if it's now correct?

@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented Jun 1, 2016

I've gone ahead and added the rotation option to SkyCoord.astrometric_frame in 0a39669.

@astrofrog astrofrog added the Affects-dev PRs and issues that do not impact an existing Astropy release label Jun 1, 2016
@taldcroft
Copy link
Copy Markdown
Member

Should it be omitted for this file? Or does someone know how to modify the AstrometricFrame class implementation to make it work with from future import unicode_literals on Python 2?

It can be omitted. I think the use of unicode_literals is more controversial than the guideline would suggest. io.fits and io.ascii do not use them. I personally would advocate not using that in code but testing with unicode literals (and str literals) in Py2 as needed.

An astrometric frame of the same type as this `SkyCoord` (e.g., if
this object has an ICRS coordinate, the resulting frame is
AstrometricFrame with an ICRS origin)
rotation : Quantity with angle units
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just ~astropy.coordinates.Angle? Could still add "or ~astropy.units.Quantity with angle units"

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 copy & pasted this from the AstrometricFrame docstring. Do you want me to change it in both places, just here, or leave as is?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely both should be the same. And I think it is good practice to link to classes (like ~astropy.units.Quantity). But this is not very important, so I'll leave the decision up to you.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 1, 2016

Agree to just omit the unicode_literals. One tiny comment as you would be editing anyway. Otherwise, this looks all ready to go in.

- Add rotation option to SkyCoord.astrometric_frame
- Correct some code comments about lon / lat attribute names
- Fix some typos and code formatting
@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented Jun 1, 2016

@mhvk - Thanks for the feedback. I applied your inline comment and also squashed the commits.

@alexrudy
Copy link
Copy Markdown
Contributor

alexrudy commented Jun 1, 2016

@cdeil I tried with 'unicode_literals', and I think that we just need to convert the frame name to a native string type, since it becomes a class name.

See alexrudy@09cc02f

This issue is one of the reasons people aren't in favor of 'unicode_literals' any more, as it might break if someone ever got a non-ascii character in there. But I don't think we are going to be creating frames with non-ascii names any time soon. So I'm 0 on whether to leave 'unicode_literals' in or take it out. Otherwise LGTM

@cdeil
Copy link
Copy Markdown
Member Author

cdeil commented Jun 2, 2016

So I'm 0 on whether to leave 'unicode_literals' in or take it out.

Let's leave as-is then.

I think this PR is non-controversial and ready to go then.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 2, 2016

It all looks good, so I merge this before the name change in promised in #5002 makes this unmergeable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release coordinates no-changelog-entry-needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants