Support fancy indexing
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:
- Use
NDCube.axis_world_coordsto 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. - Only produce tabular transformations for the axes that are fancy indexed. Use
CompositeWCSto combine the fancy indexed tabulated transformations with the those unaffected by the fancy indexing.CompositeWCSis slow, but may be more memory efficient in some cases. - 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_pathto get the world coordinates of all pixels along a path in the spatial plane of anNDCube. - Use
NDCube.wcs.world_to_array_indicesto 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),...))
@Cadair @sageyu123, let me know what you think of this summary of our discussion