SamplingOperator

class odl.SamplingOperator(*args, **kwargs)

Bases: Operator

Operator that samples coefficients.

The operator is defined by

SamplingOperator(f) == c * f[sampling_points]

with the weight c being determined by the variant. By choosing c = 1, this operator approximates point evaluations or inner products with Dirac deltas, see option variant='point_eval'. By choosing c = cell_volume, it approximates the integration of f over the indexed cells, see option variant='integrate'.

__init__(domain, sampling_points, variant='point_eval')[source]

Initialize a new instance.

Parameters

domainTensorSpace

Set of elements on which this operator acts.

sampling_points1D array-like or sequence of 1D array-likes

Indices that determine the sampling points. In n dimensions, it should be a sequence of n arrays, where each member array is of equal length N. The indexed positions are (arr1[i], arr2[i], ..., arrn[i]), in total N points. If domain is one-dimensional, a single array-like can be used. Likewise, a single point can be given as integer in 1D, and as a array-like sequence in nD.

variant{‘point_eval’, ‘integrate’}, optional

For 'point_eval' this operator performs the sampling by evaluation the function at the sampling points. The 'integrate' variant approximates integration by multiplying point evaluation with the cell volume.

Examples

Sampling in 1d can be done with a single index (an int) or a sequence of such:

>>> space = odl.uniform_discr(0, 1, 4)
>>> op = odl.SamplingOperator(space, sampling_points=1)
>>> x = space.element([1, 2, 3, 4])
>>> op(x)
rn(1).element([ 2.])
>>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1])
>>> op(x)
rn(3).element([ 2.,  3.,  2.])

There are two variants 'point_eval' (default) and 'integrate', where the latter scales values by the cell volume to approximate the integral over the cells of the points:

>>> op = odl.SamplingOperator(space, sampling_points=[1, 2, 1],
...                           variant='integrate')
>>> space.cell_volume  # the scaling constant
0.25
>>> op(x)
rn(3).element([ 0.5 ,  0.75,  0.5 ])

In higher dimensions, a sequence of index array-likes must be given, or a single sequence for a single point:

>>> space = odl.uniform_discr([0, 0], [1, 1], (2, 3))
>>> # Sample at the index (0, 2)
>>> op = odl.SamplingOperator(space, sampling_points=[0, 2])
>>> x = space.element([[1, 2, 3],
...                    [4, 5, 6]])
>>> op(x)
rn(1).element([ 3.])
>>> sampling_points = [[0, 1, 1],  # indices (0, 2), (1, 1), (1, 0)
...                    [2, 1, 0]]
>>> op = odl.SamplingOperator(space, sampling_points)
>>> op(x)
rn(3).element([ 3.,  5.,  4.])