Repository navigation
Add CartesianRepresentationFrameAttribute to GCRS and PrecessedGeocentric frames - #5207
StuartLittlefair wants to merge 31 commits into
Conversation
|
I should mention it would be nice to merge this ASAP, since astropy/astroplan#167 introduced some fairly dodgy hacks to workaround #4926. It would be nice to remove those before the next version of astroplan is released. |
|
@StuartLittlefair - This looks good, except that I think we should not aim to be flexible in where the three coordinates are located: I think they have to be the first dimension, as for |
|
p.s. Agreed it would be nice to merge this soon -- it will also help make |
|
Also, this does need a changelog entry. Is this something that makes sense to backport? My guess is not, so I put the milestone at 1.2.2 for now. |
|
p.p.p.s. The failures seem real. |
|
Ok @mhvk - I can see that (3,3) is ambiguous. It's a one liner to change this and most code within astropy shouldn't need to change. There may be some potential changes to I'm not sure about backporting. It would be useful for astroplan to backport to 1.2 I think, but I don't fully understand the implications. I'll have to look at that and the failures tomorrow morning. |
|
@mhvk good call on removing the flexibility. Everything "just works" regardless. The only user-facing change as a result of this PR is that accessing the |
| if np.all(value == 0) and self.unit is not None: | ||
| return CartesianRepresentation(np.zeros(3) * self.unit), True | ||
| else: | ||
| converted = True |
There was a problem hiding this comment.
At this point, can we just do
cartrep = CartesianRepresentation(value)
I.e., do we need a unit change at all? It seems a lot of code for something that I find hard to see the use of...
There was a problem hiding this comment.
The idea is to stop someone setting the attributes with a Quantity or CartesianRepresentation that's in the wrong units.
The other purpose is that later in the coordinate transformation code we use the fact that we can trust obsgeoloc to be in metres and obsgeovel to be in metres/sec.
There was a problem hiding this comment.
OK, it sounds like CartesianRepresentation should obtain a .to method for unit conversion... But that can be in a separate PR...
|
@StuartLittlefair - great that it "just works"!! I have one in-line question for simplification. Another is a more general one: why would In the end, I don't think it matters too much (indeed, In any case, it would probably be good if some of those who wrote the code can have a quick look as well, so cc @taldcroft, @eteq. |
|
Thanks for the suggestion @mhvk . I was quite impressed by how simple it was. Almost as if someone thought carefully when they wrote these objects in the first place ;) One reason not to use |
|
Also OK on |
| raise TypeError('Tried to set a CartesianRepresentationFrameAttribute with ' | ||
| 'something that does not have a unit.') | ||
| oldvalue = value | ||
| value = u.Quantity(oldvalue, copy=False).to(self.unit) |
There was a problem hiding this comment.
Couldn't this just be?
value = u.Quantity(oldvalue, self.unit, copy=False)
|
This PR almost addresses part of #5209. Instead the example there causes a different bug: In [4]: SkyCoord(moon)
Out[4]:
<SkyCoord (GCRS: obstime=2014-01-20 22:00:00.000, obsgeoloc=(1712675.0, 5328049.0, -3053885.0) m, obsgeovel=(-388.0, 125.0, 0.0) m / s): (ra, dec, distance) in (deg, deg, AU)
(172.4, 0.51, 0.002671)>
In [5]: SkyCoord([moon])
Out[5]:
<SkyCoord (ICRS): (ra, dec) in deg
(172.4, 0.51)>
In [6]: SkyCoord([moon, moon])
Out[6]:
<SkyCoord (ICRS): (ra, dec, distance) in (deg, deg, AU)
[(172.4, 0.51, 0.002671), (172.4, 0.51, 0.002671)]>
In [7]: SkyCoord([moon.icrs, moon.icrs])
Out[7]:
<SkyCoord (ICRS): (ra, dec, distance) in (deg, deg, AU)
[(122.91386538, 19.98343108, 0.98321877),
(122.91386538, 19.98343108, 0.98321877)]>
In [8]: moon.icrs
Out[8]:
<SkyCoord (ICRS): (ra, dec, distance) in (deg, deg, AU)
(122.91386538, 19.98343108, 0.98321877)>I think this is because |
| obstime = TimeFrameAttribute(default=DEFAULT_OBSTIME) | ||
| obsgeoloc = QuantityFrameAttribute(default=0, unit=u.m, shape=(3,)) | ||
| obsgeovel = QuantityFrameAttribute(default=0, unit=u.m/u.s, shape=(3,)) | ||
| obsgeoloc = CartesianRepresentationFrameAttribute(default=0, unit=u.m) |
There was a problem hiding this comment.
Per previous comment, this could be CartesianRepresentationFrameAttribute(default=[0, 0, 0], unit=u.m) (I think).
|
Thanks for the comments @taldcroft The last few commits should address them, I think. |
|
Fixes #5216 |
|
|
||
| - ``astropy.coordinates`` | ||
|
|
||
| - Changed obsgeoloc and obsgeovel frame attributes to CartesianRepresentation. Fixes creation of |
There was a problem hiding this comment.
I wonder if this should also be listed in API changes.
|
Overall this is looking close. I just looked at the test diffs and it does not appear that all of the logical code paths are being tested. I'm guessing that existing tests won't cover this, but I haven't explicitly looked. |
|
I've added a few extra lines to the regression test which should test all the logic I added. |
|
@StuartLittlefair - I like the idea here and I think this is basically good (it looks to me like you had no more changes pending, right?). But I have one concern: backwards compatibility. If I understand right, this is still backwards compatible at the input - that is, if you provide an Alternatively, if we think these attributes are never actually accessed in the wild, then maybe it's not worth worrying much about it. But it should still definitely be listed in the API changes section of the changelog. |
|
Now back from holidays and had a bit more of a look. On the backwards compatibility, possibly the direct use of the attributes is a rare enough case that we can just do it rather than deprecate? I ask in part because at a bit higher level I wonder a bit about the logic of having a separate Above, @StuartLittlefair mentioned that one perhaps shouldn't use Anyway, it is all leaving me a bit confused. However, from the perspective of allowing proper broadcasting between coordinates and their frame attributes, it certainly is very helpful that with the current implementation, the |
|
p.s. Separately, |
|
Thanks for the comments. A few thoughts:
Will add an API changeling entry, but pending a decision on deprecation, that is the only outstanding change. |
| - Changed obsgeoloc and obsgeovel frame attributes to CartesianRepresentation. Fixes creation of | ||
| GCRS frames representing a location on Earth with multiple obstimes. [#5207] | ||
| - GCRS frames representing a location on Earth with multiple obstimes are now allowed. This means that | ||
| the solar system routines ``get_body``, ``get_moon`` and ``get_sun`` now work with non-scalar times and |
There was a problem hiding this comment.
I think the travis failure is because the indentation here is not exactly right (add one more space to align this line and the one below).
|
Thanks @mhvk. This is now passing. Pending some consensus on deprecation I am finished working on the PR. |
|
To have something to look at, I changed |
|
Am closing this since it is part of #5253, and there seems to be agreement that it is better to change |
This PR fixes #4926, and is a replacement for #5196.
As @mhvk mentioned on the latter PR, it would be much more logical for the
obsgeolocandobsgeovelattributes to beCartesianRepresentations.I was initially reluctant, but I realised that you can be flexible about what types of values initialise these attributes so that (3, ...) or (..., 3) shaped
Quantitiesare allowed, as well asCartesianRepresentationsthemselves. This means the code changes are minimal, and anyone who sets these attributes in their code will find their code still works.