developer.python.indexing

From autoplot.org

Jump to: navigation, search

Purpose: define behavior of PyQDataSet.__getItem__(x) for all x. We wish to have indexing similar to IDL and Matlab indexing, so scripts can be ported and to reduce confusion. We wish to have strongly-typed index lists as QDataSets, so that for example, the output of "where" can be used to index data.

Index Types:

  • Python or Java scalar
  • Python or Java array
  • Python slice (QDataSet trim)
  • Rank 0 QDataSet for slicing.
  • Rank N QDataSet
  • "index trim" descriptor QDataSet
  • "indexes list" QDataSet

The expression SRC[IDX] will result in the following:

Contents

  1. IDX is scalar, array, or N-index array
  2. IDX= rank 0 dataset
  3. IDX=rank 1 dataset
  4. IDX=rank N dataset with geometry G
  5. IDX=rank 2 qube dataset with qube size=[N,R] with BUNDLE_1 set. ("indexes list")
  6. IDX is a tuple (SRC(IDX0,IDX1,...,IDXR))
  7. Notes

1 IDX is scalar, array, or N-index array

Coerce to QDataSet, use that logic.

2 IDX= rank 0 dataset

SRC=rank 0 dataset: rank limit exception.

SRC=rank 1 dataset: return scalar (not rank 0 dataset) at the index.

SRC=rank N dataset: return slice at the index.

Note for Rank 3 dataset, SRC[0] is equivalent to SRC[0,:,:]

3 IDX=rank 1 dataset

SRC=rank 0 dataset: rank limit exception.

SRC=rank 1 dataset: return rank 1 dataset that is the subset.

SRC=rank N dataset: return rank N dataset that is the join of the slices at each index.

4 IDX=rank N dataset with geometry G

SRC=rank 0 dataset: rank limit exception.

SRC=rank 1 dataset: return rank N dataset with geometry G, with values from rank 1 dataset.

SRC=rank 2 dataset: rank limit exception.

5 IDX=rank 2 qube dataset with qube size=[N,R] with BUNDLE_1 set. ("indexes list")

SRC=rank 0 dataset: rank limit exception.

SRC=rank 1 dataset and R=1: return rank 1 dataset that is the subset containing N points.

SRC=rank R dataset: return rank 1 dataset that is the subset containing N points.

Notes: BUNDLE_1 should have length R. length(i)=0 (bundle of rank 1). property(VALID_MAX,i)=ds.length might be used to hint at the dimension size it should index. property( FILL,0 )=ds.length

6 IDX is a tuple (SRC(IDX0,IDX1,...,IDXR))

  • if R does not equal SRC rank, rank exception.
  • If each IDXi is a rank 0 dataset (scalar), return the value at this index.
  • For each IDXi, if IDXi is a rank 0 dataset, perform the slice on this dimension.
  • For each IDXi, if IDXi is a trim (slice in python, rank 1 bins dataset in QDataSet), perform the trim on this dimension. This should also include the cases where an all-element slice is used (SRC[2,3,:]).
  • The remaining IDXi that are arrays of indexes must have the same geometry. The result dataset will have this geometry. (NOTE: this does not match IDL, for which this is only the case when all the indeces are arrays of indexes.)

7 Notes

Represent Python slice object (e.g. 3:11:2 in SRC[3:11:2]): rank 1 dataset. length=2. property(BINS_0)="min,max". value[0]=3. value[1]= 11. property(CADENCE)=2. A value > property(VALID_MAX) indicates the start or stop is implicitly 0 or length.

Personal tools