locan.analysis.nearest_neighbor.NearestNeighborDistances#

class locan.analysis.nearest_neighbor.NearestNeighborDistances(meta=None, k=1)[source]#

Bases: _Analysis

Compute the k-nearest-neighbor distances within data or between data and other_data.

The algorithm relies on sklearn.neighbors.NearestNeighbors.

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

  • k (int) – Compute the kth nearest neighbor.

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) – Computed results.

  • distribution_statistics (Distribution_stats | None) – Distribution parameters derived from MLE fitting of results.

Methods

__init__([meta, k])

compute(locdata[, other_locdata])

Run the computation.

fit_distributions([with_constraints])

Fit probability density functions to the distributions of loc_property values in the results using MLE (scipy.stats).

hist([ax, bins, density, 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, other_locdata=None)[source]#

Run the computation.

Parameters:
  • locdata (LocData) – Localization data.

  • other_locdata (Optional[LocData]) – Other localization data from which nearest neighbors are taken.

Return type:

Self

count: int = 0#

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

fit_distributions(with_constraints=True)[source]#

Fit probability density functions to the distributions of loc_property values 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:

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

Return type:

None

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

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

Parameters:
  • ax (Optional[Axes]) – 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.

  • fit (bool) – Flag indicating to fit pdf of nearest-neighbor distances under complete spatial randomness.

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

Returns:

Axes object with the plot.

Return type:

matplotlib.axes.Axes