paprica.runner

Submodule containing classes and functions relative to the running pipeline.

By using this code you agree to the terms of the software license agreement.

© Copyright 2020 Wyss Center for Bio and Neuro Engineering – All rights reserved

class paprica.runner.clearscopeRunningPipeline(path, n_channels, output_path=None)[source]

Bases: object

__init__(path, n_channels, output_path=None)[source]

Constructor for the clearscopeRunningPipeline.

Parameters
  • path (str) – Path of the acquisition. It has to be the acquisition folder (root of /0001/ folder).

  • n_channels (int) – Number of channels that will be acquired. This will be parsed/guessed in the future.

_build_database()[source]

Build the database for storing the registration parameters. This method needs to be called after the registration map has been produced.

Return type

None

_build_sparse_graphs()[source]

Build the sparse graph from the reliability and (row, col). This method needs to be called after the pair-wise registration has been performed for all neighbors pair.

Return type

None

_check_conversion(tile)[source]

Checks that conversion is ok, if not it should keep the original data.

Parameters

tile (tileLoader) – tile object to try if conversion worked as expected using facy metrics.

Return type

None

_check_for_apr_file(tile)[source]

Check if a given APR file already exists at a given location.

Parameters

tile (pipapr.loader.tileLoader) – tileLoader object

Returns

apr, parts – tuple containing APR and particles if found or (None, None) if not found.

Return type

pypapr.APR, pyapr.ParticleData

_convert_to_apr(tile)[source]

Convert the given tile to APR.

Parameters

tile (tileLoader) – tile object to be converted to APR.

Return type

None

_get_channel(path)[source]

Get channel from Clearscope tile path.

Parameters

path (str) – Clearscope tile path

Returns

_ – Channel number

Return type

int

_get_ind(ind_from, ind_to)[source]

Returns the ind in the original graph which corresponds to (ind_from, ind_to) in the minimum spanning tree.

Parameters
  • ind_from (int) – starting node in the directed graph

  • ind_to (int) – ending node in the directed graph

Returns

ind – corresponding ind in the original graph

Return type

int

_get_row_col(path)[source]

Get ClearScope tile row and col position given the tile path.

Parameters

path (str) – ClearScope tile path

Returns

row, col – row and col numbers

Return type

(int, int)

_get_tile(path)[source]

Returns the tile at the given path.

Parameters

path (string) – tile path

Returns

tile – tile object

Return type

tileLoader

_is_new_tile_available()[source]

Checks if a new tile is available for processing.

Returns

  • is_available (bool) – True if a new tile is available, False otherwise

  • tile (tileLoader) – tile object is available, None otherwise

_optimize_sparse_graphs()[source]

Optimize the sparse graph by computing the minimum spanning tree for each direction (H, D, V). This method needs to be called after the sparse graphs have been built.

Return type

None

_parse_acquisition_settings()[source]

Function that parses the setting txt file created by cleascope software at the begining of the acquisition and automatically extract the required parameters for the running pipeline to work.

Return type

None

_pre_stitch(tile)[source]

Perform pre-stitching, i.e. perform maximum intensity projection of the tile and register with available neighbors.

Parameters

tile (pipapr.loader.tileLoader) – tileLoader object containing the tile to perform the pre-stitiching on.

Return type

None

_print_info()[source]

Display stitching result information.

Return type

None

_process_RGB_for_display(u)[source]

Process RGB data for correctly displaying it.

Parameters

u (ndarray) – RGB data

Returns

data_to_display – RGB data displayable with correct contrast and colors.

Return type

ndarray

_produce_registration_map()[source]

Produce the registration map where reg_rel_map[d, row, col] (d = H,V,D) is the relative tile position in pixel from the expected one. This method needs to be called after the optimization has been done.

Return type

None

_project_tile(tile)[source]

Perform maximum intensity projection of the tile in the overlap area (+ predefined margin). For each tile a dictionnary ´tile´ is created and the ´[‘zy’, ‘zx’, ‘yx’]´ projections are save as a list in the dictionnary where the key corresponds to the edge location ´[‘north’, ‘south’, ‘east’, ‘west’]´.

Parameters

tile (tileLoader) – tile object

Return type

None

_reconstruct_z_slice(z=None, n_proj=0, downsample=1, color=False, debug=False, plot=True, progress_bar=True)[source]

Reconstruct and merge the sample at a given depth z.

Parameters
  • z (int) – reconstruction depth (vary with downsample)

  • n_proj (int (default: 0)) – Number of planes to perform the maximum intensity projection.

  • dim (int (default: 0)) – Dimension of the reconstruction, e.g. 0 will be [y, x] plane (orthogonal to z).

  • downsample (int (default: 1)) – Downsample factor for the reconstruction. Must be in [1, 2, 4, 8, 16, 32].

  • color (bool (default: False)) – Option to reconstruct with checkerboard color pattern. Useful to identify doubling artifacts.

  • debug (bool (default: False)) – Option to add a white square for each tile, making it easy to see overlapping areas.

  • plot (bool (default: True)) – Define if the function plots the results with Matplotlib or just returns an array.

  • seg (bool (default: False)) – Option to also reconstruct the segmentation. Only works with dim=0

Returns

merged_data – Merged frame at depth z.

Return type

ndarray

_register_tile(tile)[source]

Perform pair-wise registration of a given tile with all its previously processed neighbors.

Parameters

