Submodules

picasso_addon.autopick

picasso_addon.autopick.check_spots

Check all boxes around x,y for number of localizations, active pixels and center of mass position.

Parameters:
  • frame (np.array) – Subpixel rendered localization image.
  • y (int) – Box center y-coordinate (row)
  • x (int) – Box center x-coordinate (column)
  • box (int) – Box size in subpixels. Must be uneven!
Returns:

  • [0] (float): Center of mass y-position as measured from y
  • [1] (float): Center of mass x-position as measured from x
  • [2] (int): Number of localizations within box
  • [3] (int): Number of subpixels within box with at least one localization

Return type:

tuple

picasso_addon.autopick.ck_nlf(trace, M=10, N=[2, 4, 8, 16], p=30)

Chung-Kennedy nonlinear filter

Nonlinear local low-pass filter optimized for edge preservation. Used quite frequently in step detection in noisy traces. For details, see: Chung SH & Kennedy RA, J Neurosci Meth 1991, DOI: 10.1016/0165-0270(91)90118-J

Note that the algorithm frequently raises warnings saying “invalid value encountered in true_divide”. There is no need to worry about that: The filter, when used with high p, tends to create extreme numbers in calculation intermediates, which may even end up creating zeros. This only affects weighting functions of a handful of data points, though, and has negligible impact on the overall filter result. It will NOT create any extreme values in the returned filtered trace, at least I have never encountered such results.

Parameters:
  • trace (numpyp.array) – Time trace to be filtered. Signal only, no time axis required.
  • M (int) – Field width for predictor weight determination. Typical values: 5-20.
  • N (list) – Field width set for predictor calculation. Typical values: [4, 8, 16, 32] or subsets thereof. Minumum len(N) > 1
  • p (int) – Positive single number (usually int, but not strictly required). Nonlinear order of predictor weight calculation. Typical values: 5-100, strongly application-dependent. Higher values mean sharper edge preservation.
Returns:

1D filtered time trace of same structure as input.

Return type:

trace_f (numpy.array)

picasso_addon.autopick.coordinate_convert(spot_centers, viewport_min, oversampling)

Convert spot centers as detected in rendered localizations by given viewport minima and oversampling back to original localization coordinates.

Parameters:
  • spot_centers (pandas.DataFrame) – Output of function spotcenters_in_image()[0], i.e. spot center coordinates.
  • viewport_min (tuple) – (min_x,min_y) of viewport as in picasso.render.
  • oversampling (int) – Pixel oversampling as in picasso.render
Returns:

spot_centers converted back to orignal localization coordinates.

Return type:

pandas.DataFrame

picasso_addon.autopick.get_picked(locs_in, picks_idx)

Get locs corresponding to picks_idx as obtained by query_locs_for_centers() and assign group ID.

Parameters:
  • locs (numpy.recarray) – Localizations as loaded by picasso.io (see picasso.localize).
  • picks_idx (numpy.ndarray) – Single rows correpond to indices (as list) in locs within pick_radius around centers. See query_locs_for_centers().
Returns:

Picked as in picasso.render. Localizations in overlapping picks appear in each pick,

i.e. same localization appears multiple times but with different group ID! This means _picked can have more localizations than original _locs!

Return type:

pandas.DataFrame

picasso_addon.autopick.identifyspots_in_image

Identify boxes above localization threshold in rendered localizations image by using check_spots().

Parameters:
  • image (np.array) – Subpixel rendered localization image.
  • minimum_n_locs (int) – Number of localization threshold for valid boxes
  • box (int) – Box size in subpixels. Must be uneven!
Returns:

  • [0] (int): Local box maximum y (i.e. box y center coordinate)
  • [1] (int): Local box maximum x (i.e. box x center coordinate)
  • [2] (float): Center of mass y-position as measured from y
  • [3] (float): Center of mass x-position as measured from x
  • [4] (int): Number of localizations within box

Return type:

tuple

picasso_addon.autopick.main(locs, info, path, **params)

Cluster detection (pick) in localizations by thresholding in number of localizations per cluster. Cluster centers are determined by creating images of localization list with set oversampling using picasso.render.

Parameters:
  • locs (numpy.recarray) – (Undrifted) localization list as created by picasso.render.
  • info (list(dict)) – Info to localization list when loaded with picasso.io.load_locs().
Keyword Arguments:
 
  • pick_diameter (float=1.2) – Pick diameter in original pixels.
  • oversampling (int=5) – Oversampling for rendering of localization list, i.e. sub-pixels per pixel of original image.
  • min_n_locs (float=0.2*NoFrames) – Detection threshold for number of localizations in cluster. Standard value is set for spt. Set to lower value for usual DNA-PAINT signal (see lbfcs).
  • fit_center (bool=False) – False = Center of mass. True = 2D Gaussian fitting of center.
  • lbfcs (bool=False) – If set to True will overrun min_n_locs and sets it to 0.02*NoFrames.
Returns:

  • [0] (dict): kwargs passed to function.
  • [1] (pandas.DataFrame): Picked localizations, saved with extension _picked.hdf5.
  • [2] (pandas.DataFrame): Center positions and number of localizations per pick, saved with extension _autopick.yaml.
  • [3] (str): Full save path.

Return type:

list

picasso_addon.autopick.query_locs_for_centers(locs, centers, pick_radius=1)

Builds up KDtree for locs, queries the tree for localizations within pick_radius (norm of p=2) around centers (xy coordinates). Output will be list of indices as result of query.

Parameters:
  • locs (numpy.recarray or pandas.DataFrame) – Localizations as created by picasso.localize with fields x and y.
  • centers (np.array) – Pick center coordinates (x,y)
  • pick_radius (float=1) – Pick diameter in px.
Returns:

List of len(centers). Single list entries correpond to indices in locs of localizations within pick_radius around centers. Hence every list indicates one pick (group).

Return type:

list

picasso_addon.autopick.spotcenters_in_image(image, box, min_nlocs, fit=False)

Get pick center coordinates in subpixel rendered localization image by either calculating center of mass or fitting 2D Gaussian.

Parameters:
  • image (np.array) – Subpixel rendered localization image.
  • box (int) – Box size in subpixels. Must be uneven!
  • min_nlocs (int) – Number of localization threshold for valid boxes
  • fit (bool=False) – Employ 2D gaussian fitting? Normally not better performing. If False only center of mass position.
Returns:

  • [0] (pandas.DataFrame): Spot center coordinates (image units) and number of localizations (x,y,n_locs)
  • [1] (bool): True if fit was performed

Return type:

tuple

picasso_addon.io

picasso_addon.io.load_locs(path)

Returns localization .hdf5 from picasso as pandas.DataFrame and corresponding .yaml as list of dictionaries.

Parameters:
  • path (str) – Path to .hdf5 file as generated by picasso.localize
  • container (str) –
    Name of dataset within .hdf5 container. Must be set to:
    • 'locs' for _locs, _render and _picked .hdf5 files as generated by picasso.render.
    • 'groups' for _pickprops.hdf5 files as generated by picasso.render.
    • Defaults to 'locs'.
Returns:

  • [0] (pandas.DataFrame): Localizations stored under 'locs' in .hdf5 file
  • [1] (list): List of dictionaries contained in .yaml corresponding to .hdf5 file

Return type:

tuple

picasso_addon.io.save_locs(path, locs, info, mode=None)

Save localizations in .hdf5 container and corresponding info in .yaml.

Parameters:
  • locs (pandas.DataFrame) – Localizations as obtained by picasso.localize but converted to pands.DataFrame.
  • info (list) – Info as list of dicts, will be stored in .yaml
  • path (str) – Full save path.
  • mode (str) – If mode='picasso_compatible' localizations will be stored as nmpy.rec_array to be readable with picasso.filter.
picasso_addon.io.save_picks(locs, pick_diameter, path)

Save pick centers in .yaml file so they can be loaded with picasso.render

Parameters:
  • locs (pandas.DataFrame or numpy.array) – Spot center coordinates. Must contain fields x and y.
  • pick_diameter (int) – Pick diameter in pixel as in picasso.render.
  • path (str) – Full save path.
Returns:

Converted locs with entries 'Diameter', 'Centers' and 'Shape'

Return type:

dict

picasso_addon.localize

picasso_addon.localize.autodetect_mng(movie, info, box)

Automatically detect minimal net-gradient for localization. Based on net-gradient distribution of all boxes in raw movie using identify_in_image(). Distribution is taken from 10 frames evenly distributed over total aquisition time.

Parameters:
  • movie (io.TiffMultiMap) – Movie object as created by picasso.io.load_movie().
  • info (list) – Info file as created by picasso.io.load_movie()
  • box (uneven int) – Box size in pixels.
Returns:

Minimal net gradient

Return type:

int

picasso_addon.localize.boxvals_in_frame
picasso_addon.localize.cut_spots_readvar(ids, box)
picasso_addon.localize.gradient_at
picasso_addon.localize.localize_movie(movie, box, mng, baseline, sensitivity, qe, gain, weight_fit)

Localize using least square fitting in either non-weighted version (CPU,GPU) or weighted version (GPU) using provided CMOS camera readout variance map.

Parameters:
  • movie (io.TiffMultiMap) – Movie object as created by picasso.io.load_movie()
  • box (int) – Box length (uneven!) of fitted spots (see picasso.localize)
  • mng (float) – Minimal net-gradient spot detection threshold (see picasso.localize)
  • baseline (int) – Camera spec. baseline (see picasso.localize)
  • sensitivity (float) – Camera spec. sensitivity (see picasso.localize)
  • qe (float) – Camera spec. quantum efficiency (see picasso.localize)
  • gain (float) – Camera spec. EM gain (see picasso.localize)
  • weight_fit (bool) – Use weighted least square fitting based on readout variance and gain maps(only GPU implemented!)
Returns:

Localizations (numpy.recarray)

Return type:

locs

picasso_addon.localize.main(file, info, path, **params)

Localize movie (least squares, GPU fitting if available) and undrift resulting localizations using rcc.

Parameters:
  • file (picasso.io) – Either raw movie loaded with picasso.io.load_movie() or_locs.hdf5 loaded with picasso.io.load_locs()
  • info (list(dicts)) – Info to raw movie/_locs.hdf5 loaded with picasso.io.load_movie() or picasso.io.load_locs()
Keyword Arguments:
 
  • calibrate_movie (bool=True) – Pixel calibration of raw movie using offset and gain maps for CMOS sensors
  • localize (bool=True) – Localize raw or calibrated movie (CMOS) (see picasso_addon.localize)
  • box (int=9) – Box length (uneven!) of fitted spots (see picasso.localize)
  • mng (int or str='auto') – Minimal net-gradient spot detection threshold(see picasso.localize. If set to ‘auto’ minimal net_gradient is determined by autodetect_mng().
  • baseline (int=113) – Camera spec. baseline (see picasso.localize).
  • gain (float=1) – Camera spec. EM gain (see picasso.localize)
  • sensitivity (float=0.49) – Camera spec. sensitivity (see picasso.localize)
  • qe (float=1) – Camera spec. quantum gain (see picasso.localize), set to 1 to count generated photoelectrons.
  • undrift (bool=True) – Apply RCC drift correction (see picasso.postprocess)
  • segments (int=450 or str='auto') – Segment length (frames) for undrifting by RCC (see picasso.render). If set to ‘auto’ segment length is `int(ceil(NoFrames))`.
Returns:

  • [0][0](dict): kwargs passed to localize_movie()
  • [0][1](dict): kwargs passed to undriftrcc_locs()
  • [1](numpy.array): Undrifted localization list saved as _render.hdf5 (if undrift was True) otherwise localization list (no undrifting) saved as _locs.hdf5
  • [2](str): Last full file saving path for input to further modules

Return type:

list

picasso_addon.localize.weightfit_spots_gpufit(spots, spots_readvar)