pyconform.indexing

Indexing Functions

The ‘index_str’ method gives a compact string representation of an indexing object (i.e., an object returned by the Numpy.index_exp[] method).

>>> idx = numpy.index_exp[1:2:3, 4]
>>> index_str(idx)
'1:2:3, 4'

The ‘join’ operation in this module is designed to reduce multiple slicing operations, where consecutive slices are reduced to a single slice:

A[slice1][slice2] = A[slice12]

Most Python programmers that work with Numpy have been told that slicing an array results in a ‘view’ of the array. Namely, they have been told that slicing the array costs nothing, so multiple consecutive slices need no reduction.

While this statement is true for in-memory (Numpy) arrays, array-like access to data stored on file (NetCDF, for example) presents a problem. The first slice of the file-storaged data results in an I/O read operation which returns an in-memory (Numpy) array, and the second slice results in a view of that array. The I/O operation can be costly, so it is worth our time to invest in a way of reducing the amount of data read, as well as limiting the possibility of overrunning memory with a large read.


Copyright 2017-2020, University Corporation for Atmospheric Research LICENSE: See the LICENSE.rst file for details

pyconform.indexing.align_index(index, dimensions)[source]

Compute an index tuple or dictionary with indices aligned according to dimension name

Parameters
  • index – An index or a dictionary of indices keyed by dimension name

  • dimensions (tuple) – A tuple of named dimensions for each axis of the data

pyconform.indexing.index_str(index)[source]

Convert an index expression into a compact string

pyconform.indexing.index_tuple(index, ndims)[source]

Generate an index tuple from a given index expression and number of dimensions

pyconform.indexing.join(shape0, index1, index2)[source]

Join two index expressions into a single index expression

Parameters
  • shape0 – The shape of the original array

  • index1 – The first index expression to apply to the array

  • index2 – The second index expression to apply to the array