megafish.decode module

gaussian_kernel(shape, sigma)[source]

Generates a Gaussian kernel for spatial filtering. This kernel is used for spatial filtering in the MERFISH prefiltering step.

Parameters:
  • shape (tuple of int) – The dimensions (height, width) of the kernel.

  • sigma (float) – The standard deviation of the Gaussian distribution, which controls the spread of the kernel.

Returns:

A 2D array representing the Gaussian kernel, normalized so that the sum of all elements equals 1.

Return type:

numpy.ndarray

merfish_prefilter(zarr_path, group, sigma_high, psf, iterations, sigma_low, mask_size, footer='_mfp')[source]

Applies MERFISH prefiltering steps, including high-pass filtering, Richardson-Lucy deconvolution, and low-pass filtering.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group (str) – Group name in the Zarr file where the image data is stored.

  • sigma_high (float) – Standard deviation for the high-pass Gaussian filter.

  • psf (numpy.ndarray or cupy.ndarray) – Point spread function used for deconvolution.

  • iterations (int) – Number of iterations for the Richardson-Lucy deconvolution.

  • sigma_low (float) – Standard deviation for the low-pass Gaussian filter.

  • mask_size (int) – Size of the dilation mask for edge removal.

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_mfp”.

Returns:

This function saves the processed image data in the Zarr file.

Return type:

None

scaling(zarr_path, group, percentile, factor, footer='_scl')[source]

Scales the intensity of the image data stored in a Zarr file based on a given percentile and scaling factor.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group (str) – Group name in the Zarr file where the image data is stored.

  • percentile (float) – The percentile value used for scaling the image intensity.

  • factor (float) – The scaling factor applied to normalize the image intensity.

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_scl”.

Returns:

This function saves the scaled image data in the Zarr file.

Return type:

None

norm_value(zarr_path, group, footer='_nmv')[source]

Calculates the L2 norm (Euclidean norm) of the image data across cycles stored in a Zarr file.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group (str) – Group name in the Zarr file where the image data is stored.

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_nmv”.

Returns:

This function saves the calculated norm values as a new dataset in the Zarr file.

Return type:

None

divide_by_norm(zarr_path, group_mfp, group_nmv, footer='_nrm')[source]

Divides the filtered image data by the calculated norm values for normalization.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group_mfp (str) – Group name in the Zarr file where the filtered image data is stored.

  • group_nmv (str) – Group name in the Zarr file where the norm values are stored.

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_nrm”.

Returns:

This function saves the normalized image data as a new dataset in the Zarr file.

Return type:

None

nearest_neighbor(zarr_path, group, code_intensity_path, footer='_nnd')[source]

Calculates the nearest neighbor for each pixel’s intensity trace in an image dataset using a precomputed codebook.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group (str) – Group name in the Zarr file where the image data is stored.

  • code_intensity_path (str) – Path to the NumPy file containing intensity codes for matching.

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_nnd”.

Returns:

This function saves the nearest neighbor indices and distances as a new dataset in the Zarr file.

Return type:

None

split_nnd(zarr_path, group, footers=['_cde', '_dst'])[source]

Splits the nearest neighbor dataset into two separate datasets: one for the code indices and one for the distances. The function saves each as a new dataset in the Zarr file.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group (str) – Group name in the Zarr file where the nearest neighbor dataset is stored.

  • footers (list, optional) – List of two strings specifying the footers for the output datasets; defaults to [“_cde”, “_dst”].

Returns:

This function saves the split datasets in the Zarr file.

Return type:

None

select_decoded(zarr_path, group_nmv, group_nnd, min_intensity, max_distance, area_limits, footer='_dec')[source]

Filters decoded spots based on intensity, distance, and area criteria.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group_nmv (str) – Group name in the Zarr file where the norm value data is stored.

  • group_nnd (str) – Group name in the Zarr file where the nearest neighbor data is stored.

  • min_intensity (float) – Minimum intensity threshold for valid spots.

  • max_distance (float) – Maximum distance threshold for valid spots.

  • area_limits (tuple) – A tuple containing the minimum and maximum area values (min_area, max_area).

  • footer (str, optional) – Footer string to append to the output Zarr group name; defaults to “_dec”.

Returns:

This function saves the filtered dataset in the Zarr file.

Return type:

None

coordinates_decoded(zarr_path, group_dec, group_nuc, footer='_crd')[source]

Extracts and records the coordinates of decoded spots within nuclei, saving the information in a CSV file for each chunk.

Parameters:
  • zarr_path (str) – Path to the Zarr file containing the image data.

  • group_dec (str) – Group name in the Zarr file where decoded data is stored.

  • group_nuc (str) – Group name in the Zarr file where nuclear data is stored.

  • footer (str, optional) – Footer string to append to the output group name; defaults to “_crd”.

Returns:

This function saves the coordinates of decoded spots in CSV files.

Return type:

None