Write the single-molecule localisation program of a microscopy core's TIRF set-up (EMCCD photon conversion with the camera's gain history, PSF photometry from bead z-stacks, two-colour splitter, focus and hot-pixel handling, calibrated precision) under a time limit; it is run on further acquisitions with known molecule positions and photon numbers.
harbor run -t reactive-labs/smt-localisationharbor download reactive-labs/smt-localisationYou are Samir Haddad, staff scientist for image analysis in the Light Microscopy Core of the Tarnwell Institute for
Cell Biology. The core runs TIRF-2, a single-molecule TIRF set-up with an EMCCD camera and a two-colour image
splitter. Today is Monday 30 November 2026. Ingrid Valtonen, head of the core, wants the program that will localise
every single-molecule tracking movie from TIRF-2 on the core's analysis server from December. Her mail is in
/app/inputs/mail/.
You have 60 minutes. Whatever is in /app/output when the time is up is graded, so keep a working program saved as
you go.
In /app/inputs:
acquisitions/: the twelve movies of the users' current projects, one folder each with the Halde Acquire record
(.ini) and the raw frames (.raw), and manifest.csv.calibration/: PSF z-stacks of beads, dark references, registration-bead stacks, the monthly EM gain checks and
the camera's defect map from commissioning.docs/: LMC-SOP-031 rev C, the camera test sheet and an excerpt of its manual, the grid calibration report, the
vendor's service report and the TIRF-2 logbook export.legacy/: spotfit_v2.py, the script the users have been running, and its author's handover notes./app/output/smt_localise.py, run as
python3 /app/output/smt_localise.py <acquisition_dir> <out.csv>
It reads one acquisition folder in the layout of those in hand and writes the localisation table of SOP-031 section 8: a comma-separated file with a header line and one row per spot (molecule or bead) and frame, with at least these columns:
| Column | Content |
|---|---|
frame |
frame index in the movie, 0-based, dark frames counted |
channel |
1 for direct-path movies and Duet-2 channel 1, 2 for Duet-2 channel 2 |
x_nm, y_nm |
position in nm in the sample plane, from the outer corner of the first pixel of the channel's region, x along chip columns and y along rows |
photons |
total detected photons of the spot in that frame |
background |
background photons per pixel per frame at the spot, without the spot's own light |
precision_nm |
estimated 1-sigma localisation error per axis |
The program runs with Python 3.12, numpy, scipy and pandas, on one CPU core with 3 GB of memory and no network,
and must finish each acquisition within 45 seconds. Acquisitions have up to 3000 frames (two-colour up to 1500)
of 64 x 64 or 64 x 136 pixels. It is run as another user from a copy of /app/output: it may load helper files
that you put in /app/output (found relative to __file__), but /app/inputs is not there when it runs.
/app/output/results/<acquisition>.csv for each of the twelve acquisitions in hand (for example
/app/output/results/20260309_EGFR_d1_c03.csv): the program's table for that movie.
Rafael runs the program on the core's validation set: 30 further TIRF-2 acquisitions that the core generates with its model of the instrument (this camera, its optics and its history) from known molecule positions and photon numbers. Twelve re-image the cells of the movies in hand in other sessions; eighteen use protocols, readout settings and dates that SOP-031 and the logbook allow, some of which the movies in hand show once or not at all. The twelve tables in hand are compared with their known values in the same way.
In each frame and channel, reported spots are paired with true emitters within 200 nm by minimum total distance. An emitter with fewer photons than max(40, 4 x sqrt(4 pi s^2 b)) (s the PSF sigma in pixels, b its background), with motion blur above 1 pixel rms, more than 0.5 um out of focus, within 1 pixel of the region edge or within 2 pixels of a brighter emitter is neither required nor counted against you. Other unpaired rows count as false spots and unpaired emitters as missed. Per acquisition five quantities are formed and compared with the core's reference pipeline on the same acquisition:
| Quantity | Definition | Full credit | No credit |
|---|---|---|---|
| Detection | Jaccard index, paired / (paired + false + missed) | at most 0.025 below the reference | 0.20 below |
| Position | robust SD (1.4826 x median absolute value) of the x and y errors, each divided by the emitter's Cramer-Rao bound | at most 6 % above the reference | 18 % above |
| Photons | median of reported / true photons over paired molecules | within the reference's deviation from 1 (at least 2 %) plus 3 % | plus 9 % |
| Background | median of reported / true background over paired molecules | within the reference's deviation (at least 3 %) plus 4 % | plus 12 % |
| Precision | robust SD of the x and y errors, each divided by the reported precision_nm |
within the reference's deviation from 1 (at least 3 %) plus 6 % | plus 18 % |
Credit falls linearly between the two columns. Acquisition score = detection credit x (0.30 position + 0.30 photons