pairwisesingle

High level helper functions that deal with the alignment of a single pair of neighbours, written for use by the class pairwise alignment. Creates its own logger object when imported.

Functions: align_single_pair – Determine the ideal alignment between two

neighbouring tiles
refine_single_pair – Determine the ideal alignment between two
neighbouring tiles, with the use of an old alignment.
determine_overlap – Determine the overlap between two
neighbouring tiles
calculate_pos_shifts – Calulate possible shifts, given two
overlapping images.
find_best_trans – Find the best translation using the cross
covariance.
find_best_trans_corr – Find the best translation using the cross
correlation.
perform_upsampling – Perform upsampling for subpixel precision in
the shift
pysmFISH.stitching_package.pairwisesingle.align_single_compress_pic(overlap1, overlap2, nr_peaks, nr_dim, nr_slices, plot_order)[source]

Perform the alignment when using the 3D method “compress pic”

overlap1: np.array
Image that overlaps with overlap2
overlap2: np.array
Image that overlaps with overlap1
nr_peaks: int
The n highest peaks from the PCM matrix that will be used to do crosscovariance with. A good number for 2D analysis is 8 peaks and good numbers for 3D with method =’compress pic’ are 6 or 9 peaks.
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
nr_slices: int
Only applicable when running with 3D pictures and using ‘compres pic’ method. Determines the number of slices that are compressed together (compression in the z-direction).
plot_order: np.array
Numpy array, filled with ones. The order in wich subplots should be made if we want to plot overlap1 and 2
best_trans: np.array
1 by 3 array containing best found z, y and x translation.
best_cov: float
The covariance of the overlap after translation of the overlap by best_trans.
pysmFISH.stitching_package.pairwisesingle.align_single_pair(tiles, tile_file, contig_tuples, contig_ind, micData, nr_peaks, nr_dim=2, nr_slices=None)[source]

Determine the ideal alignment between two neighbouring tiles

tiles: list
List of strings. List of references to the the tiles in the hdf5 file tile_file.
tile_file: pointer
hdf5 file object. The opened file containing the tiles to stitch.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
contig_ind: int
The index of the current tile pair in contig_tuples. More precisely: the index of the tuple in contig_tuples containing the indexes of the tiles that should be aligned.
micData: object
MicroscopeData object. Should contain coordinates of the tile corners as taken from the microscope. These coordinates are used to dtermine the overlap between a tile pair.
nr_peaks: int
The n highest peaks from the PCM matrix that will be used to do crosscovariance with. A good number for 2D analysis is 8 peaks and good numbers for 3D with method =’compress pic’ are 6 or 9 peaks.
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
nr_slices: int
Only applicable when running with 3D pictures and using ‘compres pic’ method. Determines the number of slices that are compressed together (compression in the z-direction). If None, all the slices are compressed together. Default: None
best_trans: np.array
1 by 2 or 3 array containing best found (z), y and x translation.
best_cov: float
The covariance of the overlap after translation of the overlap by best_trans.
contig_ind: int
The index of the used tile pair in contig_tuples. This is necessary to return when running on multiple processors/cores. More precisely: the index of the tuple in contig_tuples containing the indexes of the tiles that should be aligned.
pysmFISH.stitching_package.pairwisesingle.align_single_pair_npy(contig_tuple, filtered_files_list, micData, nr_peaks=8)[source]

Determine the ideal alignment between two neighbouring tiles It is a modification of the align_single_pair function that will run in parallel using .npy image arrays. The functions runs only in 2D.

contig_tuple: tuple
Tuple containing two tile indexes denoting these tiles are contingent to each other.
filtered_files_list: list
List containing the paths to the files to porocess
micData: object
MicroscopeData object. Should contain coordinates of the tile corners as taken from the microscope. These coordinates are used to dtermine the overlap between a tile pair.
nr_peaks: int
The n highest peaks from the PCM matrix that will be used to do crosscovariance with. A good number for 2D analysis is 8 peaks and good numbers for 3D with method =’compress pic’ are 6 or 9 peaks.
best_trans: np.array
1 by 2 or 3 array containing best found (z), y and x translation.
best_cov: float
The covariance of the overlap after translation of the overlap by best_trans.
contig_ind: int
The index of the used tile pair in contig_tuples. This is necessary to return when running on multiple processors/cores. More precisely: the index of the tuple in contig_tuples containing the indexes of the tiles that should be aligned.
pysmFISH.stitching_package.pairwisesingle.calculate_pos_shifts(overlap1, overlap2, nr_peaks, nr_dim)[source]

Calulate possible shifts, given two overlapping images

