{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial about localizations per frame" ] }, { "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": "raw", "metadata": {}, "source": [ "path = TEST_DIR / 'test_data/rapidSTORM_dstorm_data.txt'\n", "print(path, '\\n')\n", "\n", "dat = lc.load_rapidSTORM_file(path=path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or get data with more localizations:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "dat = lc.load_tubulin()" ] }, { "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=500, rescale=lc.Trafo.EQUALIZE_0P3);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analyze localizations per frame" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have a look at the number of localizations that were detected in each frame. \n", "\n", "The analysis class Localizations_per_frame provides numerical results, a plot of results versus frame, and a density graph (histogram)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf = lc.LocalizationsPerFrame()\n", "lpf.compute(dat)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf.results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(lpf.results.time_series.head())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The plot shows results smoothed by a running average according to the specified window." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf.plot(window=10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The histogram per default provides automatic bins, is normalized to show a probability density function and estimates a normal distribution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf.hist();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The accumulation time is the time at which `fraction` of the cumulative intensity is reached." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf.results.accumulation_time()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot normalized values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can normalize the number of localizations to any other LocData property." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dat.properties" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf = lc.LocalizationsPerFrame(norm='region_measure_bb').compute(dat)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lpf.hist();" ] } ], "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 }