RectGrid

class odl.RectGrid(*coord_vectors)

Bases: Set

An n-dimensional rectilinear grid.

A rectilinear grid is the set of points defined by all possible combination of coordinates taken from fixed coordinate vectors.

The storage need for a rectilinear grid is only the sum of the lengths of the coordinate vectors, while the total number of points is the product of these lengths. This class makes use of that sparse storage scheme.

See Notes for details.

__init__(*coord_vectors)[source]

Initialize a new instance.

Parameters

vec1,…,vecNarray-like

The coordinate vectors defining the grid points. They must be sorted in ascending order and may not contain duplicates. Empty vectors are not allowed.

Examples

>>> g = RectGrid([1, 2, 5], [-2, 1.5, 2])
>>> g
RectGrid(
    [ 1.,  2.,  5.],
    [-2. ,  1.5,  2. ]
)
>>> g.ndim  # number of axes
2
>>> g.shape  # points per axis
(3, 3)
>>> g.size  # total number of points
9

Grid points can be extracted with index notation (NOTE: This is slow, do not loop over the grid using indices!):

>>> g = RectGrid([-1, 0, 3], [2, 4, 5], [5], [2, 4, 7])
>>> g[0, 0, 0, 0]
array([-1.,  2.,  5.,  2.])

Slices and ellipsis are also supported:

>>> g[:, 0, 0, 0]
RectGrid(
    [-1.,  0.,  3.],
    [ 2.],
    [ 5.],
    [ 2.]
)
>>> g[0, ..., 1:]
RectGrid(
    [-1.],
    [ 2.,  4.,  5.],
    [ 5.],
    [ 4.,  7.]
)

Notes

In 2 dimensions, for example, given two coordinate vectors

v_1 = (-1, 0, 2),\ v_2 = (0, 1)

the corresponding rectilinear grid G is the set of all 2d points whose first component is from v_1 and the second component from v_2:

G = \{(-1, 0), (-1, 1), (0, 0), (0, 1), (2, 0), (2, 1)\}

Here is a graphical representation:

   :    :        :
   :    :        :
1 -x----x--------x-...
   |    |        |
0 -x----x--------x-...
   |    |        |
  -1    0        2

Apparently, this structure can represent grids with arbitrary step sizes in each axis.

Note that the above ordering of points is the standard 'C' ordering where the first axis (v_1) varies slowest. Ordering is only relevant when the point array is actually created; the grid itself is independent of this ordering.