Support fancy indexing

Open
#647 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with NDCube.axis_world_coords and NDCube.wcs.world_to_array_indices, then review sunpy/map/maputils.py and its pixelate_coord_path workflow. Implement the decided option 1 using tabular coordinate transformations for the tuple of slices and index arrays, returning a new NDCube that supports the motivating path-extraction workflow.

Written by the indexing model from the issue text.

Description

Describe the feature

Provide a function that takes an NDCube and a tuple of slice items and/or arrays of array indices and returns a new NDCube. As fancy indexing is not suitable for all underlying data array representations (e.g. dask), this should be a function rather than a method on NDCube.

Proposed solution

The bulk of the work in developing this functionality is building the new WCS. Fancy indexing enables discontinuities in the coordinate transformations. We foresee the following paths forward:

  1. Use NDCube.axis_world_coords to get tables of all the coordinates, and then produce a tabular gWCS object using the fancy index inputs. Do this for all axes, even if the original transformation could be maintained in some cases. This makes the implementation easier, but inefficient for large resultant cubes.
  2. Only produce tabular transformations for the axes that are fancy indexed. Use CompositeWCS to combine the fancy indexed tabulated transformations with the those unaffected by the fancy indexing. CompositeWCS is slow, but may be more memory efficient in some cases.
  3. Develop a new WCS implementation that wraps a FITS-WCS within a gWCS model. @Cadair thinks this is a tractable amount of work, but is probably a longer term goal.
Decision

For the first version of this functionality, pursue option 1.

Motivating Use Case

Ability to produce N-D time/frequency/polarisation-distance plots. This functionality will enable this to be acheived by the following work-flow:

  • Use sunpy.map.maputils.pixelate_coord_path to get the world coordinates of all pixels along a path in the spatial plane of an NDCube.
  • Use NDCube.wcs.world_to_array_indices to get the array indices of the path
  • Build a slice item tuple valid of the cube, e.g. (path_indices_x, path_indices_y, slice(None),...) (assuming the spatial dimensions are the first two array axes)
  • Extract pixels along path, retaining other dimensions in new (N-1)-D cube: new_cube = fancy_index_ndcube(old_cube, (path_indices, slice(None),...))
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.