Skip to content

Use representation arithmetic - #5434

Merged
eteq merged 1 commit into
astropy:masterfrom
mhvk:use-representation-arithmetic
Oct 28, 2016
Merged

eteq merged 1 commit into
astropy:masterfrom
mhvk:use-representation-arithmetic

Conversation

@mhvk

@mhvk mhvk commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

As it seems the representation arithmetic is nearing merging, I thought it would be useful to see how much simpler the coordinate transformation code becomes if one uses it. I'm quite pleased: now almost all fiddling with dimensions is to get stuff to and from erfa.

Note: for now built on top of #5301; just look at the last commit only to see the effect on the transformations.

p.s. The only part I did not touch is matching.py.

representation = representation.represent_as(UnitSphericalRepresentation)
else:
representation = CartesianRepresentation(x=x*c.unit, y=y*c.unit, z=z*c.unit)
r = r.represent_as(UnitSphericalRepresentation)

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.

I realize you're following r from some of the other cases here, but what about uniformly changing to representation instead of r? I remember when writing some of this that I avoided r because it seemed like r as in the spherical coordinate r rather than "representation".

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.

I'd even take rep :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made it rep, representation being a bit too long...

@eteq

eteq commented Oct 27, 2016

Copy link
Copy Markdown
Member

A very nice demonstration of the power of #5301 - nice work @mhvk!

@mhvk
mhvk force-pushed the use-representation-arithmetic branch 2 times, most recently from 731f70d to 534314b Compare October 27, 2016 16:29
@mhvk

mhvk commented Oct 27, 2016

Copy link
Copy Markdown
Contributor Author

OK, rebased this, and replaced r with rep. Tests pass locally, but will wait for the cython problem to be resolved.

@StuartLittlefair StuartLittlefair left a comment

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.

This is lovely @mhvk!

newrep = CartesianRepresentation(newxyz).represent_as(SphericalRepresentation)
astrom_eb = CartesianRepresentation(
u.Quantity(np.rollaxis(astrom['eb'], -1, 0), u.au, copy=False),
copy=False)

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.

This construct is repeated often enough to make me think it's worth hiving off into a utility function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wondered also whether to make the CartesianRepresentation initializer a little more flexible, so one could give an array and just tell it which axis to take as the xyz one (rather than only allowing axis 0). One might then also want to be able to pass in a unit...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I raised #5439 to remind myself, as I'm not sure I'll have time to do it here (or whether indeed it isn't better done separately).

@mhvk
mhvk force-pushed the use-representation-arithmetic branch from 534314b to fc5f5b8 Compare October 28, 2016 14:56
@mhvk

mhvk commented Oct 28, 2016

Copy link
Copy Markdown
Contributor Author

@eteq - this now passes. Let me know if you have any remaining comments on this (or if there still are problems with multi-D representations).

@eteq

eteq commented Oct 28, 2016

Copy link
Copy Markdown
Member

@mhvk - I'm still getting errors when I try to run eteq/astropy@ec9cba8 locally (in a few different configurations) that look like broadcasting problems. I think the best way to proceed is for me to make a new PR with just that so we can spec out on travis what the problem is, which I did in #5441.

But the fact that these tests are currently passing means that it's not seriously affect the existing machinery. So I think it's safe to merge this now anyway... so I will do so!

@eteq
eteq merged commit 4c424e5 into astropy:master Oct 28, 2016
@mhvk
mhvk deleted the use-representation-arithmetic branch October 28, 2016 23:27
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.

4 participants