Skip to content

Problem with base classes for coordinate-frame classes needing to have name #11096

Closed

Description

@ayshih

A recent code change in #11090 is causing errors in SunPy:

# Deal with setting the name of the frame:
if not hasattr(cls, 'name'):
cls.name = cls.__name__.lower()
elif (BaseCoordinateFrame not in cls.__bases__ and
cls.name in [base.name for base in cls.__bases__]):
# This may be a subclass of a subclass of BaseCoordinateFrame,
# like ICRS(BaseRADecFrame). In this case, cls.name will have been
# set by init_subclass
cls.name = cls.__name__.lower()

We have a base class for a frame that does not have a name attribute, so the base.name access produces an error. It's easy enough to add a dummy name attribute to "fix" this on our side, but presumably the Astropy code needs some protection?

Activity

  1. adrn commented on Nov 27, 2020

    @adrn
    Member

    Ah, yes, an oversight on my part - oops! I'll submit a follow-up PR now, and add a regression test.

  2. adrn commented on Nov 27, 2020

    @adrn
    Member

    I'm assuming this is RotatedSunFrame? I'm a little confused about why it misses the first if clause then, if it doesn't have a defined name attribute?

  3. ayshih commented on Nov 27, 2020

    @ayshih
    ContributorAuthor

    The error does not occur directly with our RotatedSunFrame metaframe, but rather when it tries to dynamically create a coordinate frame. For example, RotatedSunFrame can create RotatedSunHeliographicStonyhurst, which has two base classes: the coordinate frame HeliographicStonyhurst and the non-coordinate-frame RotatedSunFrame. The problem is that the latter doesn't have the name attribute.

    Astropy's SkyOffsetFrame doesn't have an issue because that metaframe itself subclasses BaseCoordinateFrame, so will automatically have .name. I found that I needed RotatedSunFrame to not subclass BaseCoordinateFrame to work properly, although I don't currently recall why.

  4. adrn commented on Nov 28, 2020

    @adrn
    Member

    Hm. First off, I think that RotatedSunFrame should probably just subclass from BaseCoordinateFrame. I did some experiments with the Sunpy frames to figure out why that was failing before, and I think I now know why. For SkyOffsetFrame, we intentionally do not use the frame-specific representation information from the parent coordinate frame class because we wanted the SkyOffsetFrame to have the same (default) component names as the default representation class. So, for example, a SkyOffsetFrame with an ICRS origin expects lon, lat, distance not ra, dec, distance. But it looks like that is not how you want RotatedSunFrame to work: It looks like your tests expect RotatedSunFrame to have the same component names as the base frame? So, in the construction of the Rotated<framecls>'s in RotatedSunMeta, I think you need to copy the _frame_specific_representation_info from the frame class into members. See sunpy/sunpy#4691 for a possible solution (fingers crossed)

  5. ayshih commented on Nov 29, 2020

    @ayshih
    ContributorAuthor

    Thanks for fixing the bug in Astropy! Re RotatedSunFrame, I'll continue the discussion in SunPy PR.

  6. added a commit that references this issue on Nov 29, 2020
  7. mhvk commented on Nov 29, 2020

    @mhvk
    Contributor

    fixed by #11101

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