Allow greater flexibility in crop bounds order

Open
#608 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start at the NDCube crop method and inspect how SkyCoord and SpectralCoord bounds are matched to WCS axes. Reproduce the two ordering examples from the issue, including a spectral axis in the middle if supported by the WCS, and verify that valid bounds no longer fail solely because their coordinate types are ordered differently.

Written by the indexing model from the issue text.

Description

Describe the feature

I recently noticed while doing some work in specutils (see https://github.com/astropy/specutils/pull/1033/files#r1134253955) that when providing both a sky coordinate and spectral coordinate as bounds to the NDCube crop method, the physical types need to be in the same order as they appear in the WCS. For example, if the spectral axis is last in the WCS, you can do this:

   >>> lower = [SkyCoord(ra=205, dec=26, unit=u.deg), SpectralCoord(4.9, unit=u.um)]
   >>> upper = [SkyCoord(ra=205.5, dec=27.5, unit=u.deg), SpectralCoord(4.9, unit=u.um)]

but not this:

    >>> lower = [SpectralCoord(4.9, unit=u.um), SkyCoord(ra=205, dec=26, unit=u.deg)]
    >>> upper = [SpectralCoord(4.9, unit=u.um), SkyCoord(ra=205.5, dec=27.5, unit=u.deg)]

It seems like it shouldn't matter in what order the SpectralCoord and SkyCoord are provided, since in the WCS it's unambiguous which axes these apply to. I'm also not sure what would happen if you had the spectral axis in the middle of the WCS, (e.g., [RA, Wavelength, Dec]), which seems silly but isn't impossible. I propose adding some logic to make this a little more flexible and avoid the error trace that occurs currently if the bounds are provided out of order (I don't have the trace on hand right now, unfortunately, I can add it here later).

Proposed solution

No response

Dominant language
Python
Stars
49
Forks
56
Avg merge
5h 54m
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sunpy/ndcube

All issues in sunpy/ndcube

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.