locan.analysis.blinking.BlinkStatistics#

class locan.analysis.blinking.BlinkStatistics(meta=None, memory=0, remove_heading_off_periods=True)[source]#

Bases: _Analysis

Estimate on and off times from the frame values provided.

On and off-periods and the first frame of each period are determined from the sorted frame values. A series of frame values that constantly increase by one is considered an on-period. Each series of missing frame values between two given frame values is considered an off-period.

A log warning is provided if a frame number occurs multiple times.

Missing localizations within an on-period can be taken into account by increasing the memory parameter. There is no way to correct for false positive localizations.

Parameters:
  • memory (int) – The maximum number of intermittent frames without any localization that are still considered to belong to the same on-period.

  • remove_heading_off_periods (bool) – Flag to indicate if off-periods at the beginning of the series are excluded.

  • meta (metadata_analysis_pb2.AMetadata | None) – Metadata about the current analysis routine.

Variables:
  • count (int) – A counter for counting instantiations.

  • parameter (dict[str, Any]) – A dictionary with all settings for the current computation.

  • meta (metadata_analysis_pb2.AMetadata) – Metadata about the current analysis routine.

  • results (dict[str, npt.NDArray[np.int64 | np.float64] | list[int | float]] | None) – ‘on_periods’ and ‘off_periods’ in units of frame numbers. ‘on_periods_frame’ and ‘off_periods_frame’ with the first frame in each on/off-period. ‘on_periods_indices’ are groups of indices to the input frames or more precise np.unique(frames)

  • distribution_statistics (dict[str, Any]) – Distribution parameters derived from MLE fitting of results.

Methods

__init__([meta, memory, ...])

compute(locdata)

Run the computation.

fit_distributions([distribution, ...])

Fit probability density functions to the distributions of on- and off-periods in the results using MLE (scipy.stats).

hist([data_identifier, ax, bins, log, fit])

Provide histogram as matplotlib.axes.Axes object showing hist(results).

report(*args, **kwargs)

Show a report about analysis results.

Attributes

count

A counter for counting Analysis class instantiations (class attribute).

compute(locdata)[source]#

Run the computation.

Parameters:

locdata (Union[LocData, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – Localization data or just the frame values of given localizations.

Return type:

Self

count: int = 0#

A counter for counting Analysis class instantiations (class attribute).

fit_distributions(distribution=<scipy.stats._continuous_distns.expon_gen object>, data_identifier=('on_periods', 'off_periods'), with_constraints=True, **kwargs)[source]#

Fit probability density functions to the distributions of on- and off-periods in the results using MLE (scipy.stats).

If with_constraints is true we put the following constraints on the fit procedure: If distribution is expon then floc=np.min(self.analysis_class.results[self.loc_property].values).

Parameters:
  • distribution (str | rv_continuous) – Distribution model to fit.

  • data_identifier (str | Iterable[str]) – String to identify the data in results for which to fit an appropriate distribution, here ‘on_periods’ or ‘off_periods’. For True all are fitted.

  • with_constraints (bool) – Flag to use predefined constraints on fit parameters.

  • kwargs (Any) – Other parameters are passed to the scipy.stat.distribution.fit() function.

Return type:

None

hist(data_identifier='on_periods', ax=None, bins='auto', log=True, fit=True, **kwargs)[source]#

Provide histogram as matplotlib.axes.Axes object showing hist(results).

Parameters:
  • data_identifier (str) – ‘on_periods’ or ‘off_periods’.

  • ax (Optional[Axes]) – The axes on which to show the image

  • bins (int | Sequence[int | float] | str) – Bin specifications (passed to matplotlib.hist()).

  • log (bool) – Flag for plotting on a log scale.

  • fit (Optional[bool]) – Flag indicating if distribution fit is shown. The fit will only be computed if distribution_statistics is None.

  • kwargs (Any) – Other parameters passed to matplotlib.pyplot.hist().

Returns:

Axes object with the plot.

Return type:

matplotlib.axes.Axes