sunpy / ndcube

A base package for multi-dimensional contiguous and non-contiguous coordinate-aware arrays. "Maintainers": @danryanirish & @Cadair
http://docs.sunpy.org/projects/ndcube/
BSD 2-Clause "Simplified" License
44 stars 45 forks source link

Support fancy indexing #647

Open DanRyanIrish opened 8 months ago

DanRyanIrish commented 8 months ago

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:

DanRyanIrish commented 8 months ago

@Cadair @sageyu123, let me know what you think of this summary of our discussion