scopyon module

class scopyon.Configuration(filename=None, yaml=None)

Bases: collections.abc.Mapping

Note

Requires yaml and pint.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
save(file)

Save configurations as YAML file.

Parameters

file (str) – An output file name.

update(conf)
property yaml
class scopyon.DefaultConfiguration

Bases: scopyon.config.Configuration

Default configuration. All the settings are available in package data, scopyon.yaml. See https://github.com/ecell/scopyon/blob/master/scopyon/scopyon.yaml

class scopyon.EPIFMSimulator(config=None, method=None, rng=None)

Bases: object

base()
form_image(inputs, start_time=0.0, exposure_time=None, full_output=False)

Form image.

Parameters
  • inputs (array_like) – A list of points. The shape must be ‘(n, 3)’, where ‘n’ means the number of points.

  • start_time (float, optional) – A time to start detecting. Defaults to 0.0.

  • exposure_time (float, optional) – An exposure time. Defaults to detector.exposure_time in the configuration.

  • full_output (bool, optional) – True to return a dictionary containing optional outputs.

Returns

An image. dict: only returned if full_output == True

A dictionary containing additional information. ‘expectation’ is 2-dimensional ndarray. ‘true_data’ is a dictionary containing a pair of a molecule ID and ndarray. The array has 7 elements, which are exposure time, photon state, X and Y in pixels, X and Y in meter-scale, and normalization.

Return type

Image

generate_images(inputs, num_frames, start_time=0.0, exposure_time=None, full_output=False)

Form image.

Parameters
  • inputs (array_like) – A list of points. The shape must be ‘(n, 3)’, where ‘n’ means the number of points.

  • num_frames (int) – The number of frames taken.

  • start_time (float, optional) – A time to start detecting. Defaults to 0.0 in the configuration.

  • exposure_time (float, optional) – An exposure time. Defaults to detector_exposure_time in the configuration.

  • full_output (bool, optional) – True to return a dictionary containing optional outputs.

Yields

Image – An image. dict: only returned if full_output == True

A dictionary containing additional information. ‘expectation’ is 2-dimensional ndarray. ‘true_data’ is a dictionary containing pairs of a molecule ID and ndarray. The array has 7 elements, which are exposure time, photon state, X and Y in pixels, X and Y in meter-scale, and normalization. If ‘photo_bleaching’ is active, ‘fluorescence_states’ contains pairs of a molecule ID and remaining photon budget.

class scopyon.EnvironSettings(config)

Bases: object

initialize(config)
class scopyon.Image(data)

Bases: object

PLOTTING = <module 'scopyon._plotly' from '/home/docs/checkouts/readthedocs.org/user_builds/scopyon/checkouts/latest/scopyon/_plotly.py'>
static RGB(red=None, green=None, blue=None)

Make an image from RGB arrays.

Parameters
  • red (2d ndarray or Image) – RGB channel

  • green (2d ndarray or Image) – RGB channel

  • blue (2d ndarray or Image) – RGB channel

Returns

an image object

Return type

Image

as_8bit(cmin=None, cmax=None, low=None, high=None)

Same as scipy.misc.bytescale

Parameters
  • cmin (float, optional) – Defaults to the minimum in data.

  • cmax (float, optional) – Defaults to the maximum in data.

  • low (float, optional) – Defaults to 0

  • high (float, optional) – Defaults to 255.

Returns

an Image object with 8bit data.

Return type

Image

as_array()
property dtype
static load(file)

Load an image.

Parameters

file (str) – A file path.

Returns

an image object

Return type

Image

property ndim
save(filename, **kwargs)

Save the 8-bit image.

Note

Requires pillow to save in the image format. See also scopyon.Image.savefig.

Parameters

filename (str) – An output file name. .npy, .csv or image formats are accepted.

static savefig(filename, img, shapes=None)

Save figure.

Parameters
  • filename (str) – An output file path.

  • img (ndarray) – An image data to be shown.

  • shapes (list, optional) – A list of shapes. shape is a dictionary consisting of x (row), y (column), sigma and color. sigma is a half size of the box (square).

