tomosipo.utils module
- tomosipo.utils.atleast_nd(array, ndmin)[source]
View input as array with at least ndmin dimensions.
This is different from numpy.atleast_1d/2d in that it prepends dimensions instead of appending them.
- tomosipo.utils.print_options()[source]
This context manager set numpy print options temporarily
ODL sets the numpy printoptions globally, which makes it difficult to ensure that the representation of geometries is consistent over different installations. Specifically, we want to ensure that testing succeeds regardless of the specific version of ODL.
- Returns:
- Return type:
- tomosipo.utils.slice_interval(left, right, length, key)[source]
Slice a one-dimensional interval
The line extends from left to right and is divided into length parts. It is indexed by a key which can be an int or a slice.
If the step size of key equals one, then slice_interval should works exactly as expected.
When the step size is greater than one, there are two equally valid approaches to slicing:
Take the left-most and right-most pixel of the slice and set the size of the resulting interval to be equal to the difference between their left- and right-most edge, respectively.
Multiply the pixel size by the step size and ensure the size of the new interval equals new_len * new_pixel_size.
This function implements the second approach.
The first approach has the disadvantage that the new pixel size is not an integer multiple of the original pixel size. Moreover, it is not compatible with the way that we want to use this function as a way to bin detector pixels.
The second approach has the disadvantage that the new values for left and right might fall outside the original interval, which is counter-intuitive. Nonetheless, it is compatible with detector and volume binning.
Example. Suppose we have the interval [0, 4] divided into four pixels. An illustration of the interval is shown below, with | denoting the edges of the pixels. As you can see, with a step size of two, the pixels become twice as large, and depending on the start of the slice, the interval is shifted to the left or right. With a step size of 3, the resulting interval is larger than the original interval.
|x|x|x|x| [0:4:1] | x | x | [0:4:2] | x | x | [1:4:2] | x | x | [0:4:3]
- Parameters:
left – scalar or np.array
right – scalar or np.array
length – int
key – slice or int
- Returns:
A tuple containing the new left and right extent of the line, the number of “pixels”, and the new “pixel” size.
- Return type:
(scalar, scalar, int, scalar)
- tomosipo.utils.up_slice(key)[source]