Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A concept of "Global Coordinates" #284

Closed
Cadair opened this issue Sep 22, 2020 · 12 comments · Fixed by #323
Closed

A concept of "Global Coordinates" #284

Cadair opened this issue Sep 22, 2020 · 12 comments · Fixed by #323
Assignees
Projects
Milestone

Comments

@Cadair
Copy link
Member

Cadair commented Sep 22, 2020

The rework of extra coords in #271 excludes one use case for the extra_coords dict in 1.0, which is the concept of structured metadata describing the coordinates of the whole cube. i.e. "this (x,y,t) cube is at wavelength y nm".

We should consider adding some kind of functionality to NDCube 2.0 to represent these type of coordinates.

(N.B. this is something that could potentially be upstreamed into the APE 14 WCS interface at some point)

@Cadair
Copy link
Member Author

Cadair commented Sep 28, 2020

A conversation at the PyHC meeting means we should consider this as a way to represent spacecraft location and maybe frame info.

@DanRyanIrish
Copy link
Member

Would this be attached to the WCS?

@kakirastern
Copy link

Will start working on this issue shortly...

@DanRyanIrish
Copy link
Member

Thanks @kakirastern!

@kakirastern
Copy link

Yeah, this would be a really great feature to have for Astropy conforming to the APE 14 WCS

@kakirastern
Copy link

Thanks @DanRyanIrish for the assignment. I will take it up later today HKT during the weekly community meeting.

@DanRyanIrish
Copy link
Member

DanRyanIrish commented Nov 9, 2020

In the case of slicing out axes, the coord value at which the slice was made will be stored in this sliced_low_level_wcs property from astropy 4.2: https://github.com/astropy/astropy/pull/10195/files#diff-3976bdca12d482d3c3b404875b2db43f9cb04a37f674e17089d3520cced2a72dR157

Something similar must be implemented in the new ExtraCoords class.

So point of GlobalCoords is to expose this information as high level objects, e.g. SkyCoord

Need an API for users to add global coords explicitly.

Draft API

  • Make a GlobalCoords class and attach to NDCube.
  • When asked, GlobalCoords compiles the dropped wcs coords, dropped extra coords, and user added coords into single object, e.g. dictionary/set, etc
  • Index GlobalCoords like a dictionary, index with a name
  • A global coord is made of three pieces of info: name, physical type, value (high level object)
  • When compiling list of global coords, coord name defaults to wcs.world_axis_name/CNAME (in FITS WCS). If not present, make name physical type. If physical type not unique, append physical type with unique suffix.

Methods/Properties

  1. .add
  2. .remove
  3. .names and/or .keys()
  4. .values (like dict) that gives a list of the higher level objects in the same order as .names/.keys()
  5. .physical_types that gives a list of the higher level objects in the same order as .names/.keys()
  6. __getitem__ (This should only take a single string, i.e. a coord name)

@Cadair
Copy link
Member Author

Cadair commented Nov 9, 2020

from collections.abc import Mapping


class GlobalCoords(Mapping):
    """
    A structured representation of coordinate information applicable to a whole NDCube.
    """
    def __init__(self, ndcube):
        pass

    def add(self, name, physical_type):
        """
        Add a new coordinate to the collection.
        """

    def remove(self, name):
        """
        Remove a coordinate from the collection
        """

    @property
    def names(self):
        """
        A tuple of all the names.
        """

    @property
    def physical_types(self):
        """
        A tuple of all physical types, one per coordinate.
        """

    def keys(self):
        """
        A set-like of all names in this collection.
        """

    def values(self):
        """
        A set-like of all values in this collection
        """

    def __getitem__(self, item):
        """
        Index the collection by a name.
        """

    def __iter__(self):
        pass

Should implement the whole Mapping API. What this means is that we only need to implement the methods listed in the "Abstract Methods" column (__getitem__, __iter__, __len__) and the ones listed in "Mixin methods" use those implementations to provide things like values().

@kakirastern
Copy link

Will start working on this today HKT

@kakirastern
Copy link

How about adding an update() besides add() and remove()for GlobalCoords? Or am I complicating things?

@Cadair
Copy link
Member Author

Cadair commented Nov 11, 2020

update is a dict-like API, the issue is that as well as the key (name) we also have physical type which needs to be present, hence sticking with Mapping and custom add and remove methods, rather than MutableMapping.

@kakirastern
Copy link

I see. Thanks for the clarification ❤️!

@DanRyanIrish DanRyanIrish moved this from To do to In Progress Issues in ndcube 2.0 Nov 11, 2020
ndcube 2.0 automation moved this from In Progress Issues to Done Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
ndcube 2.0
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants