Skip to content

Slicing and subscript operator for skyfield.api.Star #1091

@bryan-lunt

Description

@bryan-lunt

When we load a Star object from a pandas dataframe, it ends up acting like an array or container for multiple values. It behaves as a list of stars.

It would be nice to be able to subscript it, slice it, etc. the same way we can a Time object that contains multiple times.

For now, I have a function:

def get_one_star(st,i):
            return skyfield.api.Star(ra_hours = st.ra.hours[i],
                                    dec_degrees = st.dec.degrees[i],
                                    ra_mas_per_year=st.ra_mas_per_year[i],
                                    parallax_mas=st.parallax_mas[i],
                                    epoch=st.epoch[i]
                                )

But it would feel much more natural to do something like:

one_star = stars_from_dataframe[i]

The advantage of adding this to the API and putting the responsibility onto Skyfield is that if you change the contents and fields of Star later, then any code which uses the subscript operator will automagically benefit, without the user needing to read the and understand the inner workings of the objects.

More broadly speaking, there are many objects in Skyfield that can either act as a single thing or act as a numpy-like array of things. It would be nice if any of the ones that act as an array, when acting as an array, could be sliced or subscripted. Otherwise we end up needing to subscript every one of their fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions