AdamGohain commited on
Commit
2645108
·
verified ·
1 Parent(s): 19cbee7

Add selective real imaging pilots and standalone benchmark client

Browse files
.gitattributes CHANGED
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ assets/dandi-000715-sub-56-YAaDV/reference.nwb filter=lfs diff=lfs merge=lfs -text
LICENSE-code.txt ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WormTrack-Verify contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
assets/ascent-opterra/pilot.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2e44df9e5f6f0a2b9273fc95cc7c3100ce19f547226deee34edb59f54cc93e6
3
+ size 17810930
assets/dandi-000541-sub-20190924-01/pilot.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9a74b74140fd2b5a20af8bc3d1d1da5045a60dc39f2e20012425b2fd8eca9a7
3
+ size 250230
assets/dandi-000715-sub-56-YAaDV/reference.nwb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8fac20135945a039301002a68fbc12b5384b36642f26d60f81bc7ecbaf2aa009
3
+ size 77073624
assets/nerve-al-w1-via-zephir/annotations.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1b4531260e8cace262c6caf517a13d565c431bbc071df7fb297209fa30757b7
3
+ size 3887104
assets/nerve-al-w1-via-zephir/metadata.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "shape_t": 1536,
3
+ "shape_c": 2,
4
+ "shape_z": 33,
5
+ "shape_y": 600,
6
+ "shape_x": 600,
7
+ "t_ref_fn1536": [
8
+ 412,
9
+ 539,
10
+ 182,
11
+ 908,
12
+ 1246,
13
+ 489,
14
+ 270,
15
+ 690,
16
+ 808,
17
+ 1260
18
+ ]
19
+ }
assets/nerve-al-w1-via-zephir/worldlines.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e919f281c5448f613713abe297206ffcff1d981498a068bad954e822c2c3b8a4
3
+ size 3568
assets/targettrack-epfl10/pilot.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c79b0601b33363893040cac97976ec29abc11b09dd60ad5be704a23fc31376ea
3
+ size 465651
assets/zephir-zm9624/annotations.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8b91f55ce566146ab7cc75f5f1c32bc5e83cc080fa3d64caa165a28e0fd0456
3
+ size 6041856
assets/zephir-zm9624/metadata.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "shape_t": 1060,
3
+ "shape_c": 2,
4
+ "shape_z": 23,
5
+ "shape_y": 512,
6
+ "shape_x": 512,
7
+ "dtype": "np.uint8",
8
+ "t_ref": [
9
+ 498,
10
+ 444,
11
+ 463
12
+ ],
13
+ "t_ref_fn1060": [
14
+ 271,
15
+ 640,
16
+ 764,
17
+ 149,
18
+ 1038,
19
+ 95,
20
+ 806
21
+ ]
22
+ }
assets/zephir-zm9624/pilot.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c14ab5c0dca0a0b2064fe860a22afc4791db64546897f3f208616b0831143f81
3
+ size 786338
assets/zephir-zm9624/timestamps_s.json ADDED
@@ -0,0 +1 @@
 
 
1
+ [1631827565.191196, 1631827565.4415264, 1631827565.6868942, 1631827565.9392192, 1631827566.1925423, 1631827566.4319212, 1631827566.697213, 1631827566.9345777, 1631827567.1829135, 1631827567.443218, 1631827567.6845732, 1631827567.9449098, 1631827568.1882596, 1631827568.4455714, 1631827568.693908, 1631827568.9342654, 1631827569.196564, 1631827569.443903, 1631827569.6912696, 1631827569.943595, 1631827570.1939259, 1631827570.4412646, 1631827570.6846142, 1631827570.949905, 1631827571.1922803, 1631827571.4426107, 1631827571.6839657, 1631827571.95225, 1631827572.1896143, 1631827572.4489617, 1631827572.6893198, 1631827572.9496245, 1631827573.1919754, 1631827573.4503264, 1631827573.6876915, 1631827573.9499905, 1631827574.192342, 1631827574.4456851, 1631827574.6920266, 1631827574.9493387, 1631827575.1887298, 1631827575.436069, 1631827575.687398, 1631827575.935733, 1631827576.1860638, 1631827576.4373922, 1631827576.6897173, 1631827576.9380538, 1631827577.1933708, 1631827577.4387155, 1631827577.689046, 1631827577.9374006, 1631827578.2036886, 1631827578.446041, 1631827578.6933799, 1631827578.950692, 1631827579.1970334, 1631827579.4473963, 1631827579.6887512, 1631827579.9510503, 1631827580.1953967, 1631827580.4487193, 1631827580.6890957, 1631827580.9394264, 1631827581.1937482, 1631827581.4510586, 1631827581.690419, 1631827581.9487514, 1631827582.1901069, 1631827582.4404368, 1631827582.6947572, 1631827582.9531088, 1631827583.1934557, 1631827583.4517653, 1631827583.6971092, 1631827583.9454458, 1631827584.2017803, 1631827584.444132, 1631827584.700476, 1631827584.950807, 1631827585.2061245, 1631827585.4474788, 1631827585.7057889, 1631827585.944177, 1631827586.2024863, 1631827586.4428437, 1631827586.7031717, 1631827586.9485161, 1631827587.2018385, 1631827587.4432156, 1631827587.691552, 1631827587.9438894, 1631827588.1942315, 1631827588.4545357, 1631827588.7018747, 1631827588.9512367, 1631827589.2065544, 1631827589.450901, 1631827589.704224, 1631827589.9475732, 1631827590.1969256, 1631827590.4532406, 1631827590.702574, 1631827590.9439292, 1631827591.1952572, 1631827591.4615636, 1631827591.7029192, 1631827591.9602306, 1631827592.199591, 1631827592.4539108, 1631827592.6952655, 1631827592.9496064, 1631827593.212901, 1631827593.4522614, 1631827593.7065814, 1631827593.9529226, 1631827594.1962917, 1631827594.4466226, 1631827594.6959558, 1631827594.9462864, 1631827595.2115777, 1631827595.4459507, 1631827595.6963007, 1631827595.9576025, 1631827596.202946, 1631827596.456269, 1631827596.6966267, 1631827596.9609509, 1631827597.2033033, 1631827597.44765, 1631827597.707954, 1631827597.9592822, 1631827598.2056239, 1631827598.4539597, 1631827598.711272, 1631827598.9546218, 1631827599.210936, 1631827599.4572778, 1631827599.699662, 1631827599.9609635, 1631827600.2063074, 1631827600.4576356, 1631827600.7049744, 1631827600.966276, 1631827601.2076557, 1631827601.459982, 1631827601.7053256, 1631827601.9656296, 1631827602.2019978, 1631827602.457336, 1631827602.710659, 1631827602.9570007, 1631827603.20035, 1631827603.4606538, 1631827603.710985, 1631827603.9593453, 1631827604.207682, 1631827604.457015, 1631827604.716322, 1631827604.957677, 1631827605.2050345, 1631827605.453371, 1631827605.7106826, 1631827605.9580214, 1631827606.2023683, 1631827606.4636905, 1631827606.7080371, 1631827606.9623575, 1631827607.2116907, 1631827607.45504, 1631827607.7193336, 1631827607.9527323, 1631827608.2040606, 1631827608.4693515, 1631827608.7087116, 1631827608.9660237, 1631827609.2153795, 1631827609.4637156, 1631827609.7040732, 1631827609.9683676, 1631827610.209721, 1631827610.4610674, 1631827610.7034197, 1631827610.954748, 1631827611.205596, 1631827611.4619105, 1631827611.7172282, 1631827611.9675975, 1631827612.2079551, 1631827612.467262, 1631827612.7156165, 1631827612.9599645, 1631827613.218273, 1631827613.46262, 1631827613.7159424, 1631827613.9562998, 1631827614.217601, 1631827614.4629452, 1631827614.7132978, 1631827614.9626312, 1631827615.214957, 1631827615.4642904, 1631827615.7176127, 1631827615.9629571, 1631827616.2128122, 1631827616.4651377, 1631827616.7075124, 1631827616.965822, 1631827617.222137, 1631827617.4635108, 1631827617.7078576, 1631827617.957191, 1631827618.2095163, 1631827618.4728134, 1631827618.7091808, 1631827618.9715102, 1631827619.2158568, 1631827619.459206, 1631827619.7225025, 1631827619.9668493, 1631827620.2092311, 1631827620.4615571, 1631827620.71089, 1631827620.9632154, 1631827621.2105541, 1631827621.459906, 1631827621.716221, 1631827621.9735336, 1631827622.2188768, 1631827622.467242, 1631827622.715578, 1631827622.9599473, 1631827623.212273, 1631827623.4745715, 1631827623.7149293, 1631827623.9742355, 1631827624.2176118, 1631827624.4619584, 1631827624.7132866, 1631827624.975586, 1631827625.22093, 1631827625.4662738, 1631827625.7236054, 1631827625.9629655, 1631827626.2282565, 1631827626.4706101, 1631827626.7119634, 1631827626.9633367, 1631827627.2276304, 1631827627.466991, 1631827627.7282915, 1631827627.9636624, 1631827628.2309477, 1631827628.4663186, 1631827628.723631, 1631827628.9759562, 1631827629.2252898, 1631827629.4636526, 1631827629.7159977, 1631827629.964334, 1631827630.2146647, 1631827630.4809527, 1631827630.7243292, 1631827630.9646864, 1631827631.2279825, 1631827631.4643507, 1631827631.7156787, 1631827631.9660292, 1631827632.2173574, 1631827632.4686852, 1631827632.7180188, 1631827632.9833097, 1631827633.2157207, 1631827633.479017, 1631827633.7193744, 1631827633.9667447, 1631827634.2280462, 1631827634.4703984, 1631827634.732697, 1631827634.9730544, 1631827635.223405, 1631827635.4667542, 1631827635.7310681, 1631827635.9744172, 1631827636.2287579, 1631827636.4701126, 1631827636.7264493, 1631827636.9717724, 1631827637.2340703, 1631827637.4704382, 1631827637.7327375, 1631827637.970124, 1631827638.2194574, 1631827638.4677937, 1631827638.7271001, 1631827638.9764338, 1631827639.2188094, 1631827639.4701378, 1631827639.7194712, 1631827639.9757857, 1631827640.2201326, 1631827640.489436, 1631827640.7218149, 1631827640.9711483, 1631827641.2384338, 1631827641.4708323, 1631827641.7211633, 1631827641.9745052, 1631827642.2328146, 1631827642.4751668, 1631827642.7374656, 1631827642.9818122, 1631827643.2212029, 1631827643.4795122, 1631827643.7218642, 1631827643.986158, 1631827644.2265153, 1631827644.4768665, 1631827644.7301896, 1631827644.9795232, 1631827645.2308512, 1631827645.4742007, 1631827645.7295182, 1631827645.9848354, 1631827646.2282186, 1631827646.4785495, 1631827646.7348645, 1631827646.9792113, 1631827647.2305396, 1631827647.4759023, 1631827647.7242382, 1631827647.9825664, 1631827648.235889, 1631827648.4772441, 1631827648.726577, 1631827648.9859102, 1631827649.2332492, 1631827649.4756014, 1631827649.7249346, 1631827649.9752655, 1631827650.2365873, 1631827650.477942, 1631827650.734276, 1631827650.9816146, 1631827651.2249641, 1631827651.476315, 1631827651.730635, 1631827651.983958, 1631827652.2273076, 1631827652.4806306, 1631827652.734969, 1631827652.988292, 1631827653.2346332, 1631827653.4829698, 1631827653.7293108, 1631827653.9886174, 1631827654.2339928, 1631827654.485321, 1631827654.7356513, 1631827654.9849846, 1631827655.227337, 1631827655.4846687, 1631827655.7419808, 1631827655.9843328, 1631827656.236658, 1631827656.4849944, 1631827656.7393143, 1631827656.9836812, 1631827657.2300224, 1631827657.4793558, 1631827657.7276921, 1631827657.989991, 1631827658.2283823, 1631827658.4926782, 1631827658.7330334, 1631827658.9803722, 1631827659.242671, 1631827659.4810338, 1631827659.7333786, 1631827659.9936826, 1631827660.23404, 1631827660.4883597, 1631827660.74268, 1631827660.990041, 1631827661.2353852, 1631827661.4877107, 1631827661.7300632, 1631827661.993359, 1631827662.2397008, 1631827662.4860618, 1631827662.7453692, 1631827662.9857264, 1631827663.2330894, 1631827663.4834204, 1631827663.745742, 1631827663.9870965, 1631827664.2384248, 1631827664.4827912, 1631827664.743095, 1631827664.98445, 1631827665.2467706, 1631827665.4841359, 1631827665.7474322, 1631827665.9818332, 1631827666.248121, 1631827666.4855187, 1631827666.7448256, 1631827666.9901693, 1631827667.2424948, 1631827667.4868417, 1631827667.7451513, 1631827667.9835374, 1631827668.2483368, 1631827668.486699, 1631827668.747003, 1631827668.9903524, 1631827669.2426984, 1631827669.4960213, 1631827669.7423632, 1631827669.9936912, 1631827670.2390354, 1631827670.4953501, 1631827670.744713, 1631827670.9950435, 1631827671.2453744, 1631827671.4867291, 1631827671.73706, 1631827671.9963858, 1631827672.2427275, 1631827672.4850793, 1631827672.7374046, 1631827672.9947364, 1631827673.236091, 1631827673.496395, 1631827673.741739, 1631827673.9870832, 1631827674.237414, 1631827674.4957235, 1631827674.7440786, 1631827674.996404, 1631827675.2487297, 1631827675.495071, 1631827675.7374234, 1631827675.999734, 1631827676.2430944, 1631827676.501405, 1631827676.7437563, 1631827677.0000713, 1631827677.2374368, 1631827677.4957666, 1631827677.738118, 1631827678.003409, 1631827678.2457845, 1631827678.4961152, 1631827678.7394898, 1631827679.0007913, 1631827679.2381568, 1631827679.499458, 1631827679.7438262, 1631827679.9981463, 1631827680.2435114, 1631827680.497831, 1631827680.749159, 1631827680.9945037, 1631827681.2518344, 1631827681.492192, 1631827681.77344, 1631827681.9918563, 1631827682.2431843, 1631827682.4995189, 1631827682.7508473, 1631827682.9951956, 1631827683.2535036, 1631827683.4958563, 1631827683.751173, 1631827684.0005066, 1631827684.244873, 1631827684.4981952, 1631827684.7505212, 1631827685.0048418, 1631827685.2521803, 1631827685.4995189, 1631827685.7518716, 1631827686.0022023, 1631827686.249541, 1631827686.504859, 1631827686.7472389, 1631827686.9925826, 1631827687.241916, 1631827687.493244, 1631827687.7605295, 1631827687.9929085, 1631827688.2512176, 1631827688.4975598, 1631827688.7429037, 1631827688.996226, 1631827689.2475543, 1631827689.4938958, 1631827689.7492135, 1631827690.0015388, 1631827690.2448883, 1631827690.504195, 1631827690.7465472, 1631827690.9938858, 1631827691.245214, 1631827691.4955451, 1631827691.7448783, 1631827691.9952092, 1631827692.24554, 1631827692.4958704, 1631827692.7462015, 1631827692.9975297, 1631827693.2458656, 1631827693.4961963, 1631827693.7485218, 1631827693.9978552, 1631827694.2461913, 1631827694.4965224, 1631827694.749845, 1631827694.9971838, 1631827695.2465174, 1631827695.4958508, 1631827695.7581496, 1631827695.998507, 1631827696.2468429, 1631827696.4991946, 1631827696.7485278, 1631827696.9998555, 1631827697.248192, 1631827697.4975255, 1631827697.7468781, 1631827697.9982066, 1631827698.2485373, 1631827698.4988682, 1631827698.7521908, 1631827698.9985323, 1631827699.2498825, 1631827699.4992154, 1631827699.749546, 1631827699.9988797, 1631827700.2492106, 1631827700.4995415, 1631827700.750901, 1631827701.0012317, 1631827701.2495675, 1631827701.501893, 1631827701.7512267, 1631827702.00056, 1631827702.251888, 1631827702.501222, 1631827702.7505548, 1631827703.001883, 1631827703.2512167, 1631827703.5015473, 1631827703.7518785, 1631827704.001212, 1631827704.2515426, 1631827704.5028715, 1631827704.752204, 1631827705.0035322, 1631827705.2528658, 1631827705.505191, 1631827705.7515326, 1631827706.0068507, 1631827706.2771282, 1631827706.5055172, 1631827706.7568455, 1631827707.0031867, 1631827707.2525198, 1631827707.5038488, 1631827707.7821045, 1631827708.0084991, 1631827708.2548406, 1631827708.5041742, 1631827708.7545047, 1631827709.00683, 1631827709.2551663, 1631827709.5064948, 1631827709.755828, 1631827710.006159, 1631827710.254495, 1631827710.505823, 1631827710.7581487, 1631827711.0075095, 1631827711.2558453, 1631827711.5081716, 1631827711.756507, 1631827712.006838, 1631827712.261158, 1631827712.5074995, 1631827712.756833, 1631827713.008161, 1631827713.2554998, 1631827713.5058308, 1631827713.7591538, 1631827714.0074894, 1631827714.256823, 1631827714.5071537, 1631827714.7564871, 1631827715.0088131, 1631827715.2561514, 1631827715.5094743, 1631827715.7588081, 1631827716.008141, 1631827716.257475, 1631827716.5098002, 1631827716.7571387, 1631827717.0104623, 1631827717.2647817, 1631827717.5091288, 1631827717.7594595, 1631827718.0107875, 1631827718.2581265, 1631827718.5393746, 1631827718.7607832, 1631827719.0151026, 1631827719.2704203, 1631827719.5127726, 1631827719.7730765, 1631827720.0084472, 1631827720.27374, 1631827720.5170872, 1631827720.7694132, 1631827721.0197437, 1631827721.2591038, 1631827721.5204055, 1631827721.7657495, 1631827722.0100963, 1631827722.2694032, 1631827722.516742, 1631827722.7670727, 1631827723.0233874, 1631827723.2697287, 1631827723.5190628, 1631827723.7614148, 1631827724.012743, 1631827724.2750416, 1631827724.5153992, 1631827724.7737083, 1631827725.0220447, 1631827725.2713778, 1631827725.5217087, 1631827725.7690482, 1631827726.012397, 1631827726.2786846, 1631827726.5160506, 1631827726.763389, 1631827727.0246909, 1631827727.270035, 1631827727.5233576, 1631827727.7706966, 1631827728.02003, 1631827728.2633798, 1631827728.5137103, 1631827728.764041, 1631827729.030329, 1631827729.2726812, 1631827729.5260043, 1631827729.7743404, 1631827730.014698, 1631827730.2660258, 1631827730.523338, 1631827730.7636957, 1631827731.0160208, 1631827731.2783196, 1631827731.520672, 1631827731.774992, 1631827732.0263202, 1631827732.273659, 1631827732.5259843, 1631827732.7663417, 1631827733.0276432, 1631827733.2759793, 1631827733.5263102, 1631827733.7666678, 1631827734.0319583, 1631827734.2713187, 1631827734.5166626, 1631827734.7809565, 1631827735.0173242, 1631827735.2676551, 1631827735.5279593, 1631827735.7673192, 1631827736.0336075, 1631827736.273965, 1631827736.5282853, 1631827736.7756238, 1631827737.0289466, 1631827737.2673097, 1631827737.5355933, 1631827737.772958, 1631827738.0183017, 1631827738.2815988, 1631827738.5229537, 1631827738.7762756, 1631827739.0186276, 1631827739.2779346, 1631827739.5222812, 1631827739.7785962, 1631827740.0209482, 1631827740.2832468, 1631827740.5265963, 1631827740.7699459, 1631827741.024267, 1631827741.2815783, 1631827741.52393, 1631827741.771269, 1631827742.0345657, 1631827742.2699358, 1631827742.5332327, 1631827742.7795734, 1631827743.0259156, 1631827743.2872164, 1631827743.5275738, 1631827743.7878785, 1631827744.0282357, 1631827744.2815583, 1631827744.531889, 1631827744.779228, 1631827745.0345454, 1631827745.2759, 1631827745.532215, 1631827745.7815483, 1631827746.0229027, 1631827746.2822099, 1631827746.527554, 1631827746.7858636, 1631827747.0242262, 1631827747.2865255, 1631827747.5308719, 1631827747.7861893, 1631827748.0275447, 1631827748.2858536, 1631827748.5302005, 1631827748.7835233, 1631827749.032857, 1631827749.2742114, 1631827749.5375078, 1631827749.7808568, 1631827750.0321853, 1631827750.2835133, 1631827750.5308518, 1631827750.78218, 1631827751.0305164, 1631827751.2758605, 1631827751.5361645, 1631827751.7835035, 1631827752.0328372, 1631827752.2881544, 1631827752.5334985, 1631827752.7868214, 1631827753.030172, 1631827753.276512, 1631827753.5378134, 1631827753.7811637, 1631827754.0384753, 1631827754.282822, 1631827754.5351477, 1631827754.7864754, 1631827755.0368063, 1631827755.2841454, 1631827755.5394626, 1631827755.7838094, 1631827756.0271587, 1631827756.29245, 1631827756.5328074, 1631827756.7781518, 1631827757.043442, 1631827757.278813, 1631827757.5411117, 1631827757.7854583, 1631827758.0317998, 1631827758.280136, 1631827758.5434322, 1631827758.7827928, 1631827759.039107, 1631827759.2854488, 1631827759.5297954, 1631827759.780126, 1631827760.042425, 1631827760.2797904, 1631827760.5420895, 1631827760.7874334, 1631827761.0317807, 1631827761.29408, 1631827761.5384257, 1631827761.779781, 1631827762.0430765, 1631827762.285429, 1631827762.5467303, 1631827762.7841163, 1631827763.0354445, 1631827763.292775, 1631827763.5371218, 1631827763.7904446, 1631827764.0407758, 1631827764.2821302, 1631827764.5464242, 1631827764.7817948, 1631827765.0351174, 1631827765.282456, 1631827765.5467505, 1631827765.7881045, 1631827766.037438, 1631827766.2957473, 1631827766.5390966, 1631827766.795411, 1631827767.0397584, 1631827767.2910864, 1631827767.54145, 1631827767.7828047, 1631827768.044106, 1631827768.2874749, 1631827768.5497732, 1631827768.7861414, 1631827769.0374691, 1631827769.2848082, 1631827769.5471072, 1631827769.7934487, 1631827770.0338063, 1631827770.300127, 1631827770.542479, 1631827770.7898376, 1631827771.035182, 1631827771.3004725, 1631827771.5358434, 1631827771.7981417, 1631827772.0424886, 1631827772.2958117, 1631827772.5441477, 1631827772.7984912, 1631827773.0388489, 1631827773.3061345, 1631827773.5415053, 1631827773.801809, 1631827774.043164, 1631827774.2895055, 1631827774.5478148, 1631827774.7861779, 1631827775.0484765, 1631827775.2878368, 1631827775.5531719, 1631827775.7955241, 1631827776.0378761, 1631827776.3031666, 1631827776.5475132, 1631827776.7968469, 1631827777.041194, 1631827777.2875352, 1631827777.5478394, 1631827777.797173, 1631827778.0445118, 1631827778.2978346, 1631827778.544176, 1631827778.7905176, 1631827779.0508213, 1631827779.297163, 1631827779.5544953, 1631827779.798842, 1631827780.041194, 1631827780.2905276, 1631827780.5558186, 1631827780.7951782, 1631827781.0425367, 1631827781.3018434, 1631827781.5521743, 1631827781.7995322, 1631827782.0418847, 1631827782.2912173, 1631827782.5545413, 1631827782.8018804, 1631827783.0432348, 1631827783.291589, 1631827783.5548851, 1631827783.7992501, 1631827784.054568, 1631827784.2919333, 1631827784.5432613, 1631827784.8115437, 1631827785.048421, 1631827785.3082404, 1631827785.549595, 1631827785.8049316, 1631827786.043295, 1631827786.2936254, 1631827786.5449865, 1631827786.8042932, 1631827787.042656, 1631827787.307947, 1631827787.5493014, 1631827787.7946675, 1631827788.0569663, 1631827788.303308, 1631827788.5436654, 1631827788.7950127, 1631827789.052325, 1631827789.3166401, 1631827789.5520115, 1631827789.794363, 1631827790.0456917, 1631827790.298038, 1631827790.5563471, 1631827790.7947102, 1631827791.0639904, 1631827791.302353, 1631827791.5466998, 1631827791.7970304, 1631827792.0613244, 1631827792.3006842, 1631827792.556999, 1631827792.8113194, 1631827793.055666, 1631827793.3070123, 1631827793.5583405, 1631827793.7967036, 1631827794.0629916, 1631827794.3073385, 1631827794.5586665, 1631827794.806035, 1631827795.0473893, 1631827795.299715, 1631827795.5590217, 1631827795.8033683, 1631827796.0517244, 1631827796.299063, 1631827796.5563967, 1631827796.797752, 1631827797.0530694, 1631827797.3193753, 1631827797.5557523, 1631827797.808077, 1631827798.050429, 1631827798.3007782, 1631827798.5640748, 1631827798.8054492, 1631827799.0587723, 1631827799.3110976, 1631827799.5554445, 1631827799.8097646, 1631827800.0491366, 1631827800.316433, 1631827800.549809, 1631827800.8170943, 1631827801.060444, 1631827801.301825, 1631827801.570111, 1631827801.8044827, 1631827802.0518386, 1631827802.315135, 1631827802.552501, 1631827802.815817, 1631827803.0611613, 1631827803.3144834, 1631827803.560825, 1631827803.8031769, 1631827804.062484, 1631827804.3108451, 1631827804.5681572, 1631827804.8015335, 1631827805.059843, 1631827805.3231392, 1631827805.5585303, 1631827805.8118534, 1631827806.0542054, 1631827806.3165042, 1631827806.56087, 1631827806.81918, 1631827807.062559, 1631827807.316879, 1631827807.5652149, 1631827807.803578, 1631827808.054906, 1631827808.3042583, 1631827808.5755332, 1631827808.8109038, 1631827809.0612347, 1631827809.326526, 1631827809.561896, 1631827809.8172412, 1631827810.0635822, 1631827810.3049371, 1631827810.5732205, 1631827810.8046017, 1631827811.0569553, 1631827811.307286, 1631827811.5735753, 1631827811.8089452, 1631827812.0702472, 1631827812.3175855, 1631827812.5659213, 1631827812.8192444, 1631827813.0685778, 1631827813.3089545, 1631827813.5662663, 1631827813.815619, 1631827814.0599663, 1631827814.3102965, 1631827814.5696223, 1631827814.815964, 1631827815.0673194, 1631827815.3086743, 1631827815.568978, 1631827815.818312, 1631827816.0666482, 1631827816.324987, 1631827816.5653448, 1631827816.8276434, 1631827817.070993, 1631827817.3153396, 1631827817.5746462, 1631827817.8150036, 1631827818.0593505, 1631827818.325639, 1631827818.5699856, 1631827818.8203163, 1631827819.0586793, 1631827819.3210044, 1631827819.5703378, 1631827819.8166795, 1631827820.069005, 1631827820.3113573, 1631827820.5696878, 1631827820.8110423, 1631827821.0623708, 1631827821.3276615, 1631827821.5710108, 1631827821.822339, 1631827822.0707092, 1631827822.3200426, 1631827822.5703738, 1631827822.8117476, 1631827823.0630758, 1631827823.3154197, 1631827823.5767214, 1631827823.8220654, 1631827824.061426, 1631827824.3157456, 1631827824.581076, 1631827824.8224313, 1631827825.0837324, 1631827825.3191035, 1631827825.5794072, 1631827825.8197846, 1631827826.063134, 1631827826.3264303, 1631827826.566788, 1631827826.8141265, 1631827827.0654545, 1631827827.3277833, 1631827827.5741246, 1631827827.8144822, 1631827828.0837622, 1631827828.320149, 1631827828.5794568, 1631827828.8138292, 1631827829.076128, 1631827829.3254614, 1631827829.574795, 1631827829.8151524, 1631827830.0665002]
assets/zephir-zm9624/worldlines.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c4ac04fb461fd3336d6decf81dd4009f7ef1f188ebc6c0193a797b1a6eaff70
3
+ size 5449
examples/pilot.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run the actual ASCENT pilot; accept either a local assembly or pinned Hub revision."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+
8
+ from cell_tracking.data.wormtrack_verify import BenchmarkClient
9
+ from cell_tracking.evaluation.wormtrack_verify import (
10
+ association_metrics,
11
+ corrupt_tracks,
12
+ reference_residual_scores,
13
+ verifier_metrics,
14
+ )
15
+
16
+
17
+ def run(client):
18
+ clean = client.load_tracks("ascent-opterra", label_source="human_corrected")
19
+ cloud = client.load_reference_cloud("ascent-opterra")
20
+ corrupt = corrupt_tracks(
21
+ clean, kind="swap_recovery", seed=20261007, start_frame=300, stop_frame=700
22
+ )
23
+ scores = reference_residual_scores(corrupt, cloud)
24
+ metrics = verifier_metrics(scores, corrupt.is_error, threshold=5.0)
25
+ metrics.pop("risk_coverage")
26
+ volume = client.load_volume("ascent-opterra", frame=0)
27
+ print(
28
+ json.dumps(
29
+ {
30
+ "volume_czyx": list(volume.shape),
31
+ "association": association_metrics(clean, corrupt),
32
+ "verifier": metrics,
33
+ },
34
+ indent=2,
35
+ )
36
+ )
37
+
38
+
39
+ if __name__ == "__main__":
40
+ parser = argparse.ArgumentParser()
41
+ parser.add_argument("--root")
42
+ parser.add_argument("--revision")
43
+ args = parser.parse_args()
44
+ run(BenchmarkClient(root=args.root, revision=args.revision))
examples/stream.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Inspect the published annotation stream without downloading microscopy volumes."""
2
+
3
+ from datasets import load_dataset
4
+
5
+ stream = load_dataset(
6
+ "pytc/trackingBench",
7
+ name="tracks",
8
+ revision="v0.1.0-alpha.1",
9
+ split="development",
10
+ streaming=True,
11
+ )
12
+ print(next(iter(stream)))
pyproject.toml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+ [project]
5
+ name = "wormtrack-verify"
6
+ version = "0.1.0a1"
7
+ requires-python = ">=3.12"
8
+ description = "Selective client and evaluation helpers for WormTrack-Verify"
9
+ readme = "README.md"
10
+ license = {text = "MIT (helper code only)"}
11
+ dependencies = ["huggingface_hub>=1.0", "pyarrow>=20", "pandas>=2.2", "h5py>=3.12", "numpy>=2.2", "scipy>=1.15", "scikit-learn>=1.6", "requests>=2.32", "PyYAML>=6"]
12
+ [tool.hatch.build.targets.wheel]
13
+ packages = ["src/cell_tracking"]
requirements.lock.txt ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PyYAML==6.0.3
2
+ PyYAML==6.0.3
3
+ Pygments==2.21.0
4
+ Pygments==2.21.0
5
+ aiohappyeyeballs==2.7.1
6
+ aiohappyeyeballs==2.7.1
7
+ aiohttp==3.14.4
8
+ aiohttp==3.14.4
9
+ aiosignal==1.4.0
10
+ aiosignal==1.4.0
11
+ anyio==4.15.1
12
+ anyio==4.15.1
13
+ attrs==26.1.0
14
+ attrs==26.1.0
15
+ certifi==2026.7.22
16
+ certifi==2026.7.22
17
+ charset-normalizer==3.5.2
18
+ charset-normalizer==3.5.2
19
+ click==8.5.0
20
+ click==8.5.0
21
+ cloudpickle==3.1.2
22
+ cloudpickle==3.1.2
23
+ datasets==5.1.0
24
+ datasets==5.1.0
25
+ dill==0.4.1
26
+ dill==0.4.1
27
+ donfig==0.8.1.post1
28
+ donfig==0.8.1.post1
29
+ filelock==4.0.12
30
+ filelock==4.0.12
31
+ frozenlist==1.8.0
32
+ frozenlist==1.8.0
33
+ fsspec==2026.7.0
34
+ fsspec==2026.7.0
35
+ google-crc32c==1.9.0
36
+ google-crc32c==1.9.0
37
+ h11==0.16.0
38
+ h11==0.16.0
39
+ h5py==3.16.0
40
+ h5py==3.16.0
41
+ hf-xet==1.7.0
42
+ hf-xet==1.7.0
43
+ httpcore2==2.13.1
44
+ httpcore2==2.13.1
45
+ httpx2==2.13.1
46
+ httpx2==2.13.1
47
+ huggingface_hub==2.1.1
48
+ huggingface_hub==2.1.1
49
+ idna==3.20
50
+ idna==3.20
51
+ iniconfig==2.3.1
52
+ iniconfig==2.3.1
53
+ joblib==1.6.0
54
+ joblib==1.6.0
55
+ jsonschema-specifications==2025.9.1
56
+ jsonschema-specifications==2025.9.1
57
+ jsonschema==4.26.0
58
+ jsonschema==4.26.0
59
+ msgspec==0.22.0
60
+ msgspec==0.22.0
61
+ multidict==6.9.1
62
+ multidict==6.9.1
63
+ multiprocess==0.70.19
64
+ multiprocess==0.70.19
65
+ narwhals==2.26.0
66
+ narwhals==2.26.0
67
+ numcodecs==0.17.0
68
+ numcodecs==0.17.0
69
+ numpy==2.5.3
70
+ numpy==2.5.3
71
+ packaging==26.3
72
+ packaging==26.3
73
+ pandas==3.0.6
74
+ pandas==3.0.6
75
+ pluggy==1.6.0
76
+ pluggy==1.6.0
77
+ propcache==0.5.4
78
+ propcache==0.5.4
79
+ pyarrow==25.0.1
80
+ pyarrow==25.0.1
81
+ pytest==9.1.1
82
+ pytest==9.1.1
83
+ python-dateutil==2.9.0.post0
84
+ python-dateutil==2.9.0.post0
85
+ referencing==0.37.0
86
+ referencing==0.37.0
87
+ requests==2.34.2
88
+ requests==2.34.2
89
+ rpds-py==2026.9.1
90
+ rpds-py==2026.9.1
91
+ ruff==0.16.10
92
+ ruff==0.16.10
93
+ scikit-learn==1.9.1
94
+ scikit-learn==1.9.1
95
+ scipy==1.18.1
96
+ scipy==1.18.1
97
+ six==1.17.0
98
+ six==1.17.0
99
+ threadpoolctl==3.7.0
100
+ threadpoolctl==3.7.0
101
+ tifffile==2026.9.20
102
+ tifffile==2026.9.20
103
+ tqdm==4.70.1
104
+ tqdm==4.70.1
105
+ truststore==0.10.4
106
+ truststore==0.10.4
107
+ typing_extensions==4.16.0
108
+ typing_extensions==4.16.0
109
+ urllib3==2.8.0
110
+ urllib3==2.8.0
111
+ xxhash==4.0.1
112
+ xxhash==4.0.1
113
+ yarl==1.25.1
114
+ yarl==1.25.1
115
+ zarr==3.4.0
116
+ zarr==3.4.0
src/cell_tracking/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """WormTrack-Verify benchmark helpers."""
src/cell_tracking/data/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """WormTrack-Verify benchmark helpers."""
src/cell_tracking/data/wormtrack_verify/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """Selective access and assembly tools for the WormTrack-Verify pilot."""
2
+
3
+ from .client import BenchmarkClient, MissingComponentError
4
+
5
+ __all__ = ["BenchmarkClient", "MissingComponentError"]
src/cell_tracking/data/wormtrack_verify/adapters.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Native ASCENT and ZephIR table adapters with conservative annotation provenance."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ XYZ = ["x_voxel", "y_voxel", "z_voxel"]
9
+ TRUSTED = {"human_corrected", "manually_verified", "verified_checkpoint"}
10
+
11
+
12
+ def _physical(df, spacing_xyz):
13
+ for axis, scale in zip("xyz", spacing_xyz or [None] * 3, strict=True):
14
+ df[f"{axis}_um"] = df[f"{axis}_voxel"] * scale if scale is not None else np.nan
15
+ df["coordinate_system"] = "source_microscope"
16
+ df["annotation_confidence"] = np.nan
17
+ df["validity"] = True
18
+ return df
19
+
20
+
21
+ def ascent_tracks(path, recording_id, *, predicted=False):
22
+ """Read native ZYX CSV; physical spacing is from Zenodo 17561700 metadata."""
23
+ df = pd.read_csv(path).rename(
24
+ columns={
25
+ "TrackID": "track_id",
26
+ "ObjectID": "detection_id",
27
+ "t": "frame_index",
28
+ "x": "x_voxel",
29
+ "y": "y_voxel",
30
+ "z": "z_voxel",
31
+ }
32
+ )
33
+ required = {"track_id", "detection_id", "frame_index", *XYZ}
34
+ if not required.issubset(df.columns):
35
+ raise ValueError(f"Missing ASCENT fields: {sorted(required - set(df.columns))}")
36
+ df["recording_id"] = recording_id
37
+ df["annotation_type"] = "algorithm_prediction" if predicted else "human_corrected"
38
+ df["source_provenance"] = "ASCENT-PRED" if predicted else "ASCENT-GT-proofread-ZephIR"
39
+ df["label_set"] = "prediction" if predicted else "reference"
40
+ df["track_id"] = df.track_id.astype(str)
41
+ df["detection_id"] = df.detection_id.map(lambda i: f"{'pred' if predicted else 'gt'}:{i}")
42
+ return _physical(df, [0.243, 0.243, 1.5])
43
+
44
+
45
+ def zephir_tracks(path, metadata, recording_id):
46
+ """Retain scorer codes; only documented ZEIR results are classified as predictions.
47
+
48
+ Other codes remain unknown until their human/algorithm provenance is verified.
49
+ Normalized coordinates map to voxel index x*size-0.5 using the native viewer
50
+ convention. No voxel spacing is inferred from the neuron arrangement.
51
+ """
52
+ import h5py
53
+
54
+ with h5py.File(path, "r") as h:
55
+ df = pd.DataFrame({k: h[k][()] for k in h})
56
+ df = df.rename(
57
+ columns={
58
+ "t_idx": "frame_index",
59
+ "worldline_id": "track_id",
60
+ "id": "detection_id",
61
+ "provenance": "source_provenance",
62
+ }
63
+ )
64
+ df["source_provenance"] = df.source_provenance.map(lambda s: s.decode("utf-8"))
65
+ for axis in "xyz":
66
+ df[f"{axis}_normalized"] = df[axis]
67
+ df[f"{axis}_voxel"] = df[axis] * metadata[f"shape_{axis}"] - 0.5
68
+ df = df.drop(columns=axis)
69
+ df["annotation_type"] = np.where(
70
+ df.source_provenance == "ZEIR", "algorithm_prediction", "unknown"
71
+ )
72
+ df["recording_id"] = recording_id
73
+ df["label_set"] = "source_mixed"
74
+ df["track_id"] = df.track_id.astype(str)
75
+ df["detection_id"] = df.detection_id.map(lambda i: f"source:{i}")
76
+ df = _physical(df, None)
77
+ normalized = df[[f"{axis}_normalized" for axis in "xyz"]].to_numpy(dtype=float)
78
+ df["validity"] = (
79
+ np.isfinite(normalized).all(axis=1)
80
+ & (normalized >= 0).all(axis=1)
81
+ & (normalized <= 1).all(axis=1)
82
+ )
83
+ return df
84
+
85
+
86
+ def validate_tracks(df, *, shape_xyz=None):
87
+ """Reject ambiguous assignments and nonfinite observed points; never clamp or interpolate."""
88
+ required = {
89
+ "recording_id",
90
+ "frame_index",
91
+ "track_id",
92
+ "detection_id",
93
+ *XYZ,
94
+ "annotation_type",
95
+ "label_set",
96
+ "validity",
97
+ }
98
+ if not required.issubset(df.columns):
99
+ raise ValueError(f"Missing fields: {sorted(required - set(df.columns))}")
100
+ if df.empty:
101
+ raise ValueError("Empty tracking table")
102
+ valid = df.loc[df.validity]
103
+ scope = ["recording_id", "label_set", "frame_index"]
104
+ if valid.duplicated(scope + ["track_id"]).any():
105
+ raise ValueError("Duplicate track assignments")
106
+ if valid.duplicated(scope + ["detection_id"]).any():
107
+ raise ValueError("Duplicate detection assignments")
108
+ if valid.track_id.isna().any() or valid.detection_id.isna().any():
109
+ raise ValueError("Missing identity on a valid observation")
110
+ if not np.isfinite(valid[XYZ].to_numpy(dtype=float)).all():
111
+ raise ValueError("Nonfinite observed coordinates")
112
+ if (valid.frame_index < 0).any() or (valid.frame_index % 1 != 0).any():
113
+ raise ValueError("Invalid frame index")
114
+ # Centers use pixel boundaries [-0.5, size-0.5], including ZephIR normalized endpoints.
115
+ if shape_xyz is not None:
116
+ points = valid[XYZ].to_numpy(dtype=float)
117
+ if ((points < -0.5) | (points > np.asarray(shape_xyz) - 0.5)).any():
118
+ raise ValueError("Spatial coordinates outside source bounds")
119
+ return {
120
+ "observations": len(valid),
121
+ "frames": int(valid.frame_index.nunique()),
122
+ "tracks": int(valid.track_id.nunique()),
123
+ "annotation_types": {
124
+ str(k): int(v) for k, v in valid.annotation_type.value_counts().items()
125
+ },
126
+ }
src/cell_tracking/data/wormtrack_verify/assembly.py ADDED
@@ -0,0 +1,678 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build a development pilot from audited, checksum-pinned upstream assets.
2
+
3
+ Usage: python -m cell_tracking.data.wormtrack_verify.assembly WORKSPACE OUTPUT
4
+ Acquisition is deliberately separate: this command never downloads large files.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import json
11
+ import shutil
12
+ import sys
13
+ from datetime import datetime
14
+ from pathlib import Path
15
+ from zoneinfo import ZoneInfo
16
+
17
+ import h5py
18
+ import numpy as np
19
+ import pandas as pd
20
+
21
+ from cell_tracking.data.wormtrack_verify.adapters import (
22
+ XYZ,
23
+ ascent_tracks,
24
+ validate_tracks,
25
+ zephir_tracks,
26
+ )
27
+ from cell_tracking.data.wormtrack_verify.inventory import DANDI_COHORTS, WORMND_COMMIT
28
+ from cell_tracking.evaluation.wormtrack_verify import (
29
+ association_metrics,
30
+ corrupt_tracks,
31
+ oracle_association_baseline,
32
+ reference_residual_scores,
33
+ verifier_metrics,
34
+ )
35
+
36
+ VERSION = "0.1.0-alpha.1"
37
+ SEED = 20261007
38
+
39
+
40
+ def digest(path, algorithm="sha256"):
41
+ h = hashlib.new(algorithm)
42
+ with Path(path).open("rb") as stream:
43
+ for chunk in iter(lambda: stream.read(8 * 1024**2), b""):
44
+ h.update(chunk)
45
+ return h.hexdigest()
46
+
47
+
48
+ def dump(path, data):
49
+ path.parent.mkdir(parents=True, exist_ok=True)
50
+ path.write_text(json.dumps(data, indent=2, allow_nan=False) + "\n")
51
+
52
+
53
+ def table(root, path, df):
54
+ target = root / path
55
+ target.parent.mkdir(parents=True, exist_ok=True)
56
+ df.to_parquet(target, index=False)
57
+ return path
58
+
59
+
60
+ def harmonize_tables(root):
61
+ """Align per-recording Parquet schemas without dropping source-specific fields."""
62
+ import pyarrow as pa
63
+ import pyarrow.parquet as pq
64
+
65
+ for folder in Path(root).glob("data/*"):
66
+ files = sorted(folder.glob("*.parquet"))
67
+ if not files:
68
+ continue
69
+ schema = pa.unify_schemas(
70
+ [pq.read_schema(path) for path in files], promote_options="permissive"
71
+ ).remove_metadata()
72
+ for path in files:
73
+ original = pq.read_table(path)
74
+ arrays = [
75
+ original[field.name].cast(field.type)
76
+ if field.name in original.column_names
77
+ else pa.nulls(original.num_rows, type=field.type)
78
+ for field in schema
79
+ ]
80
+ pq.write_table(pa.Table.from_arrays(arrays, schema=schema), path)
81
+
82
+
83
+ def build(workspace, destination):
84
+ workspace, root = Path(workspace), Path(destination)
85
+ root.mkdir(parents=True, exist_ok=True)
86
+ audit, raw = workspace / "audit", workspace / "raw"
87
+ now = datetime.now(ZoneInfo("America/New_York")).isoformat()
88
+ sources, recordings, upstream, overlaps = [], [], [], []
89
+ original = pd.read_csv(audit / "wormid-tracking-split.csv")
90
+ split_lookup = original.drop_duplicates("filename").set_index("filename")
91
+ provenance_path = audit / "dandi-asset-provenance.json"
92
+ provenance = json.loads(provenance_path.read_text()) if provenance_path.exists() else {}
93
+ subject_groups = {}
94
+ for identifier, cohort in DANDI_COHORTS.items():
95
+ release = json.loads((audit / f"dandi-{identifier}-pinned.json").read_text())
96
+ assets = json.loads((audit / f"dandi-{identifier}-assets.json").read_text())
97
+ sources.append(
98
+ {
99
+ "source_id": f"dandi-{identifier}",
100
+ "name": cohort,
101
+ "priority": "P0" if identifier not in {"001623", "000981"} else "P1",
102
+ "version": assets["version"],
103
+ "url": f"https://dandiarchive.org/dandiset/{identifier}/{assets['version']}",
104
+ "license": release.get("license"),
105
+ "license_status": "verified_release_metadata",
106
+ "asset_count": len(assets["assets"]),
107
+ "bytes": sum(a["size"] for a in assets["assets"]),
108
+ "assembly_status": "inventoried_assets_not_bulk_ingested",
109
+ }
110
+ )
111
+ for asset in assets["assets"]:
112
+ subject = asset["path"].split("/")[0]
113
+ rid = f"dandi-{identifier}-{subject}"
114
+ animal = f"dandi:{identifier}:{subject}"
115
+ subject_groups.setdefault(subject, []).append(rid)
116
+ full_name = f"{identifier}/{asset['path']}"
117
+ split = split_lookup.loc[full_name] if full_name in split_lookup.index else None
118
+ tracking = bool(split.use_for_calcium_task == 1) if split is not None else False
119
+ # SF is explicitly excluded from the published trusted tracking subset.
120
+ tracking = tracking and cohort != "SF"
121
+ record = {
122
+ "recording_id": rid,
123
+ "source_dataset": f"dandi-{identifier}",
124
+ "source_cohort": cohort,
125
+ "source_version": assets["version"],
126
+ "source_asset": asset["asset_id"],
127
+ "source_path": asset["path"],
128
+ "source_checksum": json.dumps(provenance.get(asset["asset_id"], {}).get("digest")),
129
+ "source_size_bytes": asset["size"],
130
+ "lab_id": None,
131
+ "animal_id": animal,
132
+ "session_id": asset["path"].split("/")[-1].removesuffix(".nwb"),
133
+ "species": None,
134
+ "sex": None,
135
+ "stage": None,
136
+ "strain": None,
137
+ "fov_region": "unknown",
138
+ "acquisition_setup": "unknown",
139
+ "shape_tczyx": None,
140
+ "voxel_size_um": None,
141
+ "timestamps_status": "not_inspected",
142
+ "channels": None,
143
+ "tracking_gt_level": "not_inspected",
144
+ "posture_gt_level": "not_inspected",
145
+ "source_overlap_group": subject,
146
+ "license": ";".join(release.get("license", [])),
147
+ "qc_status": "inventory_only",
148
+ "hosted_tracks": False,
149
+ "hosted_volume": False,
150
+ "wormid_tracking_subset": tracking,
151
+ "wormid_fold": str(split.dataset_split) if split is not None else None,
152
+ }
153
+ recordings.append(record)
154
+ upstream.append(
155
+ {
156
+ "recording_id": rid,
157
+ "asset_id": asset["asset_id"],
158
+ "source_version": assets["version"],
159
+ "path": asset["path"],
160
+ "bytes": asset["size"],
161
+ "digests": provenance.get(asset["asset_id"], {}).get("digest"),
162
+ "location": "external",
163
+ "url": f"https://api.dandiarchive.org/api/assets/{asset['asset_id']}/download/",
164
+ }
165
+ )
166
+ for subject, ids in subject_groups.items():
167
+ if len(ids) > 1:
168
+ overlaps.append(
169
+ {
170
+ "group_id": subject,
171
+ "recording_ids": ids,
172
+ "status": "potential_same_animal_or_acquisition",
173
+ "evidence": "shared upstream subject identifier",
174
+ "split_policy": "keep together; prohibit separate test assignments until audited",
175
+ }
176
+ )
177
+ components, qc, counts = {}, {}, {}
178
+
179
+ def recording(rid):
180
+ return next(r for r in recordings if r["recording_id"] == rid)
181
+
182
+ def register_tracks(rid, df, shape_xyz):
183
+ qc[rid] = validate_tracks(df, shape_xyz=shape_xyz)
184
+ qc[rid]["invalid_observations_preserved"] = int((~df.validity).sum())
185
+ counts[rid] = qc[rid]
186
+ entry = components.setdefault(rid, {})
187
+ entry["tracks"] = table(root, f"data/tracks/{rid}.parquet", df)
188
+ detections = df.drop(columns=["track_id"]).copy()
189
+ entry["detections"] = table(root, f"data/detections/{rid}.parquet", detections)
190
+ recording(rid).update(
191
+ hosted_tracks=True,
192
+ qc_status="table_validated",
193
+ tracking_gt_level="trusted_human_corrected"
194
+ if set(df.annotation_type) == {"human_corrected"}
195
+ else "unknown_or_mixed_provenance",
196
+ )
197
+
198
+ # Small real recordings and trusted ASCENT annotations.
199
+ for source, identifier in [
200
+ ("ASCENT", "17561700"),
201
+ ("ZephIR", "10818810"),
202
+ ("Targettrack", "10008744"),
203
+ ]:
204
+ meta = json.loads((audit / f"zenodo-{identifier}.json").read_text())
205
+ sources.append(
206
+ {
207
+ "source_id": source.lower(),
208
+ "name": source,
209
+ "priority": "P0" if source == "ZephIR" else "P1",
210
+ "version": f"10.5281/zenodo.{identifier}",
211
+ "url": f"https://zenodo.org/records/{identifier}",
212
+ "license": meta["metadata"].get("license", {}).get("id"),
213
+ "license_status": "verified_record_metadata",
214
+ "asset_count": len(meta["files"]),
215
+ "bytes": sum(a["size"] for a in meta["files"]),
216
+ "assembly_status": "pilot_assets_and_tables",
217
+ }
218
+ )
219
+ for asset in meta["files"]:
220
+ upstream.append(
221
+ {
222
+ "recording_id": None,
223
+ "source_dataset": source.lower(),
224
+ "path": asset["key"],
225
+ "bytes": asset["size"],
226
+ "digests": {"md5": asset["checksum"].split(":", 1)[-1]},
227
+ "location": "external",
228
+ "url": asset["links"]["self"],
229
+ }
230
+ )
231
+ local = raw / asset["key"]
232
+ if local.exists() and digest(local, "md5") != asset["checksum"].split(":", 1)[-1]:
233
+ raise ValueError(f"Upstream checksum mismatch: {local.name}")
234
+ template = {
235
+ "source_checksum": None,
236
+ "source_size_bytes": None,
237
+ "species": "Caenorhabditis elegans",
238
+ "sex": None,
239
+ "stage": None,
240
+ "strain": None,
241
+ "fov_region": "unknown",
242
+ "acquisition_setup": "unknown",
243
+ "shape_tczyx": None,
244
+ "voxel_size_um": None,
245
+ "timestamps_status": "unknown",
246
+ "channels": None,
247
+ "tracking_gt_level": "unknown",
248
+ "posture_gt_level": "unavailable",
249
+ "license": "CC-BY-4.0",
250
+ "qc_status": "inventory_only",
251
+ "hosted_tracks": False,
252
+ "hosted_volume": False,
253
+ "wormid_tracking_subset": False,
254
+ "wormid_fold": None,
255
+ }
256
+
257
+ def new_record(rid, source, version, asset, **kwargs):
258
+ record = dict(
259
+ template,
260
+ recording_id=rid,
261
+ source_dataset=source,
262
+ source_cohort=source,
263
+ source_version=version,
264
+ source_asset=asset,
265
+ source_path=asset,
266
+ lab_id=None,
267
+ animal_id=rid,
268
+ session_id=rid,
269
+ source_overlap_group=rid,
270
+ )
271
+ record.update(kwargs)
272
+ recordings.append(record)
273
+
274
+ rid = "ascent-opterra"
275
+ new_record(
276
+ rid,
277
+ "ascent",
278
+ "10.5281/zenodo.17561700",
279
+ "InHouse_Opterra_tracks_GT.csv",
280
+ fov_region="head",
281
+ acquisition_setup="device_restricted",
282
+ strain="ZM9624",
283
+ shape_tczyx=json.dumps([1100, 2, 9, 512, 512]),
284
+ voxel_size_um=json.dumps([0.243, 0.243, 1.5]),
285
+ timestamps_status="nominal_3.3Hz_not_measured_timestamps",
286
+ channels=json.dumps(
287
+ [
288
+ {"index": 0, "name": "mNeptune", "role": "structural"},
289
+ {"index": 1, "name": "GCaMP6", "role": "calcium"},
290
+ ]
291
+ ),
292
+ )
293
+ clean = ascent_tracks(raw / "InHouse_Opterra_tracks_GT.csv", rid)
294
+ register_tracks(rid, clean, [512, 512, 9])
295
+ pred = ascent_tracks(raw / "InHouse_Opterra_tracks_PRED.csv", rid, predicted=True)
296
+ qc["ascent-source-predictions"] = validate_tracks(pred, shape_xyz=[512, 512, 9])
297
+ table(root, "evaluation/source_predictions/ascent.parquet", pred)
298
+ # Source-predicted objects differ from oracle detections: do not score these as oracle association.
299
+ ref = clean.loc[clean.frame_index == clean.frame_index.min()].copy()
300
+ ref["reference_origin"] = "same_animal_human_corrected_reference_frame"
301
+ components[rid]["anatomy"] = table(root, f"data/anatomy/{rid}.parquet", ref)
302
+ scenarios, verification, results = [], [], {}
303
+ clean_control = clean.copy()
304
+ clean_control["scenario_id"] = "clean"
305
+ clean_control["is_error"] = False
306
+ clean_control["reference_track_id"] = clean_control.track_id
307
+ clean_control["corruption_type"] = "clean"
308
+ clean_control["seed"] = SEED
309
+ scenarios.append(clean_control)
310
+ # Choose a nearby pair using only the development reference frame.
311
+ positions = ref[["x_um", "y_um", "z_um"]].to_numpy()
312
+ distance = np.linalg.norm(positions[:, None] - positions[None], axis=2)
313
+ np.fill_diagonal(distance, np.inf)
314
+ i, j = np.unravel_index(distance.argmin(), distance.shape)
315
+ pair = [ref.track_id.iloc[i], ref.track_id.iloc[j]]
316
+ for kind in [
317
+ "single_frame_swap",
318
+ "persistent_swap",
319
+ "swap_recovery",
320
+ "nearby_swap",
321
+ "fragmentation",
322
+ "dropout",
323
+ ]:
324
+ stop = 700 if kind in {"swap_recovery", "nearby_swap"} else None
325
+ corrupted = corrupt_tracks(
326
+ clean,
327
+ kind=kind,
328
+ seed=SEED,
329
+ start_frame=300,
330
+ stop_frame=stop,
331
+ pair=pair if kind == "nearby_swap" else None,
332
+ )
333
+ scenarios.append(corrupted)
334
+ for df in scenarios:
335
+ scores = reference_residual_scores(df, ref)
336
+ report = verifier_metrics(scores, df.is_error, threshold=5.0)
337
+ # Keep exact risk/coverage breakpoints in a separate tabular artifact.
338
+ curve = report.pop("risk_coverage")
339
+ table(
340
+ root, f"evaluation/risk_coverage/{df.scenario_id.iloc[0]}.parquet", pd.DataFrame(curve)
341
+ )
342
+ scenario = df.scenario_id.iloc[0]
343
+ report["association"] = association_metrics(clean, df)
344
+ results[scenario] = report
345
+ verification.append(
346
+ pd.DataFrame(
347
+ {
348
+ "recording_id": rid,
349
+ "scenario_id": scenario,
350
+ "frame_index": df.frame_index,
351
+ "detection_id": df.detection_id,
352
+ "reference_track_id": df.reference_track_id,
353
+ "proposed_track_id": df.track_id,
354
+ "is_error": df.is_error,
355
+ "score_um": scores,
356
+ "verifier": "fixed_reference_distance",
357
+ "threshold_um": 5.0,
358
+ "partition": "development",
359
+ }
360
+ )
361
+ )
362
+ components[rid]["perturbations"] = table(
363
+ root, f"data/perturbations/{rid}.parquet", pd.concat(scenarios, ignore_index=True)
364
+ )
365
+ table(root, f"data/verification/{rid}.parquet", pd.concat(verification, ignore_index=True))
366
+ for method in ["nearest_neighbor", "hungarian"]:
367
+ prediction = oracle_association_baseline(clean.drop(columns="track_id"), method=method)
368
+ table(root, f"evaluation/baseline_predictions/{method}.parquet", prediction)
369
+ results[method] = association_metrics(clean, prediction)
370
+ dump(root / "evaluation/pilot_results.json", results)
371
+
372
+ for name, rid, source in [
373
+ ("ZM9624_Ex(myo-20_mCherry)", "zephir-zm9624", "zephir"),
374
+ ("nguyen2017_AL_w1", "nerve-al-w1-via-zephir", "nerve"),
375
+ ]:
376
+ folder = raw / "zephir/zephir" / name
377
+ meta = json.loads((folder / "metadata.json").read_text())
378
+ new_record(
379
+ rid,
380
+ source,
381
+ "10.5281/zenodo.10818810",
382
+ f"zephir/{name}/annotations.h5",
383
+ acquisition_setup="freely_moving",
384
+ shape_tczyx=json.dumps([meta[f"shape_{a}"] for a in "tczyx"]),
385
+ source_overlap_group="nerve-al-w1" if source == "nerve" else rid,
386
+ timestamps_status="source_times_hosted" if source == "zephir" else "unknown",
387
+ )
388
+ register_tracks(
389
+ rid,
390
+ zephir_tracks(folder / "annotations.h5", meta, rid),
391
+ [meta[f"shape_{a}"] for a in "xyz"],
392
+ )
393
+ dest = root / "assets" / rid
394
+ dest.mkdir(parents=True, exist_ok=True)
395
+ for filename in ["annotations.h5", "worldlines.h5", "metadata.json"]:
396
+ shutil.copy2(folder / filename, dest / filename)
397
+ if (audit / "zephir-image-times.json").exists():
398
+ shutil.copy2(
399
+ audit / "zephir-image-times.json", root / "assets/zephir-zm9624/timestamps_s.json"
400
+ )
401
+
402
+ rid = "targettrack-epfl10"
403
+ new_record(
404
+ rid,
405
+ "targettrack",
406
+ "10.5281/zenodo.10008744",
407
+ "Targettrack/epfl10_CZANet_Final.h5",
408
+ shape_tczyx=json.dumps([761, 1, 32, 128, 192]),
409
+ acquisition_setup="unknown",
410
+ tracking_gt_level="mask_provenance_unresolved",
411
+ )
412
+ points, transforms = [], []
413
+ with h5py.File(raw / "Targettrack/epfl10_CZANet_Final.h5") as h:
414
+ for t in range(int(h.attrs["T"])):
415
+ g = h[str(t)]
416
+ transforms.append(
417
+ {
418
+ "recording_id": rid,
419
+ "frame_index": t,
420
+ "original_frame_index": int(g["original_fr"][()]),
421
+ "source_transform": g["transfo_matrix"][()].reshape(-1).tolist(),
422
+ "direction": "unknown",
423
+ "units": "unknown",
424
+ }
425
+ )
426
+ if "mask" not in g:
427
+ continue
428
+ mask = g["mask"][()]
429
+ for identity in np.unique(mask):
430
+ if identity == 0:
431
+ continue
432
+ xyz = np.argwhere(mask == identity).mean(axis=0)
433
+ points.append(
434
+ {
435
+ "recording_id": rid,
436
+ "frame_index": t,
437
+ "track_id": str(identity),
438
+ "detection_id": f"{t}:{identity}",
439
+ **dict(zip(XYZ, xyz.tolist(), strict=True)),
440
+ "x_um": np.nan,
441
+ "y_um": np.nan,
442
+ "z_um": np.nan,
443
+ "annotation_type": "unknown",
444
+ "annotation_confidence": np.nan,
445
+ "label_set": "source_mask",
446
+ "source_provenance": "centroid_of_native_mask; manual_or_propagated_unresolved",
447
+ "coordinate_system": "source_processed_CXYZ",
448
+ "validity": True,
449
+ }
450
+ )
451
+ register_tracks(rid, pd.DataFrame(points), [192, 128, 32])
452
+ table(root, "metadata/targettrack_transforms.parquet", pd.DataFrame(transforms))
453
+
454
+ # Same-animal NeuroPAL cloud from a directly inspected CC-BY NWB.
455
+ asset = json.loads((audit / "dandi-000715-assets.json").read_text())["assets"][0]
456
+ rid = "dandi-000715-" + asset["path"].split("/")[0]
457
+ with h5py.File(raw / "neuropal-reference.nwb") as h:
458
+ group = h["processing/NeuroPAL/NeuroPALSegmentation/NeuroPALNeurons"]
459
+ voxels, ids = group["voxel_mask"][()], group["id"][()]
460
+ spacing = h["general/optophysiology/NeuroPALImVol/grid_spacing"]
461
+ if spacing.attrs["unit"] != "micrometers":
462
+ raise ValueError("Unsupported physical calibration")
463
+ cloud = pd.DataFrame(
464
+ {
465
+ "recording_id": rid,
466
+ "track_id": ids.astype(str),
467
+ **{f"{a}_voxel": voxels[a].astype(float) for a in "xyz"},
468
+ **{f"{a}_um": voxels[a] * spacing[i] for i, a in enumerate("xyz")},
469
+ "reference_origin": "same_animal_structural_volume",
470
+ "annotation_type": "source_annotation_uncertainty_unknown",
471
+ "coordinate_system": "source_microscope",
472
+ "uncertainty_um": np.nan,
473
+ }
474
+ )
475
+ components.setdefault(rid, {})["anatomy"] = table(
476
+ root, f"data/anatomy/{rid}.parquet", cloud
477
+ )
478
+ recording(rid).update(
479
+ qc_status="reference_cloud_validated", voxel_size_um=json.dumps(spacing[()].tolist())
480
+ )
481
+ # Preserve the original small structural NWB; explicit component download only.
482
+ (root / "assets" / rid).mkdir(parents=True, exist_ok=True)
483
+ shutil.copy2(raw / "neuropal-reference.nwb", root / "assets" / rid / "reference.nwb")
484
+
485
+ if (raw / "wormid-ey-pilot.parquet").exists():
486
+ meta = json.loads((audit / "wormid-ey-pilot.json").read_text())
487
+ rid = "dandi-000541-" + meta["asset"]["path"].split("/")[0]
488
+ df = pd.read_parquet(raw / "wormid-ey-pilot.parquet")
489
+ for i, a in enumerate("xyz"):
490
+ df[f"{a}_um"] = df[f"{a}_voxel"] * meta["spacing_xyz"][i]
491
+ df["recording_id"], df["annotation_type"], df["label_set"] = (
492
+ rid,
493
+ "unknown",
494
+ "source_segmentation",
495
+ )
496
+ df["annotation_confidence"] = np.nan
497
+ df["source_provenance"] = "native_NWB_plane_segmentation_ID; temporal_identity_QC_pending"
498
+ df["coordinate_system"], df["validity"] = "source_microscope", True
499
+ register_tracks(rid, df, list(reversed(meta["shape_tczyx"][2:])))
500
+ recording(rid).update(
501
+ shape_tczyx=json.dumps(meta["shape_tczyx"]),
502
+ voxel_size_um=json.dumps(meta["spacing_xyz"]),
503
+ timestamps_status="starting_time_and_rate_4Hz",
504
+ fov_region="unknown",
505
+ )
506
+ dump(root / "metadata/wormid_ey_image_annotation_discrepancy.json", meta)
507
+ if (raw / "sf-behavior.parquet").exists():
508
+ meta = json.loads((audit / "sf-behavior.json").read_text())
509
+ rid = "dandi-000776-" + meta["asset"]["path"].split("/")[0]
510
+ df = pd.read_parquet(raw / "sf-behavior.parquet")
511
+ df["recording_id"], df["component_type"], df["status"] = rid, "behavior_summary", "measured"
512
+ components.setdefault(rid, {})["posture"] = table(root, f"data/posture/{rid}.parquet", df)
513
+ recording(rid)["posture_gt_level"] = "behavioral_summaries_only_no_centerline"
514
+ dump(root / "metadata/sf_behavior_provenance.json", meta)
515
+ for stem, rid, frames in [
516
+ ("ascent-opterra", "ascent-opterra", list(range(4))),
517
+ ("zephir-zm9624", "zephir-zm9624", list(range(4))),
518
+ ("targettrack-epfl10", "targettrack-epfl10", list(range(32))),
519
+ ("wormid-ey-20190924-01", "dandi-000541-sub-20190924-01", list(range(4))),
520
+ ]:
521
+ src = workspace / "volumes" / (stem + ".h5")
522
+ if src.exists():
523
+ dest = root / "assets" / rid / "pilot.h5"
524
+ dest.parent.mkdir(parents=True, exist_ok=True)
525
+ shutil.copy2(src, dest)
526
+ components.setdefault(rid, {})["volume"] = {
527
+ "path": str(dest.relative_to(root)),
528
+ "frames": frames,
529
+ "axis_order": "CZYX",
530
+ "transformation": "axis_permutation_only",
531
+ }
532
+ recording(rid)["hosted_volume"] = True
533
+ for source, name, priority, url, status in [
534
+ (
535
+ "nerve",
536
+ "NeRVE original release",
537
+ "P0",
538
+ "https://doi.org/10.21227/H2901H",
539
+ "one_annotation_recording_via_ZephIR; original_inventory_pending",
540
+ ),
541
+ (
542
+ "cender",
543
+ "CeNDeR C1-C3",
544
+ "P0",
545
+ "https://osf.io/v2b5n/",
546
+ "blocked_data_license_unstated; OSF_storage_empty; linked_Google_Drive_API_404",
547
+ ),
548
+ (
549
+ "brainalignnet",
550
+ "BrainAlignNet / ANTSUN 2.0",
551
+ "P1",
552
+ "https://doi.org/10.7910/DVN/8UE0H9",
553
+ "Dataverse_API_unavailable; license_and_overlap_pending",
554
+ ),
555
+ (
556
+ "skuhersky-atlas",
557
+ "Skuhersky 3D anatomical atlas",
558
+ "P2",
559
+ "https://github.com/bluevex/elegans-atlas",
560
+ "data_license_unresolved; external_reference_only",
561
+ ),
562
+ (
563
+ "neuropal-canonical",
564
+ "NeuroPAL canonical positions",
565
+ "P2",
566
+ "https://github.com/openworm/NeuroPAL",
567
+ "shared_Skuhersky_CSV; data_license_unresolved",
568
+ ),
569
+ (
570
+ "stat-atlas",
571
+ "Statistical anatomical atlas",
572
+ "P2",
573
+ "https://github.com/amin-nejat/stat-atlas",
574
+ "data_license_unresolved; external_reference_only",
575
+ ),
576
+ (
577
+ "openworm-movement",
578
+ "OpenWorm Movement Database",
579
+ "P2",
580
+ "https://movement.openworm.org/",
581
+ "DNS_resolution_failed; license_and_assets_unresolved",
582
+ ),
583
+ (
584
+ "eigenworms",
585
+ "Stephens et al. 2008",
586
+ "P2",
587
+ "https://doi.org/10.1371/journal.pcbi.1000028",
588
+ "paper_audited; reusable_basis_asset_not_ingested",
589
+ ),
590
+ ]:
591
+ sources.append(
592
+ {
593
+ "source_id": source,
594
+ "name": name,
595
+ "priority": priority,
596
+ "url": url,
597
+ "version": None,
598
+ "license": None,
599
+ "license_status": "verify",
600
+ "assembly_status": status,
601
+ "asset_count": None,
602
+ "bytes": None,
603
+ }
604
+ )
605
+ # All pilots are development assets. No small single-worm split is presented as generalization.
606
+ active = sorted(components)
607
+ splits = {
608
+ p: {"train": [], "validation": [], "test": [], "development": active, "quarantine": []}
609
+ for p in ["tracking_gt", "anatomical_verification", "anatomical_consistency"]
610
+ }
611
+ splits["tracking_gt"]["development"] = ["ascent-opterra"]
612
+ splits["anatomical_verification"]["development"] = ["ascent-opterra"]
613
+ table(root, "data/recordings/recordings.parquet", pd.DataFrame(recordings))
614
+ dump(root / "metadata/sources.json", sources)
615
+ dump(root / "metadata/upstream_assets.json", upstream)
616
+ dump(root / "metadata/overlap_registry.json", overlaps)
617
+ dump(
618
+ root / "metadata/client_manifest.json",
619
+ {
620
+ "schema_version": VERSION,
621
+ "recordings": "data/recordings/recordings.parquet",
622
+ "components": components,
623
+ "splits": splits,
624
+ },
625
+ )
626
+ dump(
627
+ root / "splits/assignments.json",
628
+ {
629
+ "seed": SEED,
630
+ "status": "development_only_no_frozen_test",
631
+ "protocols": splits,
632
+ "original_wormid_commit": WORMND_COMMIT,
633
+ },
634
+ )
635
+ table(root, "splits/original_wormid_folds.parquet", original)
636
+ dump(
637
+ root / "evaluation/validation.json",
638
+ {"status": "passed", "scope": "published_table_invariants", "tables": qc},
639
+ )
640
+ dump(
641
+ root / "metadata/assembly_counts.json",
642
+ {
643
+ "version": VERSION,
644
+ "assembled_at": now,
645
+ "inventory_recordings": len(recordings),
646
+ "wormid_inventory_assets": sum(
647
+ r["source_dataset"] in {f"dandi-{i}" for i in list(DANDI_COHORTS)[:7]}
648
+ for r in recordings
649
+ ),
650
+ "ingested": counts,
651
+ "source_inventory_entries": len(sources),
652
+ "pilot_imaging_frames": sum(
653
+ len(c.get("volume", {}).get("frames", [])) for c in components.values()
654
+ ),
655
+ "anatomical_clouds": sum("anatomy" in c for c in components.values()),
656
+ "measured_centerlines": 0,
657
+ "independent_behavior_summary_recordings": sum(
658
+ "posture" in c for c in components.values()
659
+ ),
660
+ "release_gates": {
661
+ "A": "partial: full non-DANDI inventories pending",
662
+ "B": "partial: independent moving-worm GT and centerline pending",
663
+ "C": "not_passed: all P0 ingestion and held-out evaluation pending",
664
+ },
665
+ },
666
+ )
667
+ harmonize_tables(root)
668
+ print(
669
+ json.dumps(
670
+ {"root": str(root), "inventory_recordings": len(recordings), "ingested": counts},
671
+ indent=2,
672
+ )
673
+ )
674
+ return root
675
+
676
+
677
+ if __name__ == "__main__":
678
+ build(*sys.argv[1:3])
src/cell_tracking/data/wormtrack_verify/client.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Recording-selective Hub access; metadata never triggers volume acquisition."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+
9
+ class MissingComponentError(LookupError):
10
+ """A requested component is unavailable, rather than an empty measurement."""
11
+
12
+
13
+ class BenchmarkClient:
14
+ """Read a pinned release or local assembly with a per-file download budget.
15
+
16
+ Tables retain native XYZ voxel coordinates. Physical XYZ fields are null if
17
+ calibration is unknown. Volumes return CZYX, without intensity normalization.
18
+ Local assemblies support the same API as remote commits. Remote callers must
19
+ explicitly select a revision; this prevents silent changes in experiments.
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ repo_id="pytc/trackingBench",
25
+ *,
26
+ revision=None,
27
+ root=None,
28
+ cache_dir=None,
29
+ max_download_bytes=128 * 1024**2,
30
+ ):
31
+ if root is None and revision is None:
32
+ raise ValueError("Pin a Hub commit/tag with revision, or supply root")
33
+ self.repo_id = repo_id
34
+ self.revision = revision
35
+ self.root = Path(root) if root is not None else None
36
+ self.cache_dir = cache_dir
37
+ self.max_download_bytes = max_download_bytes
38
+ self.manifest = json.loads(self._file("metadata/client_manifest.json").read_text())
39
+
40
+ def _file(self, path):
41
+ logical = Path(path)
42
+ if logical.is_absolute() or ".." in logical.parts:
43
+ raise ValueError("Manifest paths must stay within the repository")
44
+ if self.root is not None:
45
+ return self.root / logical
46
+ from huggingface_hub import HfApi, hf_hub_download
47
+
48
+ info = next(
49
+ iter(
50
+ HfApi().get_paths_info(
51
+ self.repo_id, [path], repo_type="dataset", revision=self.revision
52
+ )
53
+ ),
54
+ None,
55
+ )
56
+ if info is None or getattr(info, "size", None) is None:
57
+ raise MissingComponentError(path)
58
+ if info.size > self.max_download_bytes:
59
+ raise ValueError(f"{path} exceeds the {self.max_download_bytes}-byte file budget")
60
+ return Path(
61
+ hf_hub_download(
62
+ self.repo_id,
63
+ path,
64
+ repo_type="dataset",
65
+ revision=self.revision,
66
+ cache_dir=self.cache_dir,
67
+ )
68
+ )
69
+
70
+ def list_recordings(self, **filters):
71
+ import pandas as pd
72
+
73
+ df = pd.read_parquet(self._file(self.manifest["recordings"]))
74
+ for key, value in filters.items():
75
+ df = df.loc[df[key] == value]
76
+ return df.reset_index(drop=True)
77
+
78
+ def _component(self, recording_id, component):
79
+ import pandas as pd
80
+
81
+ entry = self.manifest["components"].get(recording_id)
82
+ if entry is None:
83
+ raise MissingComponentError(f"Unknown recording: {recording_id}")
84
+ path = entry.get(component)
85
+ if path is None:
86
+ raise MissingComponentError(f"{component} unavailable for {recording_id}")
87
+ return pd.read_parquet(self._file(path))
88
+
89
+ def load_detections(self, recording_id):
90
+ return self._component(recording_id, "detections")
91
+
92
+ def load_tracks(self, recording_id, label_source=None):
93
+ df = self._component(recording_id, "tracks")
94
+ if label_source is not None:
95
+ df = df.loc[df.annotation_type == label_source].reset_index(drop=True)
96
+ return df
97
+
98
+ def load_reference_cloud(self, recording_id):
99
+ return self._component(recording_id, "anatomy")
100
+
101
+ def load_posture(self, recording_id):
102
+ return self._component(recording_id, "posture")
103
+
104
+ def load_corruptions(self, recording_id):
105
+ return self._component(recording_id, "perturbations")
106
+
107
+ def get_split(self, protocol, partition):
108
+ if protocol not in {"tracking_gt", "anatomical_verification", "anatomical_consistency"}:
109
+ raise ValueError(f"Unknown protocol: {protocol}")
110
+ if partition not in {"train", "validation", "test", "development", "quarantine"}:
111
+ raise ValueError(f"Unknown partition: {partition}")
112
+ return self.manifest["splits"][protocol].get(partition, [])
113
+
114
+ def load_volume(self, recording_id, frame, channels=None):
115
+ """Download only the small declared imaging pilot and return one CZYX frame.
116
+
117
+ Frames outside the hosted pilot raise MissingComponentError with upstream
118
+ resolution details. Original multi-GB recordings are never auto-downloaded.
119
+ """
120
+ import h5py
121
+ import numpy as np
122
+
123
+ entry = self.manifest["components"].get(recording_id, {})
124
+ volume = entry.get("volume")
125
+ if volume is None or frame not in volume["frames"]:
126
+ raise MissingComponentError(
127
+ f"No hosted frame {frame} for {recording_id}; consult metadata/upstream_assets.json"
128
+ )
129
+ with h5py.File(self._file(volume["path"]), "r") as h:
130
+ data = h[f"frames/{frame}"][()]
131
+ return data if channels is None else np.take(data, channels, axis=0)
src/cell_tracking/data/wormtrack_verify/inventory.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pin official source metadata without bulk acquisition."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import requests
9
+
10
+ DANDI_COHORTS = {
11
+ "000541": "EY",
12
+ "000692": "KK",
13
+ "000565": "SK1",
14
+ "000472": "SK2",
15
+ "000776": "SF",
16
+ "000715": "NP",
17
+ "000714": "HL",
18
+ "001623": "Dunn",
19
+ "000981": "Chemosensory",
20
+ }
21
+ ZENODO = {"17561700": "ASCENT", "10818810": "ZephIR", "10008744": "Targettrack"}
22
+ WORMND_COMMIT = "0c74e9ddffee138cfc6330ab65c0e690e8e199dd"
23
+
24
+
25
+ def inventory(workspace):
26
+ """Save release metadata, immutable asset IDs/checksums, and the original split CSV.
27
+
28
+ Re-running an inventory captures the current latest upstream release. Assembly
29
+ uses saved snapshots, never silently updates an existing experiment. Original
30
+ data licenses are taken from release metadata, separately from code licenses.
31
+ """
32
+ out = Path(workspace) / "audit"
33
+ out.mkdir(parents=True, exist_ok=True)
34
+ for identifier in DANDI_COHORTS:
35
+ base = f"https://api.dandiarchive.org/api/dandisets/{identifier}/versions/"
36
+ versions = requests.get(base, timeout=60)
37
+ versions.raise_for_status()
38
+ versions = versions.json()
39
+ versions = versions.get("results", versions) if isinstance(versions, dict) else versions
40
+ published = [v["version"] for v in versions if v["version"] != "draft"]
41
+ version = max(published) if published else "draft"
42
+ metadata = requests.get(base + version + "/", timeout=60)
43
+ metadata.raise_for_status()
44
+ (out / f"dandi-{identifier}-pinned.json").write_text(json.dumps(metadata.json(), indent=2))
45
+ assets = []
46
+ url = base + version + "/assets/?page_size=1000"
47
+ while url:
48
+ response = requests.get(url, timeout=60)
49
+ response.raise_for_status()
50
+ page = response.json()
51
+ assets.extend(page["results"])
52
+ url = page.get("next")
53
+ (out / f"dandi-{identifier}-assets.json").write_text(
54
+ json.dumps({"version": version, "assets": assets}, indent=2)
55
+ )
56
+ for identifier in ZENODO:
57
+ response = requests.get(f"https://zenodo.org/api/records/{identifier}", timeout=60)
58
+ response.raise_for_status()
59
+ (out / f"zenodo-{identifier}.json").write_text(json.dumps(response.json(), indent=2))
60
+ url = (
61
+ f"https://raw.githubusercontent.com/focolab/WormND/{WORMND_COMMIT}"
62
+ "/neuron_tracking/3deecelltracker/dataset_split.csv"
63
+ )
64
+ response = requests.get(url, timeout=60)
65
+ response.raise_for_status()
66
+ (out / "wormid-tracking-split.csv").write_text(response.text)
src/cell_tracking/evaluation/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """WormTrack-Verify benchmark helpers."""
src/cell_tracking/evaluation/wormtrack_verify.py ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Explicit pilot diagnostics for association-only corruption and abstention.
2
+
3
+ These metrics are defined in the benchmark specification, not replacements for
4
+ canonical HOTA/IDF1. Detections stay fixed. One global identity alignment is allowed.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import itertools
10
+
11
+ import numpy as np
12
+ import pandas as pd
13
+ from scipy.optimize import linear_sum_assignment
14
+ from sklearn.metrics import average_precision_score, roc_auc_score
15
+
16
+ from cell_tracking.data.wormtrack_verify.adapters import TRUSTED, XYZ, validate_tracks
17
+
18
+
19
+ def corrupt_tracks(tracks, *, kind, seed, start_frame, stop_frame=None, pair=None):
20
+ """Deterministic swaps/fragmentation with row-level error labels and fixed observations.
21
+
22
+ Labels mark correspondence to the original reference identity. Purely global
23
+ renaming is not an error; start_frame must follow the first reference frame.
24
+ Original images, detection IDs, and coordinates are preserved.
25
+ """
26
+ validate_tracks(tracks)
27
+ if not set(tracks.annotation_type).issubset(TRUSTED):
28
+ raise ValueError("Corruptions require independently trusted source annotations")
29
+ if tracks.recording_id.nunique() != 1 or tracks.label_set.nunique() != 1:
30
+ raise ValueError("Corrupt one recording and one label set at a time")
31
+ frames = sorted(tracks.frame_index.unique())
32
+ if start_frame <= frames[0] or start_frame > frames[-1]:
33
+ raise ValueError("Corruption must follow the identity anchor and lie inside the recording")
34
+ stop_frame = frames[-1] + 1 if stop_frame is None else stop_frame
35
+ if stop_frame <= start_frame or stop_frame > frames[-1] + 1:
36
+ raise ValueError("Invalid corruption interval")
37
+ rng = np.random.default_rng(seed)
38
+ ids = sorted(tracks.track_id.unique())
39
+ if pair is None:
40
+ if len(ids) < 2:
41
+ raise ValueError("Need two tracks")
42
+ pair = list(rng.choice(ids, 2, replace=False))
43
+ if len(pair) != 2 or pair[0] == pair[1] or not set(pair).issubset(ids):
44
+ raise ValueError("Pair must identify two distinct source tracks")
45
+ df = tracks.copy()
46
+ df["reference_track_id"] = df.track_id
47
+ interval = (df.frame_index >= start_frame) & (df.frame_index < stop_frame)
48
+ affected = interval & df.track_id.isin(pair)
49
+ if not affected.any():
50
+ raise ValueError("No observations in the selected corruption interval")
51
+ if kind in {"single_frame_swap", "persistent_swap", "swap_recovery", "nearby_swap"}:
52
+ if kind == "single_frame_swap":
53
+ affected &= df.frame_index == start_frame
54
+ df.loc[affected, "track_id"] = df.loc[affected, "track_id"].map(
55
+ {pair[0]: pair[1], pair[1]: pair[0]}
56
+ )
57
+ elif kind == "fragmentation":
58
+ affected = interval & (df.track_id == pair[0])
59
+ df.loc[affected, "track_id"] = pair[0] + f":fragment:{seed}"
60
+ elif kind == "dropout":
61
+ affected = interval & (df.track_id == pair[0])
62
+ df.loc[affected, "validity"] = False
63
+ else:
64
+ raise ValueError(f"Unsupported pilot corruption: {kind}")
65
+ df["is_error"] = affected
66
+ df["corruption_type"] = kind
67
+ df["seed"] = seed
68
+ df["scenario_id"] = f"{kind}:seed{seed}"
69
+ return df
70
+
71
+
72
+ def association_metrics(reference, prediction):
73
+ """Score shared oracle detections with one recording-wide identity permutation.
74
+
75
+ Missing predictions count against coverage and correct-observation rate.
76
+ Switches are changes in predicted identity along each reference trajectory;
77
+ fragmented runs also count reappearance after a missing prediction. Evaluation
78
+ covers only source-supported reference observations, not unannotated frames.
79
+ """
80
+ validate_tracks(reference)
81
+ validate_tracks(prediction)
82
+ if reference.recording_id.nunique() != 1 or prediction.recording_id.nunique() != 1:
83
+ raise ValueError("Evaluate each independent recording separately")
84
+ if reference.recording_id.iloc[0] != prediction.recording_id.iloc[0]:
85
+ raise ValueError("Mismatched recording")
86
+ key = ["frame_index", "detection_id"]
87
+ valid_prediction = prediction.loc[prediction.validity]
88
+ joined = reference.loc[reference.validity].merge(
89
+ valid_prediction[key + ["track_id"]],
90
+ on=key,
91
+ how="left",
92
+ suffixes=("_gt", "_pred"),
93
+ validate="one_to_one",
94
+ )
95
+ gt = sorted(joined.track_id_gt.unique())
96
+ pred = sorted(valid_prediction.track_id.unique())
97
+ counts = (
98
+ pd.crosstab(joined.track_id_gt, joined.track_id_pred)
99
+ .reindex(index=gt, columns=pred, fill_value=0)
100
+ .to_numpy()
101
+ )
102
+ mapping = {}
103
+ if counts.size:
104
+ rows, cols = linear_sum_assignment(-counts)
105
+ mapping = {pred[c]: gt[r] for r, c in zip(rows, cols, strict=True)}
106
+ correct = joined.track_id_pred.map(mapping).eq(joined.track_id_gt)
107
+ switches = fragments = 0
108
+ for _, group in joined.sort_values("frame_index").groupby("track_id_gt"):
109
+ ids = group.track_id_pred.tolist()
110
+ observed = [i for i in ids if pd.notna(i)]
111
+ switches += sum(a != b for a, b in itertools.pairwise(observed))
112
+ fragments += max(
113
+ 0,
114
+ sum(
115
+ pd.notna(v) and (j == 0 or pd.isna(ids[j - 1]) or v != ids[j - 1])
116
+ for j, v in enumerate(ids)
117
+ )
118
+ - 1,
119
+ )
120
+ extra = len(
121
+ valid_prediction.merge(joined[key], on=key, how="left", indicator=True).query(
122
+ '_merge == "left_only"'
123
+ )
124
+ )
125
+ return {
126
+ "reference_observations": len(joined),
127
+ "predicted_observations": len(valid_prediction),
128
+ "coverage": float(joined.track_id_pred.notna().mean()),
129
+ "correct_observation_rate": float(correct.mean()),
130
+ "identity_switches": int(switches),
131
+ "fragmentations": int(fragments),
132
+ "extra_observations": int(extra),
133
+ }
134
+
135
+
136
+ def reference_residual_scores(tracks, reference_cloud, *, physical=True):
137
+ """Identity-sensitive distance from the fixed first-frame reference.
138
+
139
+ This intentionally simple consistency diagnostic includes genuine tissue motion.
140
+ It is not an independent deformation model or a certificate of correctness.
141
+ Reference cloud must come from an independently trusted reference observation.
142
+ """
143
+ cols = [f"{a}_um" for a in "xyz"] if physical else XYZ
144
+ ref = reference_cloud.set_index("track_id")
145
+ if ref.index.duplicated().any():
146
+ raise ValueError("Reference identities must be unique")
147
+ a = tracks[cols].to_numpy(dtype=float)
148
+ b = ref.reindex(tracks.track_id)[cols].to_numpy(dtype=float)
149
+ scores = np.linalg.norm(a - b, axis=1)
150
+ scores[~tracks.validity.to_numpy()] = np.inf
151
+ # Unseen fragment IDs are unsupported; preserve absence rather than fit a new anatomy.
152
+ scores[np.isnan(scores)] = np.inf
153
+ return scores
154
+
155
+
156
+ def verifier_metrics(scores, is_error, *, threshold):
157
+ """Fixed-population selective risk/coverage; ties enter a risk curve together.
158
+
159
+ False certification = accepted errors / all labeled errors. Selective risk =
160
+ accepted errors / accepted observations. Unsupported scores abstain. Threshold
161
+ must be specified before evaluation; this function does not select it.
162
+ """
163
+ scores = np.asarray(scores, dtype=float)
164
+ labels = np.asarray(is_error, dtype=bool)
165
+ if len(scores) != len(labels) or not len(scores) or np.isnan(scores).any():
166
+ raise ValueError("Scores and labels must be aligned, nonempty, and non-NaN")
167
+ if np.isnan(threshold):
168
+ raise ValueError("Threshold cannot be NaN")
169
+ accept = np.isfinite(scores) & (scores <= threshold)
170
+ # Infinity denotes abstention; map it above all finite scores for ranking metrics.
171
+ finite = scores[np.isfinite(scores)]
172
+ ranked = np.where(np.isfinite(scores), scores, (finite.max() + 1 if len(finite) else 1))
173
+ both = labels.any() and not labels.all()
174
+ curve = []
175
+ order = np.flatnonzero(np.isfinite(scores))
176
+ order = order[np.argsort(scores[order], kind="stable")]
177
+ if len(order):
178
+ ordered_scores = scores[order]
179
+ cumulative_errors = np.cumsum(labels[order])
180
+ ends = np.r_[np.flatnonzero(np.diff(ordered_scores) != 0), len(order) - 1]
181
+ curve = [
182
+ {
183
+ "threshold": float(ordered_scores[i]),
184
+ "coverage": float((i + 1) / len(scores)),
185
+ "risk": float(cumulative_errors[i] / (i + 1)),
186
+ }
187
+ for i in ends
188
+ ]
189
+ return {
190
+ "observations": len(scores),
191
+ "error_prevalence": float(labels.mean()),
192
+ "auroc": float(roc_auc_score(labels, ranked)) if both else None,
193
+ "auprc": float(average_precision_score(labels, ranked)) if both else None,
194
+ "false_certification_rate": float((accept & labels).sum() / labels.sum())
195
+ if labels.any()
196
+ else None,
197
+ "certified_coverage": float(accept.mean()),
198
+ "selective_risk": float(labels[accept].mean()) if accept.any() else None,
199
+ "correct_certified_coverage": float((accept & ~labels).mean()),
200
+ "threshold": float(threshold),
201
+ "risk_coverage": curve,
202
+ }
203
+
204
+
205
+ def oracle_association_baseline(detections, *, method="hungarian", physical=True):
206
+ """Untrained Euclidean nearest-neighbor or bipartite association on fixed detections."""
207
+ if method not in {"nearest_neighbor", "hungarian"}:
208
+ raise ValueError(method)
209
+ cols = [f"{a}_um" for a in "xyz"] if physical else XYZ
210
+ output = []
211
+ previous = None
212
+ next_id = 0
213
+ for frame, points in detections.sort_values("frame_index").groupby("frame_index"):
214
+ points = points.copy().reset_index(drop=True)
215
+ xyz = points[cols].to_numpy(dtype=float)
216
+ if not np.isfinite(xyz).all():
217
+ raise ValueError("Baseline requires valid coordinates in the selected units")
218
+ ids = [None] * len(points)
219
+ if previous is not None:
220
+ old_xyz, old_ids = previous
221
+ distance = np.linalg.norm(old_xyz[:, None] - xyz[None], axis=2)
222
+ if method == "hungarian":
223
+ rows, columns = linear_sum_assignment(distance)
224
+ else:
225
+ pairs = sorted((distance[i, j], i, j) for i, j in enumerate(distance.argmin(1)))
226
+ chosen = set()
227
+ matches = []
228
+ for _, i, j in pairs:
229
+ if j not in chosen:
230
+ matches.append((i, j))
231
+ chosen.add(j)
232
+ rows = [p[0] for p in matches]
233
+ columns = [p[1] for p in matches]
234
+ for i, j in zip(rows, columns, strict=True):
235
+ ids[j] = old_ids[i]
236
+ for i, identity in enumerate(ids):
237
+ if identity is None:
238
+ ids[i] = f"baseline:{next_id}"
239
+ next_id += 1
240
+ points["track_id"] = ids
241
+ points["annotation_type"] = "algorithm_prediction"
242
+ points["label_set"] = "prediction"
243
+ output.append(points)
244
+ previous = xyz, ids
245
+ return pd.concat(output, ignore_index=True)