Skip to content

Add Frame objects without data to a Table #16823

Closed

Description

@lpsinger

What is the problem this feature will solve?

Please make it possible to store Frame objects that do not have data in Astropy tables.

I am working on an Astropy-based observation planning and scheduling toolkit for space missions, primarily for tiled imaging observations with wide-field cameras. A natural way for my code to represent the fields to observe is as SkyOffsetICRS objects without any attached data: these objects represent the RA, Dec, and roll of the spacecraft for the observation.

I would like my code to be able to save the planned timeline of observations as a Table which has a column of type SkyOffsetICRS. However, I find that Astropy does not allow me to do this. Here's a minimal reproducer:

from astropy.coordinates import SkyCoord, SkyOffsetFrame
from astropy.table import Table
from astropy import units as u
import numpy as np

ra = [1, 2, 3] * u.deg
de = [4, 5, 6] * u.deg
pa = [7, 8, 9] * u.deg

# SkyOffsetFrame with dummy values is happy, but it's not what I want.
dummy = np.zeros(3) * u.deg
frame_with_dummy_data = SkyOffsetFrame(
    dummy, dummy, origin=SkyCoord(ra, de), rotation=pa)
Table({'frame': frame_with_dummy_data})

# SkyCoord with dummy values is happy, but it's not what I want either.
dummy_coord_with_frame = SkyCoord(
    dummy, dummy, frame=SkyOffsetFrame(origin=SkyCoord(ra, de), rotation=pa))
Table({'coord': dummy_coord_with_frame})

# This is what I want: a bare frame with no data. But the Table constructor
# raises the following exception: `ValueError: The frame object
# "<SkyOffsetICRS ...>" does not have associated data`
frame = SkyOffsetFrame(origin=SkyCoord(ra, de), rotation=pa)
Table({'frame': frame})

Describe the desired outcome

Add support for adding Frame objects that do not have data as columns in tables.

Additional context

No response

Activity

  1. eerovaher commented on Aug 13, 2024

    @eerovaher
    Member

    Why does the SkyOffsetFrame need to be stored in a column? Is there some reason you can't store it in metadata?

  2. lpsinger commented on Aug 14, 2024

    @lpsinger
    ContributorAuthor

    Because my data is a series of many SkyOffsetFrames. Each planned observation is a row in the table, with a SkyOffsetFrame that represents the attitude of the telescope, a Time for the start of the observation, an exposure time, an integer to represent the observing mode, etc.

  3. mhvk commented on Aug 14, 2024

    @mhvk
    Contributor

    @lpsinger - I agree that should be possible. Looking at the traceback from what you actually want, a problem is that len(frame) does not work, but really it breaks down earlier: frame should be recognized as a mixin column, but isn't:

    from astropy.table import QTable
    qt = QTable()
    qt._is_mixin_for_table(frame)
    # False
    

    And the reason for that is that SkyOffsetFrame does not have an info attribute. That seems a pure oversight. But oddly, the oversight actually starts with BaseCoordinateFrame not having info either. As a result,

    from astropy.table import QTable
    from astropy import units as u
    from astropy.coordinates import ICRS
    
    icrs = ICRS(np.arange(10.)*u.deg, np.arange(10.)*u.deg)
    QTable({'icrs': icrs})
    <QTable length=10>
                           icrs                      
                          object                     
    -------------------------------------------------
    <ICRS Coordinate: (ra, dec) in deg\n    (0., 0.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (1., 1.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (2., 2.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (3., 3.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (4., 4.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (5., 5.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (6., 6.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (7., 7.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (8., 8.)>
    <ICRS Coordinate: (ra, dec) in deg\n    (9., 9.)>
    

    This is clearly wrong: it should have been an ICRS column.

  4. mhvk commented on Aug 14, 2024

    @mhvk
    Contributor

    A fix is in #16381 #16831 - was much more painful than I had hoped...

  5. lpsinger commented on Aug 14, 2024

    @lpsinger
    ContributorAuthor

    Do you mean #16831?

  6. mhvk commented on Aug 14, 2024

    @mhvk
    Contributor

    Indeed, silly, now corrected.

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