{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial about localization precision" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Localization precision is determined from consecutive localizations that are identified within a certain search radius. The results include the distances between localization pairs, the position deltas for each coordinate and the corresponding frame of the first localizations." ] }, { "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 SMLM data file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Identify some data in the test_data directory and provide a path using `pathlib.Path` (returned by `lc.ROOT_DIR`)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path = TEST_DIR / 'test_data/npc_gp210.asdf'\n", "print(path, '\\n')\n", "dat = lc.load_locdata(path=path, file_type=lc.FileType.ASDF)" ] }, { "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=10, rescale=(0,100));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Analyze localization precision" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp = lc.LocalizationPrecision(radius=50)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.compute(dat)\n", "lp.results.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.plot(loc_property='position_delta_x', window=10);" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.plot(window=10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The histogram for the distances per default includes a fit to a distribution expected for normal distributed localizations. Sigma / sqrt(2) is the localization precision." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.hist();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively the position deltas can be histogrammed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(nrows=1, ncols=2)\n", "lp.hist(ax=ax[0], loc_property='position_delta_x')\n", "lp.hist(ax=ax[1], loc_property='position_delta_y')\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fit distributions and show parameters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Appropriate distribution functions are fitted to the data either by calling the hist function or by running:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.fit_distributions()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The estimated fit parameters are provided under the `distribution_statistics` attribute" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lp.distribution_statistics.parameter_dict()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remember: localization precision is typically defined as the standard deviation for the distances between localizations and their center position (the true dye position). Therefore, the estimated sigmas have to be divided by sqrt(2) to yield localization precision." ] } ], "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 }