Skip to content

SkyCoord.transform_to(other) ignores other.equinox if default #5722

Closed

Description

@dmopalmer

Transforming from one frame to another acts differently depending on whether the destination frame's equinox was its default value or explicitly passed to the constructor.

from astropy.coordinates import SkyCoord,FK5
import astropy.units as u
cfk5_default = SkyCoord(1 * u.deg, 0 * u.deg, frame='fk5')
cfk5_J2000 = SkyCoord(1 * u.deg, 0 * u.deg, frame='fk5', equinox='J2000')
cfk5_B1950 = SkyCoord(1 * u.deg, 0 * u.deg, frame='fk5', equinox='B1950')
print(cfk5_default,cfk5_J2000,cfk5_B1950,sep='\n')

The print claims that both cfk5_default and cfk5_J2000 are equinox J2000

<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
    ( 1.,  0.)>
<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
    ( 1.,  0.)>
<SkyCoord (FK5: equinox=B1950.000): (ra, dec) in deg
    ( 1.,  0.)>

But when an equinox=1950 coordinate is transformed to the cfk5_default frame, the equinox remains 1950.

print("Transformed:")
print(cfk5_B1950.transform_to(cfk5_default))
print(cfk5_B1950.transform_to(cfk5_J2000))
Transformed:
<SkyCoord (FK5: equinox=B1950.000): (ra, dec) in deg
    ( 1.,  -2.32615580e-17)>
<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
    ( 1.64050073,  0.27831554)>

Activity

  1. dmopalmer commented on Jan 22, 2017

    @dmopalmer
    ContributorAuthor

    This seems to be related to #3106 where @eteq @taldcroft @cdeil @astrofrog agreed that this behavior is what it should be. It is in the transform_to() documentation.

    The frame attributes (e.g. equinox or obstime) for the returned object depend on the corresponding attributes of SkyCoord object and the supplied frame, with the following precedence:

    Non-default value in the supplied frame
    Non-default value in the SkyCoord instance
    Default value in the supplied frame

    So how can I deal with this and transform from original to other and get something in the other frame? Is there a function that yields a frame with default values made explicit?

    Should we add a flag to transform_to(...,taking_destination_defaults=) or make a new function transform_to_taking_destination_defaults() (names to be discussed)?

    As it is now:

    c0x = c0.transform_to(c1)
    assert c0x.is_equivalent_frame(c1)
    

    will sometimes fail.

  2. dmopalmer commented on Jan 22, 2017

    @dmopalmer
    ContributorAuthor

    Also, the documentation block from the SkyCoord.transform_to() documentation should be replicated in the BaseCoordinateFrame.transform_to() documentation.

  3. added 2 commits that reference this issue on Jan 22, 2017
  4. taldcroft commented on Jan 23, 2017

    @taldcroft
    Member

    So how can I deal with this and transform from original to other and get something in the other frame? Is there a function that yields a frame with default values made explicit?

    The simple solution is to explicitly specify the attributes you care about. But doing this is a generic way is not possible with an existing method, but is straightforward with access to private attributes:

    In [48]: c = SkyCoord(1 * u.deg, 0 * u.deg, frame='fk5')
    
    In [49]: print(c._equinox)
    None
    
    In [50]: for attr in c.frame_attributes:
        ...:     setattr(c, '_' + attr, getattr(c, attr))
        ...:     
    
    In [51]: print(c._equinox)
    J2000.000
    
    In [52]: print(c.equinox)
    J2000.000
    

    So maybe we could add a method like harden_attributes which does the simple loop above and has the effect of making "soft attributes" that derive from defaults turn into "hard attributes" which were explicitly set by the user.

  5. added a commit that references this issue on Jan 31, 2017
  6. added a commit that references this issue on Feb 17, 2017
  7. mhvk commented on Mar 4, 2017

    @mhvk
    Contributor

    fixed by #5723

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions