{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial about nearest neighbor distances" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "%matplotlib inline\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "import locan as lc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lc.show_versions(system=False, dependencies=False, verbose=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# A path in which test data can be found:\n", "TEST_DIR: Path = Path.cwd().parents[2] / \"tests\"\n", "TEST_DIR" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load rapidSTORM data file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Identify some data in the test_data directory and provide a path using pathlib.Path" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = TEST_DIR / 'test_data/rapidSTORM_dstorm_data.txt'\n", "print(path, '\\n')\n", "\n", "dat = lc.load_rapidSTORM_file(path=path, nrows=1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print information about the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(dat.data.head(), '\\n')\n", "print('Summary:')\n", "dat.print_summary()\n", "print('Properties:')\n", "print(dat.properties)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lc.render_2d(dat, bin_size=1000, rescale=(0,100));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Analyze nearest neighbor distances" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The k-nearest neighbor distances can be analyzed for all localizations or a random subset." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn = lc.NearestNeighborDistances()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn.compute(dat)\n", "nn.results.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The histogram shows the experimental distribution and for comparision the expectation for a spatial distribution of complete spatial randomness given the experimental localization density (per default relative to the minimum bounding box region)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn.hist();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The localization_density relative to the minimum bounding box region is retweated by the localization_density attribute." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn.localization_density" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Meta data for the analysis procedure" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nn.meta" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }