Skip to main content
Ctrl+K

sdt-python 18.1 documentation

  • Regions of interest (ROIs)
  • Multi-color data analysis
  • Diffusion analysis
  • Brightness analysis
  • Data input/output
  • Changepoint detection
  • Analyze spatial aspects of data
  • Single molecule FRET analysis
  • Image filtering and processing
  • Flat-field correction
  • Fluorescent feature localization
  • GUIs for the Jupyter notebook
  • Simulation of microscopy-related data
  • Special functions
  • Plotting utilities
  • Optimization and fitting algorithms
  • Helpers for writing new code
  • Change log
  • .rst

Simulation of microscopy-related data

Contents

  • Fluoresence microscopy images
  • Single molecule tracking data
  • Programming reference
    • simulate_gauss()
    • simulate_brownian()
  • Low level simulation functions
    • gauss_psf_full()
    • gauss_psf()
    • gauss_psf_numba()
    • brownian_track()

Simulation of microscopy-related data#

Fluoresence microscopy images#

Each fluorophore appears in the microscope as a diffraction limited spot. The whole image is made up by the superposition of such spots. The simulate_gauss() function provides functions to simulate images like that.

Examples

First, create some data:

>>> shape = (120, 120)  # shape of the simulated image
>>> coords = numpy.array([np.arange(10, 101, 10)]*2).T  # create some data
>>> amplitudes = numpy.arange(100, 1001, 100)
>>> sigmas = numpy.arange(1, 11, 1)

Now, use the data to simulate the image (ideal case, no noise) using simulate_gauss():

>>> img = simulate_gauss(shape, coords, amplitudes, sigmas)

Finally, shot noise (Poissonian) and camera noise (Gaussian) can be added:

>>> img_noisy = numpy.random.poisson(img)  # shot noise
>>> img_noisy += numpy.random.normal(200, 20, img_noisy.shape)  # camera noise

Single molecule tracking data#

Simulate trajectories of particles undergoing Brownian motion using the simulate_brownian() function.

Examples

Create 10 tracks with exponentially distributed track lengths (mean 100), diffusion coefficient 0.7 μm²/s, lag time 10 ms and particles distributed initially randomly in a 30 μm x 30 μm square:

>>> trc = sm_tracks.simulate_brownian(10, 100, 0.7, size=(30, 30), lag_t=0.01,
                                      track_len_dist="exp")
>>> trc.head()
           x          y  frame  particle
0  16.657713  19.759589      0         0
1  16.816584  19.994379      1         0
2  16.792206  20.014007      2         0
3  16.676282  20.041114      3         0
4  16.590677  20.002406      4         0

Programming reference#

sdt.sim.simulate_gauss(shape, centers, amplitudes, sigmas, cutoff=5.0, mass=False, engine='numba')[source]#

Simulate an image from multiple Gaussian PSFs

Given a list of coordinates, amplitudes and sigmas, simulate a fluorescent image. This is a frontend to the lower level functions gauss_psf_numba(), gauss_psf(), and gauss_psf_full().

Parameters:
  • shape (tuple of int, len=2) – Shape of the output image. First entry is the width, second is the height.

  • centers (numpy.ndarray, shape=(n, 2)) – Coordinates of the PSF centers

  • amplitudes (array_like) – Amplitudes of the PSFs. Either a scalar that is used for all Gaussians or an 1D array specifying the amplitude for each Gaussian. See also the mass parameter.

  • sigmas (array_like) – If it is one number, this will be used as sigma for all Gaussians. An array of two numbers will be interpreted as sigmas in x and y directions for all Gaussians. A one-dimensional array of length n can be used to specify sigma for each Gaussian, and a 2D array of shape (n, 2) gives sigmas in x and y directions for each Gaussian.

  • cutoff (float, optional) – Each Gaussian is only calculated in a box cutoff times sigma pixels around the center. Does not apply if engine is “python_full”. Defaults to 5.

  • mass (bool, optional) – If True, the value(s) given by amplitude are the integrated Gaussians. If False, they are amplitudes. Defaults to False.

  • engine ({"numba", "python", "python_full"}, optional) – “numba” is a numba-optimized version, which is by far the fastest. “python” is written in pure python. “python_full” is also pure python and calculates each Gaussian for the whole image (not only in a region around the center, where it is significant), which makes it the slowest. Defaults to “numba”.

Returns:

Simulated image.

Return type:

numpy.ndarray

sdt.sim.simulate_brownian(n_tracks, track_len, d, size=None, initial=None, pa=0, lagt=1, track_len_dist='const', random_state=None, columns={})[source]#

Simulate particles undergoing Brownian motion

Parameters:
  • n_tracks (int) – Number of tracks to simulate

  • track_len (int) – Average track length (see also track_len_dist parameter )

  • d (float) – Diffusion coefficient

  • size (tuple, optional) – Size of the region where to simulate particles. If initial is None, this is used to randomly distribute the n_tracks particles.

  • initial (array-like, shape(n_tracks, m), optional) – Initial positions of the particles. If None, the particles will be placed randomly; in that case, size needs to be given.

  • pa (float, optional) – Positional (in)accuracy. Defaults to 0.

  • lagt (float) – Time between two recorded positions. Defaults to 1.

  • track_len_dist ({"const", "exp"} or callable, optional) – Track length distribution. If “const”, all tracks will be of length track_len. If “exp”, track lengths will be exponentially distributed with mean track_len. A callable has to take two arguments (n_tracks, track_len) and return a 1D array of ints containing the lengths of the tracks. Defaults to “const”

  • random_state (numpy.random.RandomState, optional) – If given, it will use this to create random numbers. Otherwise, a new RandomState object will be created and used.

  • columns (dict, optional) – Override default column names as defined in config.columns. Relevant names are coords, particle, and time. This means, if your DataFrame has coordinate columns “x” and “z” and the time column “alt_frame”, set columns={"coords": ["x", "z"], "time": "alt_frame"}.

Returns:

Simulated tracking data. Columns are coordinates, time, and particle columns as specified in the columns arg.

Return type:

pandas.DataFrame

Low level simulation functions#

sdt.sim.gauss_psf_full(shape, centers, amplitudes, sigmas)[source]#

Simulate an image from multiple Gaussian PSFs

Given a list of coordinates, amplitudes and sigmas, simulate a fluorescent image. For each emitter, the Gaussian is calculated over the whole image area, which makes this very slow (since calculating exponentials is quite time consuming.)

Parameters:
  • shape (tuple of int, len=2) – Shape of the output image. First entry is the width, second is the height.

  • centers (numpy.ndarray, shape=(n, 2)) – Coordinates of the PSF centers

  • amplitudes (list of float, len=n) – Amplitudes of the Gaussians

  • sigmas (numpy.ndarray, shape(n, 2)) – x and y sigmas of the Gaussians

Returns:

Simulated image.

Return type:

numpy.ndarray

sdt.sim.gauss_psf(shape, centers, amplitudes, sigmas, cutoff)[source]#

Simulate an image from multiple Gaussian PSFs

Given a list of coordinates, amplitudes and sigmas, simulate a fluorescent image. For each emitter, the Gaussian is calculated only in a square of 2*`roi_size`+1 pixels width, which can make it considerably faster than gauss_psf_full().

Parameters:
  • shape (tuple of int, len=2) – Shape of the output image. First entry is the width, second is the height.

  • centers (numpy.ndarray, shape=(n, 2)) – Coordinates of the PSF centers

  • amplitudes (list of float, len=n) – Amplitudes of the Gaussians

  • sigmas (numpy.ndarray, shape(n, 2)) – x and y sigmas of the Gaussians

  • cutoff (float) – Each Gaussian is only calculated in a box cutoff times sigma pixels around the center.

Returns:

Simulated image.

Return type:

numpy.ndarray

sdt.sim.gauss_psf_numba(shape, centers, amplitudes, sigmas, cutoff)[source]#

Simulate an image from multiple Gaussian PSFs

Given a list of coordinates, amplitudes and sigmas, simulate a fluorescent image. For each emitter, the Gaussian is calculated only in a square of 2*`roi_size`+1 pixels width. Also, the numba package is used, which can make it considerably faster than gauss_psf_full() and gauss_psf().

Parameters:
  • shape (tuple of int, len=2) – Shape of the output image. First entry is the width, second is the height.

  • centers (numpy.ndarray, shape=(n, 2)) – Coordinates of the PSF centers

  • amplitudes (list of float, len=n) – Amplitudes of the Gaussians

  • sigmas (numpy.ndarray, shape(n, 2)) – x and y sigmas of the Gaussians

  • cutoff (float) – Each Gaussian is only calculated in a box cutoff times sigma pixels around the center.

Returns:

Simulated image.

Return type:

numpy.ndarray

sdt.sim.brownian_track(track_len, d, size=None, initial=None, pa=0, lagt=1, random_state=None)[source]#

Simulate a single particle undergoing Brownian motion

Parameters:
  • track_len (int) – Average track length (see also track_len_dist parameter )

  • d (float) – Diffusion coefficient

  • size (tuple, optional) – Size of the region where to simulate particles. If initial is None, this is used to randomly distribute the n_tracks particles.

  • initial (array-like, shape(n_tracks, m), optional) – Initial positions of the particles. If None, the particles will be placed randomly; in that case, size needs to be given.

  • pa (float, optional) – Positional (in)accuracy. Defaults to 0.

  • lagt (float) – Time between two recorded positions. Defaults to 1.

  • random_state (numpy.random.RandomState, optional) – If given, it will use this to create random numbers. Otherwise, a new RandomState object will be created and used.

Returns:

Simulated coordinates of the particle, one set of coordinates per row.

Return type:

numpy.ndarray, shape(track_len, ndim)

previous

GUIs for the Jupyter notebook

next

Special functions

Contents
  • Fluoresence microscopy images
  • Single molecule tracking data
  • Programming reference
    • simulate_gauss()
    • simulate_brownian()
  • Low level simulation functions
    • gauss_psf_full()
    • gauss_psf()
    • gauss_psf_numba()
    • brownian_track()

By Lukas Schrangl

© Copyright 2015—2023, Lukas Schrangl.