property shape
show(**kwargs)

Plot the 8-bit image.

Note

Requires plotly optionally. See also scopyon._plotly.show, scopyon._matplotlib.show.

property size
class scopyon.Video

Bases: object

static save(filename, imgs, interval=100, dpi=None, cmin=None, cmax=None, low=None, high=None)

Make a video from images.

Note

Requires matplotlib.

Parameters
  • filename (str) – An output file name.

  • imgs (list) – A list of Images.

  • interval (int, optional) – An interval between frames given in millisecond.

  • dpi (int, optional) – dpi.

scopyon.create_simulator(config=None, method=None, rng=None)

Return a simulator.

Parameters
  • config (Configuration, optional) – Configurations.

  • method (str, optional) – A name of method used. The default is None (config.default).

  • rng (numpy.RandomState, optional) – A random number generator. The default is None.

Returns

A simulator

Return type

EPIFMSimulator

scopyon.form_image(inputs, start_time=0.0, exposure_time=None, *, method=None, config=None, rng=None, full_output=False)

Form image.

Parameters
  • inputs (array_like) – A list of points. The shape must be ‘(n, 3)’, where ‘n’ means the number of points.

  • start_time (float, optional) – A time to start detecting. Defaults to 0.0.

  • exposure_time (float, optional) – An exposure time. Defaults to detector.exposure_time in the configuration.

  • method (str, optional) – A name of method used. The default is None (‘default’).

  • config (Configuration, optional) – Configurations. The default is None.

  • rng (numpy.RandomState, optional) – A random number generator. The default is None.

  • full_output (bool, optional) – True to return a dictionary containing optional outputs.

Returns

An image dict: only returned if full_output == True

A dictionary containing additional information. ‘expectation’ is 2-dimensional ndarray. ‘true_data’ is a dictionary containing a pair of a molecule ID and ndarray. The array has 7 elements, which are exposure time, photon state, X and Y in pixels, X and Y in meter-scale, and normalization.

Return type

Image

scopyon.generate_images(inputs, num_frames, start_time=0.0, exposure_time=None, *, method=None, config=None, rng=None, full_output=False)

Form images.

Parameters
  • inputs (array_like) – A list of points. The shape must be ‘(n, 3)’, where ‘n’ means the number of points.

  • num_frames (int) – The number of frames taken.

  • start_time (float, optional) – A time to start detecting. Defaults to 0.0.

  • exposure_time (float, optional) – An exposure time. Defaults to detector_exposure_time in the configuration.

  • method (str, optional) – A name of method used. The default is None (‘default’).

  • config (Configuration, optional) – Configurations. The default is None.

  • rng (numpy.RandomState, optional) – A random number generator. The default is None.

  • full_output (bool, optional) – True to return a dictionary containing optional outputs.

Yields

Image – An image. dict: only returned if full_output == True

A dictionary containing additional information. ‘expectation’ is 2-dimensional ndarray. ‘true_data’ is a dictionary containing pairs of a molecule ID and ndarray. The array has 7 elements, which are exposure time, photon state, X and Y in pixels, X and Y in meter-scale, and normalization. If ‘photo_bleaching’ is active, ‘fluorescence_states’ contains pairs of a molecule ID and remaining photon budget.

scopyon.sample(t, N, *, lower=None, upper=None, D=None, transmat=None, ndim=3, periodic=False, rng=None)

Generate the points.

Parameters
  • t (arraylike) – The time points.

  • N (int or list) – The initial number of points for each state.

  • upper (Number or array, optional) – An upper limit of the position. Defaults to 1.

  • lower (Number or array, optional) – A lower limit of the position. Defaults to 0.

  • D (float or array-like, optional) – Diffusion constants. It is a constant or an array for each state. Defaults to 0.0.

  • transmat (array-like, optional) – A state transition rate matrix. It must be a square matrix of size n, where n is the number of states.

  • ndim (int, optional) –

  • periodic (bool, optional) – Defaults to False.

  • rng (numpy.RandomState, optional) – A random number generator.

Returns

A list of points at each time point. An array of points. Each point consists of a coordinate, state, and its index.

scopyon.sample_inputs(t, *, N=None, conc=None, lower=None, upper=None, D=None, start=0, ndim=3, rng=None)

Generate the input data.

Parameters
  • t (arraylike) – The time points.

  • N (int or list, optional) – The number of points to be generated.

  • conc (float or list, optional) – The concentration of points. Either one of N or conc must be given.

  • upper (Number or array, optional) – An upper limit of the position. Defaults to 1.

  • lower (Number or array, optional) – A lower limit of the position. Defaults to 0.

  • D (float or array-like, optional) – Diffusion constants. It is a constant or an array contains constants along with each axis. Defaults to 0.0.

  • ndim (int, optional) –

  • start (int, optional) – The first index. Defaults to 0.

  • rng (numpy.RandomState, optional) – A random number generator.

Returns

A pair of an array and the last ID.

An array of points. Each point consists of a coordinate, an index, p_state (defaults to 1) and cyc_id (defaults to inf).

The last ID. The sum of start and the number of points generated.

scopyon._plotly.show(img, shapes=None)

Show an image.

Note

Requires plotly.express.

Parameters
  • img (ndarray) – An image data to be shown.

  • shapes (list, optional) – A list of shapes. shape is a dictionary consisting of x (row), y (column), sigma and color. sigma is a half size of the box (square).

scopyon._matplotlib.show(img, shapes=None)

Show an image.

Parameters
  • img (ndarray) – An image data to be shown.

  • shapes (list, optional) – A list of shapes. shape is a dictionary consisting of x (row), y (column), sigma and color. sigma is a half size of the box (square).

class scopyon.analysis.FullPTHMM(n_components=1, min_var=1e-05, startprob_prior=1.0, transmat_prior=1.0, algorithm='viterbi', random_state=None, n_iter=10, tol=0.01, verbose=False, params='stdmv', init_params='stdmv')

Bases: hmmlearn.base._BaseHMM

Hidden Markov Model for Particle Tracking.

Parameters
  • n_components (int) – Number of states.

  • min_var (float, optional) – Floor on the variance to prevent overfitting. Defaults to 1e-5.

  • startprob_prior (array, optional) – shape (n_components, ). Parameters of the Dirichlet prior distribution for startprob_.

  • transmat_prior (array, optional) – shape (n_components, n_components). Parameters of the Dirichlet prior distribution for each row of the transition probabilities transmat_.

  • algorithm (string, optional) – Decoder algorithm. Must be one of “viterbi” or`”map”. Defaults to “viterbi”.

  • random_state (RandomState or an int seed, optional) – A random number generator instance.

  • n_iter (int, optional) – Maximum number of iterations to perform.

  • tol (float, optional) – Convergence threshold. EM will stop if the gain in log-likelihood is below this value.

  • verbose (bool, optional) – When True per-iteration convergence reports are printed to sys.stderr. You can diagnose convergence via the monitor_ attribute.

  • params (string, optional) – Controls which parameters are updated in the training process. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘d’ for diffusivities, ‘m’ for intensity means and ‘v’ for intensity variances. Defaults to all parameters.

  • init_params (string, optional) – Controls which parameters are initialized prior to training. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘d’ for diffusivities, ‘m’ for intensity means and ‘v’ for intensity variances. Defaults to all parameters.

monitor\_

Monitor object used to check the convergence of EM.

Type

ConvergenceMonitor

startprob\_

shape (n_components, ). Initial state occupation distribution.

Type

array

transmat\_

shape (n_components, n_components). Matrix of transition probabilities between states.

Type

array

diffusivities\_

shape (n_components, 1). Diffusion constants for each state.

Type

array

intensity_means\_

shape (n_components, 1). Mean parameters of intensity distribution for each state.

Type

array

intensity_vars\_

shape (n_components, 1). Variance parameters of intensity distribution for each state.

Type

array

class scopyon.analysis.PTHMM(n_diffusivities=3, n_oligomers=4, min_var=1e-05, startprob_prior=1.0, transmat_prior=1.0, algorithm='viterbi', random_state=None, n_iter=10, tol=0.01, verbose=False, params='stdmv', init_params='stdmv')

Bases: hmmlearn.base._BaseHMM

Hidden Markov Model for Particle Tracking.

Parameters
  • n_diffusivities (int) – Number of diffusivity states.

  • n_oligomers (int) – Number of oligomeric states. n_components is equal to (n_diffusivities * n_oliogmers).

  • min_var (float, optional) – Floor on the variance to prevent overfitting. Defaults to 1e-5.

  • startprob_prior (array, optional) – shape (n_components, ). Parameters of the Dirichlet prior distribution for startprob_.

  • transmat_prior (array, optional) – shape (n_components, n_components). Parameters of the Dirichlet prior distribution for each row of the transition probabilities transmat_.

  • algorithm (string, optional) – Decoder algorithm. Must be one of “viterbi” or`”map”. Defaults to “viterbi”.

  • random_state (RandomState or an int seed, optional) – A random number generator instance.

  • n_iter (int, optional) – Maximum number of iterations to perform.

  • tol (float, optional) – Convergence threshold. EM will stop if the gain in log-likelihood is below this value.

  • verbose (bool, optional) – When True per-iteration convergence reports are printed to sys.stderr. You can diagnose convergence via the monitor_ attribute.

  • params (string, optional) – Controls which parameters are updated in the training process. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘d’ for diffusivities, ‘m’ for intensity means and ‘v’ for intensity variances. Defaults to all parameters.

  • init_params (string, optional) – Controls which parameters are initialized prior to training. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘d’ for diffusivities, ‘m’ for intensity means and ‘v’ for intensity variances. Defaults to all parameters.