tile (pipapr.loader.tileLoader) – tileLoader object containing the tile to perform the pre-stitiching on.

Return type

None

_regularize(reg, rel)[source]

Remove too large displacement and replace them with expected one with a large uncertainty.

Parameters
  • reg (array_like) – list of registration (displacement) parameters

  • rel (array_like) – list of reliability parameters corresponding to each displacement.

Returns

(reg, rel) – Updated lists after regularization.

Return type

(array_like, array_like)

_update_next_tile()[source]

Update next tile coordinates given the expected pattern.

Return type

None

activate_conversion(Ip_th=108, rel_error=0.2, gradient_smoothing=2, dx=1, dy=1, dz=1, lazy_loading=True)[source]

Activate conversion for the running pipeline.

Parameters
  • Ip_th (int) – Intensity threshold

  • rel_error (float in [0, 1[) – relative error bound

  • gradient_smoothing ((float)) – B-Spline smoothing parameter (typically between 0 (no smoothing) and 10 (LOTS of smoothing)

  • dx (float) – PSF size in x, used to compute the gradient

  • dy (float) – PSF size in y, used to compute the gradient

  • dz (float) – PSF size in z, used to compute the gradient

  • lazy_loading (bool) – if lazy_loading is true then the converter save mean tree particle which are necessary for lazy loading of the APR. It will require about 1/7 more storage.

Return type

None

activate_stitching(channel)[source]

Activate stitching the data for the running pipeline.

Stitching the data consists in:

1) Computing the maximum intensity projections for each side that will have a neighboring tile once a tile is completely acquired 2) Once a neighboring tile is available and the maximum intensity projections have been computed for this tile, estimate the pairwise registration parameters, saving the results in a graph for each dimension, along with the reliability of the estimation. 3) Globaly optimize at the end to find the optimal tile placement.

Parameters

channel (int) – Number of the channel to perform the stitching on.

Return type

None

deactivate_compression()[source]

Deactivate B3D compression when saving particles.

Return type

None

plot_stitching_info()[source]

Plot pair-wise registration error for each axis [H, V, D].

Return type

None

reconstruct_slice(loc=None, n_proj=0, dim=0, downsample=1, color=False, debug=False, plot=True, progress_bar=True)[source]

Reconstruct whole sample 2D section at the given location and in a given dimension. This function can also reconstruct a maximum intensity projection if n_proj>0.

Parameters
  • loc (int (default: middle of the sample)) – Position of the plane where the reconstruction should be done. The location varies depending on the downsample parameter and should be adapted.

  • n_proj (int (default: 0)) – Number of planes to perform the maximum intensity projection.

  • dim (int (default: 0)) – Dimension of the reconstruction, e.g. 0 will be [y, x] plane (orthogonal to z).

  • downsample (int (default: 1)) – Downsample factor for the reconstruction. Must be in [1, 2, 4, 8, 16, 32].

  • color (bool (default: False)) – Option to reconstruct with checkerboard color pattern. Useful to identify doubling artifacts.

  • debug (bool (default: False)) – Option to add a white square for each tile, making it easy to see overlapping areas.

  • plot (bool (default: True)) – Define if the function plots the results with Matplotlib or just returns an array.

Returns

_ – Array containing the reconstructed data.

Return type

ndarray

reconstruct_z_color(z=None, n_proj=0, downsample=1, debug=False, plot=True, progress_bar=True)[source]

Reconstruct and merge the sample at a given depth z.

Parameters
  • z (int) – reconstruction depth

  • downsample (int) – downsample for reconstruction (must be a power of 2)

  • debug (bool) – if true the border of each tile will be highlighted

Returns

merged_data – Merged frame at depth z.

Return type

ndarray

run()[source]

Start the running pipeline. It is basically a loop waiting for each tile to be saved at the specified path.

Return type

None

set_compression(quantization_factor=1, bg=108)[source]

Activate B3D compression for saving tiles.

Parameters
  • quantization_factor (int) – quantization factor: the higher, the more compressed (refer to B3D paper for more detail).

  • bg (int) – background value: any value below this threshold will be set to the background value. This helps save up space by having the same value for the background (refer to B3D paper for more details).

Return type

None

set_overlap_margin(margin)[source]

Modify the overlaping area size. If the overlaping area is smaller than the true one, the stitching can’t be performed properly. If the overlaping area area is more than twice the size of the true one it will also fail (due to the circular FFT in the phase cross correlation).

Parameters

margin (float) – safety margin in % to take the overlaping area.

Return type

None

set_regularization(reg_x, reg_y, reg_z)[source]

Set the regularization for the stitching to prevent aberrant displacements.

Parameters
  • reg_x (int) – if the horizontal displacement computed in the pairwise registration for any tile is greater than reg_x (in pixel unit) then the expected displacement (from motor position) is taken.

  • reg_y (int) – if the horizontal displacement computed in the pairwise registration for any tile is greater than reg_z (in pixel unit) then the expected displacement (from motor position) is taken.

  • reg_z (int) – if the horizontal displacement computed in the pairwise registration for any tile is greater than reg_z (in pixel unit) then the expected displacement (from motor position) is taken.

Return type

None

set_z_range(z_begin, z_end)[source]

Set a range of depth fo computing the stitching.

Parameters
  • z_begin (int) – first depth to be included in the max-proj

  • z_end (int) – last depth to be included in the max-proj

Return type

None