Tutorial about example datasets¶
import sys
from pathlib import Path
import shutil
import logging
import httpx
import locan as lc
lc.show_versions(system=False, dependencies=False, verbose=False)
Locan:
version: 0.22.0.dev32+g4bfc3ab8b
Python:
version: 3.11.14
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger()
Load SMLM data from LocanDatasets¶
Selected example datasets are provided in a separate directory (repository) called LocanDatasets.
These datasets can be loaded by ready-to-go utility functions.
Set up a datasets directory¶
lc.DATASETS_DIR = Path.home() / 'LocanDatasets'
lc.DATASETS_DIR.mkdir(exist_ok=True)
Load dSTORM data of nuclear pore complexes¶
This is a rather large 2D dataset with > 2 mio localizations.
url = "https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/npc_gp210.asdf"
response = httpx.get(url)
print("Response is ok: ", response.status_code == httpx.codes.ok)
2026-04-30 08:37:29,000 - httpx - INFO - HTTP Request: GET https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/npc_gp210.asdf "HTTP/1.1 200 OK"
Response is ok: True
response.status_code
200
file_path = lc.DATASETS_DIR / 'npc_gp210.asdf'
with open(file_path, 'wb') as file:
for chunk in response.iter_bytes(chunk_size=128):
file.write(chunk)
file_path
PosixPath('/home/docs/LocanDatasets/npc_gp210.asdf')
dat = lc.load_npc()
Print information about the data:
print('Data head:')
print(dat.data.head(), '\n')
print('Summary:')
dat.print_summary()
print('Properties:')
print(dat.properties)
Data head:
position_x position_y frame intensity two_kernel_improvement \
0 5768.129883 20242.400391 0 83745.398438 0.0
1 21402.800781 18154.599609 0 67648.296875 0.0
2 11410.700195 3155.639893 0 73358.398438 0.0
3 15570.599609 15854.599609 0 65827.898438 0.0
4 22235.500000 12840.900391 0 56347.398438 0.0
chi_square local_background
0 4355630.0 1511.459961
1 8383720.0 1637.000000
2 2420450.0 1480.380005
3 2539930.0 1540.670044
4 16152800.0 1572.040039
Summary:
identifier: "13"
comment: ""
source: EXPERIMENT
state: RAW
element_count: 2285189
frame_count: 24999
file {
type: ASDF
path: "/home/docs/LocanDatasets/npc_gp210.asdf"
}
creation_time {
2026-04-30T08:37:30.285749Z
}
Properties:
{'localization_count': 2285189, 'position_x': np.float64(14570.820174404367), 'uncertainty_x': np.float64(5.195636170641695), 'position_y': np.float64(12028.219687728053), 'uncertainty_y': np.float64(4.523940296807998), 'intensity': np.float32(30375694000.0), 'local_background': np.float32(1124.8801), 'frame': np.int16(0), 'region_measure_bb': np.float32(655392800.0), 'localization_density_bb': np.float32(0.0034867474), 'subregion_measure_bb': np.float32(103168.0)}
lc.render_2d(dat, bin_size=100, rescale=lc.Trafo.EQUALIZE_0P3);
lc.render_2d(dat, bin_size=10, rescale=lc.Trafo.EQUALIZE_0P3,
bin_range=((0, 5000), (0, 5000)));
Load dSTORM data of microtubules¶
This is a rather large 2D dataset with about 1.5 mio localizations.
url = "https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/tubulin_cos7.asdf"
response = httpx.get(url)
print("Response is ok: ", response.status_code == httpx.codes.ok)
2026-04-30 08:37:30,682 - httpx - INFO - HTTP Request: GET https://raw.githubusercontent.com/super-resolution/LocanDatasets/main/smlm_data/tubulin_cos7.asdf "HTTP/1.1 200 OK"
Response is ok: True
file_path = lc.DATASETS_DIR / 'tubulin_cos7.asdf'
with open(file_path, 'wb') as file:
for chunk in response.iter_bytes(chunk_size=128):
file.write(chunk)
file_path
PosixPath('/home/docs/LocanDatasets/tubulin_cos7.asdf')
dat = lc.load_tubulin()
Print information about the data:
print('Data head:')
print(dat.data.head(), '\n')
print('Summary:')
dat.print_summary()
print('Properties:')
print(dat.properties)
Data head:
position_x position_y frame intensity chi_square \
0 9937.400391 16751.300781 0 40501.601562 3744920.0
1 9998.709961 12022.799805 0 36280.300781 14295400.0
2 9566.769531 8078.229980 0 29984.000000 12302200.0
3 15492.500000 10120.400391 0 38488.300781 3219820.0
4 6381.459961 16057.700195 0 37093.300781 1620450.0
local_background
0 709.413025
1 800.455017
2 890.807007
3 495.067993
4 476.035004
Summary:
identifier: "7"
comment: ""
source: EXPERIMENT
state: RAW
element_count: 1506568
frame_count: 74969
file {
type: ASDF
path: "/home/docs/LocanDatasets/tubulin_cos7.asdf"
}
creation_time {
2026-04-30T08:37:31.995064Z
}
Properties:
{'localization_count': 1506568, 'position_x': np.float64(8833.605738466662), 'uncertainty_x': np.float64(4.053253266247036), 'position_y': np.float64(10446.826432598386), 'uncertainty_y': np.float64(3.278383909327508), 'intensity': np.float32(19965508000.0), 'local_background': np.float32(284.22076), 'frame': np.int32(0), 'region_measure_bb': np.float32(289612320.0), 'localization_density_bb': np.float32(0.0052020163), 'subregion_measure_bb': np.float32(68072.0)}
lc.render_2d(dat, bin_size=100, rescale=lc.Trafo.EQUALIZE_0P3);
lc.render_2d(dat, bin_size=10, rescale=lc.Trafo.EQUALIZE_0P3,
bin_range=((0, 4000), (6000, 10_000)));