hdf5preparation

pysmFISH.stitching_package.hdf5preparation.create_structures_hdf5_files(stitching_file, joining, nr_pixels, z_size, hyb_nr, gene, ubyte=True, blend='non linear', reg_name='')[source]

Takes an HDF5 file handle and creates the necessary structures.

Creates groups and data sets, when the groups or data sets already exists, they are kept as they are, as long as the data sets have the right size and data type. Incompatible data sets will be overwritten. Stitching file has the following structure:

__________________Groups____________|___Data sets____

gene1:
StitchedImage:
final_image final_image_ubyte blending_mask temp_mask
StitchingTempTiles:
blended_tiles:
0 1 . . n
ubytes:
0 1 . . n
temp_masks:
0 1 . . n

gene2: …

stitching_file: pointer
HDF5 file handle. The file where the stitched images will be saved.
joining: dict
Dictionary containing keys ‘corner_list and ‘final_image_shape’. Corner_list is a list of list, each list is a pair of an image number (int) and it’s coordinates (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the number of dimensions and contains ints.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
z_size: int
The number of layers in one tile (size of the z-axis). Should be 1 or None if the tile is 2D.
hyb_nr: int
The number of the hybridization we are stitching. This will be used to place the data in the right group in stitching_file.
gene: str
The name of the gene we are stitching.This will be used to place the data in the right group in stitching_file.
ubyte: bool
We need to create a data set for the ubyte image when True. Otherwise we only need to create a data set for the high resolution image.
blend: str
When ‘non linear’ or ‘linear’, blending will be applied, so we will need to create the structures necessary for saving the blended tiles. When it has another value or is None no blending at all will be applied, so we can skip this. This variable also determines to return value of linear_blending.
reg_name: str
A name that will be used to create a second StitchedImage group for an image that is registered to be aligned with the other hybridizations. warp_name will be attached to the end of the group name, which is StitchedImage.
stitched_group: pointer
HDF5 reference to the group where the final will be.
temp_group: pointer
HDF5 reference to the group where the blended tiles will be saved.
linear_blending: bool
When True later blending should be linear and when False, blending should be non-linear.
ubyte: bool
The ubyte image should be saved when True. Otherwise only the high resolution image should be saved.
blend: str
When ‘non linear’ or ‘linear’, blending should be applied. When it has another value or is None no blending at all will be applied.
pysmFISH.stitching_package.hdf5preparation.create_structures_hdf5_stitched_ref_gene_file_npy(stitching_file, joining, nr_pixels, reference_gene, blend='non linear')[source]

Takes an HDF5 file handle and creates the necessary structures.

Modification of create_structures_hdf5_files to work with .npy list of files

Creates groups and data sets, when the groups or data sets already exists, they are kept as they are, as long as the data sets have the right size and data type. Incompatible data sets will be overwritten. Stitching file has the following structure:

__________________Groups____________|___Data sets____

gene_stitched:
StitchedImage:
final_image blending_mask
stitching_file: pointer
HDF5 file handle. The file where the stitched images will be saved.
joining: dict
Dictionary containing keys ‘corner_list and ‘final_image_shape’. Corner_list is a list of list, each list is a pair of an image number (int) and it’s coordinates (numpy array containing floats). Final_image_shape is a tuple of size 2 or 3 depending on the number of dimensions and contains ints.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
reference_gene: str
The name of the gene we are stitching.This will be used to place the data in the right group in stitching_file.
blend: str
When ‘non linear’ or ‘linear’,blending will be applied, so we will need to create the structures necessary for saving the blended tiles. When it has another value or is None no blending at all will be applied, so we can skip this. This variable also determines to return value of linear_blending.
stitched_group: pointer
HDF5 reference to the group where the final will be.
linear_blending: bool
When True later blending should be linear and when False, blending should be non-linear.
blend: str
When ‘non linear’ or ‘linear’, blending should be applied. When it has another value or is None no blending at all will be applied.
pysmFISH.stitching_package.hdf5preparation.divide_final_image(im_shape, nr_blocks)[source]

Divide the image in rows if it is too large to be filled at once.

The parallel HDF5 implementation cannot handle images larger than 2GB. Therefore this function can divide the rows of the image over nr_blocks to be filled by separate cores.

im_shape: tuple
Shape (y, x) of the image to be filled.
nr_blocks: int
The number of block to divide the image in, typically this will be the number of available cores.
y_corners: list
List of numpy ints (numpy.int64). The y-corners of all the blocks.
pysmFISH.stitching_package.hdf5preparation.fill_hdf5_MPI(y_corners, ind, im_shape, im_file, ubyte, blend)[source]

Fill the data sets in the hdf5 file with zeros, block by block.

The parallel HDF5 implementation cannot handle images larger than 2GB. Therefore this function only fills the part of the image from the indexing value found in y_corners[ind] up to y_corners[ind + 1].

y_corners: list
List of numpy ints (numpy.int64). The y-corners of all the blocks.
ind : int
The index of the corner in y_corners
im_shape: tuple
Shape of the final image.
im_file: pointer
HDF5 file handle or group reference. The file or group with the datasets that need to be filled.
ubyte: bool
Ubyte image is filled if True
blend: str
If this is None datasets needed for blending are left empty, for all other values they are filled.
pysmFISH.stitching_package.hdf5preparation.fill_hdf5_files(im_file, joining, nr_pixels, ubyte, blend)[source]

Fill the data sets in the hdf5 file with zeros or random data.

im_file: pointer
HDF5 reference. Reference to the StitchedImage group or any group or file that contains final_image and optionally final_image_ubyte, blending_mask and temp_mask.
joining: dictionary
Containing the key final_image_shape. Final_image_shape is a tuple of size 2 or 3 depending on the number of dimensions and contains ints.
nr_pixels: int
Height and length of the tile in pixels, tile is assumed to be square.
ubyte: bool
The ubyte image will be filled when True. Otherwise only the high resolution image will be saved.
blend: str
When blend is not None, blending_mask and temp_mask will be filled.