dival.util.odl_utility module
Provides utilities related to ODL.
- dival.util.odl_utility.uniform_discr_element(inp, space=None)[source]
Generate an element of a ODL space from an array-like.
- Parameters:
inp (array-like) – The input data from which the element is generated.
space (
odl.discr.DiscretizedSpace, optional) – The space which the element will belong to. If not given, a uniform discretization space with cell size 1 centered around the origin is generated.
- dival.util.odl_utility.apply_noise(x, noise_type, noise_kwargs=None, seed=None, random_state=None)[source]
Apply noise to an odl element.
Calls noise functions from
odl.phantom.noiseor their equivalents fromdival.util.odl_noise_random_state.- Parameters:
x (odl element) – The element to which the noise is applied (in-place).
noise_type ({
'white','uniform','poisson','salt_pepper'}) – Type of noise.noise_kwargs (dict, optional) –
Keyword arguments to be passed to the noise function, e.g.
'stddev'for'white'noise. The arguments are:- for
noise_type='white': 'stddev': float, optionalStandard deviation of each component of the normal distribution. Default is 1.
'relative_stddev': bool, optionalWhether to multiply
'stddev'withmean(abs(x)). Default isFalse.
- for
- for
noise_type='poisson': 'scaling_factor': float, optionalIf specified, the intensity is multiplied and the samples from the poisson distribution are divided by this factor:
poisson(x * scaling_factor) / scaling_factor. Default is None.
- for
seed (int, optional) – Random seed passed to the noise function.
random_state (
np.random.RandomState, optional) – Random state passed to the noise function.
- class dival.util.odl_utility.NoiseOperator(*args, **kwargs)[source]
Bases:
OperatorOperator applying noise.
Wraps
apply_noise(), which calls noise functions fromodl.phantom.noiseor their equivalents fromdival.util.odl_noise_random_state.- __init__(domain, noise_type, noise_kwargs=None, seed=None, random_state=None)[source]
- Parameters:
space (odl space) – Domain and range.
noise_type ({
'white','uniform','poisson','salt_pepper'}) – Type of noise.noise_kwargs (dict, optional) – Keyword arguments to be passed to the noise function, cf. docs for
apply_noise().seed (int, optional) – Random seed passed to the noise function.
random_state (np.random.RandomState, optional) – Random state passed to the noise function.
- class dival.util.odl_utility.CallbackStore(results=None, function=None, step=1)[source]
Bases:
CallbackThis is a modified copy of odl.solvers.util.callback.CallbackStore, Copyright held by The ODL contributors, subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. This copy incorporates https://github.com/odlgroup/odl/pull/1539.
Callback for storing all iterates of a solver. Can optionally apply a function, for example the norm or calculating the residual. By default, calls the
copy()method on the iterates before storing.- __init__(results=None, function=None, step=1)[source]
Initialize a new instance.
- Parameters:
results (list, optional) – List in which to store the iterates. Default: new list (
[])function (callable, optional) – Deprecated, use composition instead. See examples. Function to be called on all incoming results before storage. Default: copy
step (int, optional) – Number of iterates between storing iterates.
Examples
Store results as-is: >>> callback = CallbackStore() Provide list to store iterates in: >>> results = [] >>> callback = CallbackStore(results=results) Store the norm of the results: >>> norm_function = lambda x: x.norm() >>> callback = CallbackStore() * norm_function
- class dival.util.odl_utility.CallbackStoreAfter(results=None, store_after_iters=None)[source]
Bases:
CallbackCallback for storing after specific numbers of iterations of a solver. Calls the
copy()method on the iterates before storing.The source code of this class is based on odl.solvers.util.callback.CallbackStore, Copyright held by The ODL contributors, subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
- class dival.util.odl_utility.ResizeOperator(*args, **kwargs)[source]
Bases:
Operator- __init__(reco_space, space, order=1)[source]
Initialize a new instance.
- Parameters:
domain (Set) – The domain of this operator, i.e., the set of elements to which this operator can be applied
range (Set) – The range of this operator, i.e., the set this operator maps to
linear (bool, optional) – If
True, the operator is considered as linear. In this case,domainandrangehave to be instances of LinearSpace, or Field.
- class dival.util.odl_utility.RayBackProjection(*args, **kwargs)[source]
Bases:
OperatorAdjoint of the discrete Ray transform between L^p spaces.
This class is copied and modified from odl.
This main-scope class definition is used by
patch_ray_trafo_for_pickling()to make a ray transform object pickleable by replacing its_adjointattribute with an instance of this class.- __init__(ray_trafo, **kwargs)[source]
Initialize a new instance.
- Parameters:
domain (Set) – The domain of this operator, i.e., the set of elements to which this operator can be applied
range (Set) – The range of this operator, i.e., the set this operator maps to
linear (bool, optional) – If
True, the operator is considered as linear. In this case,domainandrangehave to be instances of LinearSpace, or Field.
- property geometry
- property adjoint
Adjoint of this operator (abstract).
- Raises:
OpNotImplementedError – Since the adjoint cannot be default implemented.
- dival.util.odl_utility.patch_ray_trafo_for_pickling(ray_trafo)[source]
Make an object of type
odl.tomo.operators.RayTransformpickleable by overwriting the_adjoint(which originally has a local class type) with adival.util.torch_utility.RayBackProjectionobject. This can be required for multiprocessing.- Parameters:
ray_trafo (
odl.tomo.operators.RayTransform) – The ray transform to patch for pickling.