locan.analysis.local_density.LocalDensity

class locan.analysis.local_density.LocalDensity(radii, density=True, boundary_correction=False, normalization=None, meta=None)[source]

Bases: _Analysis

Compute the local density for two- or three-dimensional data. A local density is computed from the number of neighboring localizations within a specified radius.

Parameters:
  • radii (npt.ArrayLike) – Radii in which to search for neighboring points.

  • density (bool) – If true, the number of neighboring points is normalized by the local region_measure according to radius; else, the absolute number of points is returned.

  • boundary_correction (bool) – If true, the number of points is corrected for boundary effects. The boundary is set by the region of locdata.

  • normalization (float | npt.ArrayLike | None) – If not None, the number of neighboring points is normalized by this number (in addition to the optional density normalization).

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

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

  • parameter (dict) – A dictionary with all settings for the current computation.

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

  • results (pandas.DataFrame) – Data frame with radii as index and local densities.

Methods

__init__(radii[, density, ...])

compute(locdata[, other_locdata])

Run the computation.

hist([ax, bins, density])

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, other_locdata=None)[source]

Run the computation.

Parameters:
  • locdata (LocData) – Localization data with 2D or 3D coordinates on which to estimate local density.

  • other_locdata (LocData | None) – Other localization data from which to estimate local density. For None other_points is set to points (default).

Return type:

Self

count: int = 0

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

hist(ax=None, bins='auto', density=True, **kwargs)[source]

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

Parameters:
  • ax (Axes | None) – The axes on which to show the image.

  • bins (Union[int, list[int | float], Literal['auto']]) – Bin specification as used in matplotlib.hist()

  • density (bool) – Flag for normalization as used in matplotlib.hist. True returns probability density function; None returns counts.

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

Returns:

Axes object with the plot.

Return type:

matplotlib.axes.Axes