overlap1: np.array
Image that overlaps with overlap2.
overlap2: np.array
Image that overlaps with overlap1.
nr_peaks: int
The number of peaks from the PCM that will be used to calculate shifts
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed.
unr_pos_transistions: np.array
Numpy array or list (list only when method == ‘compress pic’ and nr_dim == 3 ) Numpy array numpy arrays of int, with each of the inner arrays containing the (z), x and y translation, if nr_dim is not 3 only x and y translation are given. If method == ‘compress pic’ and nr_dim == 3 a list of 3 lists is returned. In each list the best translations for each compressed picture are given as numpy arrays of length 2.
pysmFISH.stitching_package.pairwisesingle.determine_overlap(ind1, ind2, tile_1, tile_2, micData)[source]

Determine the overlap between two neighbouring tiles

ind1: int
Index (flattened) of tile 1
ind2: int
Index (flattened) of tile 2
tile_1: np.array
Image 1
tile_2: np.array
Image 2
micData: object
MicroscopeData object containing coordinates
overlap1: np.array
Overlapping part of tile_1
overlap2: np.array
Overlapping part of tile_2
plot_order: np.array
Numpy array of ones. The shape of this array is used for plotting the overlaps in well fitting subplots.
pysmFISH.stitching_package.pairwisesingle.find_best_trans(pos_transistions, overlap1, overlap2, plot_order)[source]

Find the best translation using the cross covariance.

Shift overlap according to translations and test the cov of the translated overlaps.

pos_transistions: np.array
2D numpy array. Array containing y,x-pairs denoting the possible translations.
overlap1: np.array
Image
overlap2: np.array
Image that overlaps with overlap1.
plot_order: np.array
The shape of this array denotes the order in wich subplots should be made if we want to plot overlap1 and 2.
best_trans: np.array
1 by 2 or 3 array containing best found (z), y and x translation.
best_cov: float
The covariance of the overlap after translation of the overlap by best_trans.
pysmFISH.stitching_package.pairwisesingle.plot_overlaps(alignment, tiles, contig_tuples, micData)[source]

Plot the pairwise overlaps

alignment: dict
Dictionary containing key ‘P’ with a flattened list of translations.
tiles: list
List of strings. Each string points to a tile in the hdf5 file.
contig_tuples: list
List of tuples denoting which tiles are contingent to each other.
micData: object
MicroscopeData object containing coordinates.

Should be tested and made to work in 3D ?_?

pysmFISH.stitching_package.pairwisesingle.refine_single_pair(tiles, tile_file, contig_tuples, contig_ind, micData, old_P, nr_peaks, nr_dim=2, nr_slices=None)[source]

Determine the ideal alignment between two neighbouring tiles.

Uses an old alignment as starting point. Meant to use on smFISH signal data, where the old alignment is taken from the aligning of the nuclei staining.

tiles: list
List of strings. List of references to the the tiles in the hdf5 file tile_file.
tile_file: pointer
hdf5 file object. The opened file containing the tiles to stitch.
contig_tuples: list
List of tuples. Each tuple is a tile pair. Tuples contain two tile indexes denoting these tiles are contingent to each other.
contig_ind: int
The index of the current tile pair in contig_tuples. More precisely: the index of the tuple in contig_tuples containing the indexes of the tiles that should be aligned.
micData: object
MicroscopeData object. Should contain coordinates of the tile corners as taken from the microscope. These coordinates are used to dtermine the overlap between a tile pair.
old_P: dict
An old pairwise alignment containing a key ‘P’ containing a flattened list of 2D or 3D pairwise translations. And containing a key ‘covs’ containing the normalized cross covariance for each alignment.
nr_peaks: int
The n highest peaks from the PCM matrix that will be used to do crosscovariance with. A good number for 2D analysis is 8 peaks and good numbers for 3D with method =’compress pic’ are 6 or 9 peaks.
nr_dim: int
If 3, the code will assume three dimensional data for the tile, where z is the first dimension and y and x the second and third. For any other value 2-dimensional data is assumed. (default: 2)
nr_slices: int
Only applicable when running with 3D pictures and using ‘compres pic’ method. Determines the number of slices that are compressed together (compression in the z-direction). If None, all the slices are compressed together. Default: None
best_trans: np.array
1 by 2 or 3 array containing best found (z), y and x translation.
best_cov: float
The covariance of the overlap after translation of the overlap by best_trans.
contig_ind: int
The index of the used tile pair in contig_tuples. This is necessary to return when running on multiple processors/cores. More precisely: the index of the tuple in contig_tuples containing the indexes of the tiles that should be aligned.