Utilities

Various utility functions.

class tofu.util.Vector(x_angle=0, y_angle=0, z_angle=0, position=None)[source]

A vector based on axis-angle representation.

tofu.util.determine_shape(args, path=None, store=False, do_raise=False)[source]

Determine input shape from args which means either width and height are specified in args or try to read the path and determine the shape from it. The default path is args.projections, which is the typical place to find the input. If store is True, assign the determined values if they aren’t already present in args. Return a tuple (width, height). If do_raise is True, raise an exception if shape cannot be determined.

tofu.util.get_filenames(path)[source]

Get all filenams from path, which could be a directory or a pattern for matching files in a directory.

tofu.util.get_filtering_padding(width)[source]

Get the number of horizontal padded pixels in order to avoid convolution artifacts.

tofu.util.get_first_filename(path)[source]

Returns the first valid image filename in path.

tofu.util.get_image_shape(filename)[source]

Determine image shape (numpy order) from file filename.

tofu.util.get_reconstructed_cube_shape(x_region, y_region, z_region)[source]

Get the shape of the reconstructed cube as (slice width, slice height, num slices).

tofu.util.get_reconstruction_regions(params, store=False, dtype=<class 'int'>)[source]

Compute reconstruction regions along all three axes, use dtype for as data type for x and y regions, z region is always float.

tofu.util.make_region(n, dtype=<class 'int'>)[source]

Make region in such a way that in case of odd n it is centered around 0. Use dtype as data type.

tofu.util.make_subargs(args, subargs)[source]

Return an argparse.Namespace consisting of arguments from args which are listed in the subargs list.

tofu.util.next_power_of_two(number)[source]

Compute the next power of two of the number.

tofu.util.range_list(value)[source]

Split value separated by ‘:’ into int triple, filling missing values with 1s.

tofu.util.read_image(filename)[source]

Read image from file filename.

tofu.util.restrict_value(limits, dtype=<class 'float'>)[source]

Convert value to dtype and make sure it is within limits (included) specified as tuple (min, max). If one of the tuple values is None it is ignored.

tofu.util.set_node_props(node, args)[source]

Set up node’s properties to args which is a dictionary of values.

tofu.util.setup_read_task(task, path, args)[source]

Set up task and take care of handling file types correctly.

tofu.util.tupleize(num_items=None, conv=<class 'float'>, dtype=<class 'tuple'>)[source]

Convert comma-separated string values to a num-items-tuple of values converted with conv.