hnccorr.utils module¶
Helper functions for HNCcorr.
-
hnccorr.utils.
add_offset_set_coordinates
(iterable, offset)[source]¶ Adds a fixed offset to all pixel coordinates in a set.
- Parameters
coordinates (set) – Set of pixel coordinates. Each pixel coordinate is a tuple.
offset (tuple) – Offset to add to each pixel coordinate. Tuple should be of the same length as the tuples in coordinates.
- Returns
Set of updated coordinates.
- Return type
set
Example
>>> add_offset_set_coordinates({(5, 2), (4, 7)}, (2, 2)) {(7, 4), (6, 9)}
-
hnccorr.utils.
add_offset_to_coordinate
(coordinate, offset)[source]¶ Offsets pixel coordinate by another coordinate.
- Parameters
coordinate (tuple) – Pixel coordinate to offset.
offset (tuple) – Offset to add to coordinate. Must be of the same length.
Example
>>> add_offset_to_coordinate((5, 3, 4), (1, -1, 3)) (6, 2, 7)
-
hnccorr.utils.
add_time_index
(index)[source]¶ Inserts a full slice as the first dimension of an index for e.g. numpy.
- Parameters
index (tuple) – Index for e.g. numpy array.
- Returns
New index with additional dimension.
- Return type
tuple
Example
>>> add_time_index((5, :3)) (:, 5, :3)
-
hnccorr.utils.
eight_neighborhood
(num_dims, max_radius)[source]¶ Returns all coordinates within a given L-infinity distance of zero.
Includes zero coordinate itself.
- Parameters
num_dims (int) – Number of dimensions for the coordinates.
max_radius (int) – Largest L-infinity distance allowed.
- Returns
Set of pixel coordinates.
- Return type
set
Example
>>> eight_neighborhood(1, 1) [(-1,), (0,), (1,)] >>> eight_neighborhood(2, 1) [ (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1) ]
-
hnccorr.utils.
four_neighborhood
(num_dims)[source]¶ Returns all neighboring pixels of zero that differ in at most one coordinate.
Includes zero coordinate itself.
- Parameters
num_dims (int) – Number of dimensions for the coordinates.
- Returns
Set of pixel coordinates.
- Return type
set
Example
>>> four_neighborhood(1) [(-1,), (0,), (1,)] >>> eight_neighborhood(2) [(-1, 0), (0, -1), (0, 0), (0, 1), (1, 0)]
-
hnccorr.utils.
generate_pixels
(shape)[source]¶ Enumerate all pixel coordinates for a movie/patch.
- Parameters
shape (tuple) – Shape of movie. Number of pixels in each dimension.
- Returns
Iterates over all pixels.
- Return type
Iterator
Example
>>> generate_pixels((2,2)) [(0, 0), (0, 1), (1, 0), (1, 1)]
-
hnccorr.utils.
list_images
(folder)[source]¶ Lists and sorts tiff images in a folder.
Images are sorted in ascending order based on filename.
Caution
Filenames are sorted as strings. Note that
200.tiff
is sorted before5.tiff
. Pad image filenames with zeros to prevent this:005.tiff
.- Parameters
folder – folder containing tiff image files.
- Returns
Sorted list of paths of tiff files in folder.
- Return type
list