Skip to content

Implement AffineTransforms - #10

Closed
adrn wants to merge 25 commits into
coordinates/diffs-on-repsfrom
coordinates/affine-transforms
Closed

adrn wants to merge 25 commits into
coordinates/diffs-on-repsfrom
coordinates/affine-transforms

Conversation

@adrn

@adrn adrn commented Jun 10, 2017

Copy link
Copy Markdown
Owner

No description provided.

@adrn
adrn force-pushed the coordinates/affine-transforms branch from 8593562 to 9ccff22 Compare June 10, 2017 17:45
@adrn
adrn force-pushed the coordinates/diffs-on-reps branch from f0b88f3 to bc08ff6 Compare June 11, 2017 20:06
@adrn
adrn force-pushed the coordinates/affine-transforms branch from 72386ac to c05c77f Compare June 11, 2017 20:08
class StaticMatrixTransform(CoordinateTransform):
return newrep

class AffineTransform(BaseAffineTransform):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This (and probably BaseAffineTransform) should be in __all__ , right? That is, they shold be considered public API?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

done!

@adrn
adrn force-pushed the coordinates/affine-transforms branch from 6f68461 to d74bd6a Compare June 12, 2017 16:16
@adrn adrn changed the title Implement AffineTransforms and a proof of concept ICRS-Galactocentric demo Implement AffineTransforms Jun 12, 2017
@adrn
adrn force-pushed the coordinates/diffs-on-reps branch from bc08ff6 to 2725e80 Compare June 13, 2017 16:18
@adrn
adrn force-pushed the coordinates/affine-transforms branch 2 times, most recently from 16dce30 to 0960e2b Compare June 14, 2017 01:17
@adrn
adrn force-pushed the coordinates/diffs-on-reps branch from f08e128 to 03f04dd Compare June 14, 2017 20:30
@adrn
adrn force-pushed the coordinates/affine-transforms branch from 04c773b to db13a87 Compare June 14, 2017 20:31

@mhvk mhvk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks very good, and my comments are mostly minor, but for larger ones, see astropy#6218 (comment) (so discussion stays on the astropy github site).

rotation = rotation_matrix(-np.arcsin(z_d), 'y')
representation = (intrep - translation).transform(rotation)
translation = CartesianRepresentation(gcf.galcen_distance * [1., 0., 0.])
z_d = (gcf.z_sun / gcf.galcen_distance).decompose()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why the decompose? I'd think the arcsin would (effectively) do that for you.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yea, not sure - that was in there before, but will update now since I'm touching this code.

bary_sun_pos = get_body_barycentric('sun', hcrs_coo.obstime)
newrep = hcrs_coo.cartesian + bary_sun_pos
return icrs_frame.realize_frame(newrep)
bary_sun_vel = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This seems unused.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It's used on L298, a few lines below this.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Oh, I see what you mean now :)

@frame_transform_graph.transform(AffineTransform, ICRS, HCRS)
def icrs_to_hcrs(icrs_coo, hcrs_frame):
# this is just an origin translation so without a distance it cannot go ahead
if icrs_coo.data.__class__ == UnitSphericalRepresentation:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While you are here, replace == with is (or do isinstance(icrs_coo.data, UnitSphericalRepresentation))

# already got unregistered when trans2 was created.
trans2.unregister(frame_transform_graph)


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two empty lines between functions is actually pep8...

"""

def _apply_transform(self, fromcoord, matrix, vectors):
from .representation import (CartesianRepresentation,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not import these at the top?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Ran in to circular import issues, but I'll check again to confirm.

Comment thread astropy/coordinates/transformations.py Outdated
newdiff = newdiff.transform(matrix)

if vectors is not None and vectors[1] is not None:
vel_offset = CartesianRepresentation(vectors[1])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same as above, vectors[1] should probably be CartesianRepresentation. Or, perhaps better, just let it be an associated CartesianDifferential?

Comment thread astropy/coordinates/transformations.py Outdated
subclasses.
"""

def _apply_transform(self, fromcoord, matrix, vectors):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Move to CartesianRepresentation.transform? (since this may be discussion to keep, see larger comment in the astropy thread: astropy#6218 (comment))

Comment thread astropy/coordinates/transformations.py Outdated
newdiff = newdiff.represent_as(CartesianDifferential)
newrep._differentials = (newdiff,)

if issubclass(fromcoord.data.__class__, UnitSphericalRepresentation):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just isinstance(fromcoord.data, UnitSphericalRepresentation)?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Sure - I think this was also in the code already, but will change.

Comment thread astropy/coordinates/transformations.py Outdated
vel_offset = CartesianRepresentation(vectors[1])
newdiff = newdiff + vel_offset

newdiff = newdiff.represent_as(CartesianDifferential)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think here it would be better to represent it back as the type it was before, with newrep as a base.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done

def __call__(self, fromcoord, toframe):

M, vec = self.transform_func(fromcoord, toframe)
newrep = self._apply_transform(fromcoord, M, vec)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this would become

newrep = fromcoord.represent_as(CartesianRepresentation).transform(M, vec)

@adrn
adrn force-pushed the coordinates/affine-transforms branch from db13a87 to 3abf575 Compare June 16, 2017 01:55
@adrn
adrn force-pushed the coordinates/affine-transforms branch from 4de3f11 to df5081f Compare June 18, 2017 14:17
# Note: the above docstring gets overridden for differentials.
raise NotImplementedError()

def to_cartesian_with_differentials(self):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@mhvk @eteq I could use this for brevity in the affine transform, so this is one possibility for a short-hand

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Am still not too keen to add this to representation, as I don't like the duplication of to_cartesian and find the name rather long (but don't have a better suggestion).

How about using it for .cartesian on a frame, though? For that case, I feel there is no doubt one wants to transform the derivatives as well, and we know that we only have first-order to worry about. I guess that means adapting represent_as. We can always decide to move it down to representation later.

return dict()

if not self.differentials:
if not self.differentials and differential_class:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Only fail if an empty dict is passed and there are no differentials - this allows for slightly cleaner code elsewhere.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a good idea.

@adrn adrn closed this Jun 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants