Skip to content

Convenience attributes for accessing world-axis-specific information #811

Open

Description

@DanRyanIrish

Describe the feature

A deliberate design decision of ndcube was to make its functionality valid for any number of axes and combination of physical types. While this has generally been a success and strength, multiple instances of user feedback have highlighted the desire for a simpler and more intuitive way of accessing coordinate values for common, well-known physical types. These include spectral, spatial/celestial, time, and stokes.

This issue provide a place where thoughts on the design of such an interface can be hashed out. Two starting suggestions include:

Proposed solution

A coords class that can be attached to an NDCube, e.g. cube.coords, which introduces sets of APIs for specific world axis types. This can be used to incorporate various APIs, such as some provided by classes like sunpy.map.Map. Each world axis API can exist under its own class and accessed via a named attribute on the coords class. These can include:

  • coords.celestial
  • coords.spectral
  • coords.time
  • coords.stokes

These could have the following functionalities:

  • coords.celestial
    • .coords/.coords_values: Returns the coordinate values of all pixels as a SkyCoord. Shortcut for NDCube.axis_world_coords / axis_world_coords_values.
    • coordinate_frame: returns a celestial coordinate frame object based on the WCS info.
    • .crop: Convenience method for NDCube.crop for cropping only along the celestial axes.
  • coords.spectral
    • .coords/.coords_values: Returns the coordinate values of all pixels as a SpectralCoord. Shortcut for NDCube.axis_world_coords / axis_world_coords_values.
    • .wavelength, .energy, .frequency: Returns the coordinate values of pixels as wavelength, energy or frequency.
    • .wavelength_unit, .energy_unit, .frequency_unit: The unit in which each property is returned. Can be set by the user.
    • .crop: Convenience method for NDCube.crop for cropping only along the wavelength axis/axes.
  • coords.time:
    • .coords/.coords_values: Returns the coordinate values of all pixels as a Time. Shortcut for NDCube.axis_world_coords / axis_world_coords_values.
    • .crop: Convenience method for NDCube.crop for cropping only along the time axis/axes.
  • coords.stokes
    • .coords/.coords_values: Returns the coordinate values of all pixels as a StokesCoord. Shortcut for NDCube.axis_world_coords / axis_world_coords_values.
    • I, Q etc (all possible options depending on what's in the WCS) to crop the cube to that component.

More thoughts to follow...

Other related functionalities that aren't necessarily world axis specific:

  • .observer_coordinate: A SkyCoord giving the location of the observer, if such information is inferrable from the WCS. (Is this already available from APE-14 wcses?)
  • .light_travel_time(): Takes in a SkyCoord and returns the difference in light travel time between an origin and the input location(s), relative to that between the origin and observer location.
    • If origin not provided, its default is the observer coordinate.
    • There's a question of how to handle the case where the SkyCoords have different obstimes. Perhaps a kwarg which allows only the locations to be considered, or also the difference in times to be included.
    • Perhaps something like this already does/should exist in astropy SkyCoord.

Activity

  1. Cadair commented on Feb 13, 2025

    @Cadair
    SponsorMember

    A related thought on this, it would be nice if you could access a view of the data and coordinate information which is "I want this world coord and a flat dimension of all the other ones". This could for example be used in spectral fitting where you might want to iterate over all the spectra, or in a time lag style computation where you want to iterate over all the timeseries.

  2. Cadair commented on Oct 1, 2026

    @Cadair
    SponsorMember

    @andyto1234 Do you have any thoughts on this?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions