Tutorial about localizations per frame#
from pathlib import Path
%matplotlib inline
import matplotlib.pyplot as plt
import locan as lc
lc.show_versions(system=False, dependencies=False, verbose=False)
Locan:
version: 0.20.0.dev41+g755b969
Python:
version: 3.11.6
Load rapidSTORM data file#
Identify some data in the test_data directory and provide a path using pathlib.Path
path = lc.ROOT_DIR / 'tests/test_data/rapidSTORM_dstorm_data.txt'
print(path, '\n')
dat = lc.load_rapidSTORM_file(path=path, nrows=1000)
/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/locan/tests/test_data/rapidSTORM_dstorm_data.txt
Jupyter environment detected. Enabling Open3D WebVisualizer.
[Open3D INFO] WebRTC GUI backend enabled.
[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.
Print information about the data:
print(dat.data.head(), '\n')
print('Summary:')
dat.print_summary()
print('Properties:')
print(dat.properties)
position_x position_y frame intensity chi_square local_background
0 9657.40 24533.5 0 33290.10 1192250.0 767.732971
1 16754.90 18770.0 0 21275.40 2106810.0 875.460999
2 14457.60 18582.6 0 20748.70 526031.0 703.369995
3 6820.58 16662.8 0 8531.77 3179190.0 852.789001
4 19183.20 22907.2 0 14139.60 448631.0 662.770020
Summary:
identifier: "1"
comment: ""
source: EXPERIMENT
state: RAW
element_count: 14
frame_count: 1
file {
type: RAPIDSTORM
path: "/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/locan/tests/test_data/rapidSTORM_dstorm_data.txt"
}
creation_time {
2024-03-14T11:07:44.308119Z
}
Properties:
{'localization_count': 14, 'position_x': 15873.847142857145, 'uncertainty_x': 2361.4490857013648, 'position_y': 17403.909285714286, 'uncertainty_y': 1803.9975262697349, 'intensity': 183987.66999999998, 'local_background': 675.0614, 'frame': 0, 'region_measure_bb': 730882123.3259, 'localization_density_bb': 1.915493559521281e-08, 'subregion_measure_bb': 108337.2}
Visualization#
lc.render_2d(dat, bin_size=500, rescale=lc.Trafo.EQUALIZE_0P3);
Analyze localizations per frame#
We have a look at the number of localizations that were detected in each frame.
The analysis class Localizations_per_frame provides numerical results, a plot of results versus frame, and a density graph (histogram).
lpf = lc.LocalizationsPerFrame()
lpf.compute(dat)
LocalizationsPerFrame(norm=None, time_delta=integration_time, resample=None)
lpf.results
<locan.analysis.localizations_per_frame._Results at 0x7f0a1c93c990>
print(lpf.results.time_series.head())
frame
0 14.0
Name: n_localizations, dtype: float64
The plot shows results smoothed by a running average according to the specified window.
lpf.plot(window=10);
The histogram per default provides automatic bins, is normalized to show a probability density function and estimates a normal distribution.
lpf.hist();
/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py:2244: RuntimeWarning: invalid value encountered in multiply
lower_bound = _a * scale + loc
/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py:2245: RuntimeWarning: invalid value encountered in multiply
upper_bound = _b * scale + loc
The accumulation time is the time at which fraction
of the cumulative intensity is reached.
lpf.results.accumulation_time()
0
Plot normalized values#
We can normalize the number of localizations to any other LocData property.
dat.properties
{'localization_count': 14,
'position_x': 15873.847142857145,
'uncertainty_x': 2361.4490857013648,
'position_y': 17403.909285714286,
'uncertainty_y': 1803.9975262697349,
'intensity': 183987.66999999998,
'local_background': 675.0614,
'frame': 0,
'region_measure_bb': 730882123.3259,
'localization_density_bb': 1.915493559521281e-08,
'subregion_measure_bb': 108337.2}
lpf = lc.LocalizationsPerFrame(norm='region_measure_bb').compute(dat)
lpf.hist();
/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py:2244: RuntimeWarning: invalid value encountered in multiply
lower_bound = _a * scale + loc
/home/docs/checkouts/readthedocs.org/user_builds/locan/envs/latest/lib/python3.11/site-packages/scipy/stats/_distn_infrastructure.py:2245: RuntimeWarning: invalid value encountered in multiply
upper_bound = _b * scale + loc