monitor\_

Monitor object used to check the convergence of EM.

Type

ConvergenceMonitor

startprob\_

shape (n_components, ). Initial state occupation distribution.

Type

array

transmat\_

shape (n_components, n_components). Matrix of transition probabilities between states.

Type

array

diffusivities\_

shape (n_diffusivities, 1). Diffusion constants for each state.

Type

array

intensity_means\_

shape (1, 1). Base mean parameter of intensity distributions.

Type

array

intensity_vars\_

shape (1, 1). Base Variance parameter of intensity distributions.

Type

array

scopyon.analysis.blob_detection(data, min_sigma=1, max_sigma=50, num_sigma=10, threshold=0.2, overlap=0.5)

Finds blobs in the given image. See also http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.blob_log

Note

Requires scikit-image.

Parameters
  • data (ndarray) – An image data.

  • min_sigma (float, optional) – The minimum standard deviation. Keep this low to detect smaller blobs. Defaults to 1.

  • max_sigma (float, optional) – The maximum standard deviation. Keep this high to detect larger blobs. Defaults to 50.

  • num_sigma (int, optional) – The number of intermediate values between min_sigma and max_sigma. Defaults to 10.

  • threshold (float, optional) – The absolute lower bound for scale space maxima. Reduce this to detect blobs with less intensities.

  • overlap (float, optional) – A value between 0 and 1.

Returns

Blobs detected.

Each row represents coordinates and the standard deviation, (x, y, r).

Return type

ndarray

scopyon.analysis.spot_detection(data, roi_size=6, blobs=None, processes=None, **kwargs)

Finds spots in the given image.

Note

Requires scipy.

Parameters
  • data (ndarray) – An image data.

  • roi_size (float, optional) – A default value of a half of the ROI size. Defaults to 6.

  • blobs (ndarray, optional) – Blobs. Defaults to None. See also blob_detection.

Returns

Spots detected.

Each row represents center position x, y, intensity, background, height, and sigma, (center_x, center_y, intensity, bg, height, sigma).

Return type

ndarray

scopyon.constants.Q_

alias of pint.quantity.build_quantity_class.<locals>.Quantity

class scopyon.constants.Quantity(value, units=None)

Bases: pint.quantity.Quantity