ordering
sleap.qc.features.ordering
¶
Keypoint ordering features: turning angles along chains.
Detects nodes that are labeled out of order along an ordered chain
(e.g. a tail TTI -> Tail_0 -> Tail_1 -> Tail_2 -> TailTip).
The core idea (maintainer's design): treat consecutive chain segments as
vectors v_i = node_i - node_{i-1} and look at the turning angle between
consecutive segments at each interior node (the angle between v_i and
v_{i+1}). A correctly ordered chain -- even one that is naturally curled --
has gentle turning angles. A mislabel (e.g. an adjacent swap) produces a sharp
direction reversal, which shows up as one or two large turning angles. An
out-of-order pair that is not adjacent (e.g. Tail_1 swapped with
Tail_3) additionally makes two non-adjacent segments geometrically cross,
which is a strong, unambiguous signal.
The turning angle is invariant to translation, rotation, and uniform scale, so these features do not need any learned per-dataset statistics.
Functions:
| Name | Description |
|---|---|
compute_chain_ordering |
Detect wrong keypoint order along ordered chains via turning angles. |
resolve_chains |
Resolve ordered chains to node-index sequences. |
compute_chain_ordering(points, chains, max_turn_angle=DEFAULT_MAX_TURN_ANGLE)
¶
Detect wrong keypoint order along ordered chains via turning angles.
For each chain, the turning angle is computed at every interior node from
the two adjacent segment vectors. The order_inversion_rate is the
fraction of interior nodes whose turning angle exceeds max_turn_angle
(a sharp reversal). The chain_intersection_count is the number of
non-adjacent segment pairs that geometrically cross -- a strong signal of a
non-local swap (e.g. Tail_1 <-> Tail_3). Results are aggregated as
the maximum over all chains, and the worst chain/node are recorded for use
in an explanation.
All metrics are invariant to translation, rotation, and uniform scale, and NaN (invisible/missing) nodes are skipped without leaking into results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
|
required |
chains
|
list[list[int]]
|
List of chains, each an ordered list of node indices. Use
:func: |
required |
max_turn_angle
|
float
|
Per-interior-node turning-angle threshold in radians above which a node is counted as an inversion. Default ~60 degrees. |
DEFAULT_MAX_TURN_ANGLE
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with:
- |
Source code in sleap/qc/features/ordering.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
resolve_chains(skeleton_node_names, ordered_chains_by_name, auto_chains)
¶
Resolve ordered chains to node-index sequences.
A user-declared ordering is treated as ground truth: when
ordered_chains_by_name is provided, those chains (given as lists of node
names) are resolved to node indices and used directly. This makes the
turning-angle rule deterministic, since the intended order is known.
When no user-defined chains are given, falls back to auto_chains (chain
index sequences inferred from the skeleton graph, e.g. from
SkeletonAnalyzer.get_curvature_chains()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton_node_names
|
list[str]
|
Ordered list of node names; index |
required |
ordered_chains_by_name
|
list[list[str]] | None
|
Optional list of user-defined chains, each a
list of node names in the intended order (e.g.
|
required |
auto_chains
|
list[list[int]] | None
|
Optional fallback list of chains as node-index sequences. |
required |
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
List of chains as node-index sequences. Empty if nothing resolves. |