Skip to main content

m30 · Capstone: build a mini mapping system on a simulated atrium

Warning

Education only. Not for diagnosis, treatment or any clinical decision.

Note

Draft, stage 2 of 6. The derivations are written, and each equation is checked by tests in tests/test_m30_mapping.py. Demos, the guided code lab, questions and the remaining sections follow in later stages (plan: docs/outlines/m30-outline.md). Nothing here has had expert review yet. This capstone builds its own minimal versions of steps that modules m20 and m22–m26 will treat in depth.

In 60 seconds

A mapping system turns many small measurements into one picture: where the catheter was, what it recorded, and when the tissue under it activated. In this capstone you build each stage on a simulated atrium whose true activation is known, so every map you make can be scored. You will find that a map is an estimate, with errors you can name and measure: too few points, positions that are off, activation times that are misread, and gaps that interpolation fills with guesses.

From the field

Planned in the outline (docs/outlines/m30-outline.md); written in a later stage.

Derivations

Symbols used throughout. \(S\) the atrial surface, a triangle mesh. \(T(\mathbf{x})\) activation time (ms). \(v\) conduction velocity (mm/ms, the same as m/s). \(\mathbf{p}_i\) true position of acquired point \(i\) and \(\hat{\mathbf{p}}_i\) its measured position (mm). \(T_i\) the activation time annotated at point \(i\). \(N\) number of points. \(d(\cdot,\cdot)\) distance along the surface (mm).

The ground truth

The simulated atrium needs an activation pattern that is known everywhere. The simplest model that still behaves like a spreading wave is the eikonal equation: the front moves at local speed \(v\), always taking the fastest route. On the surface,

\[ v(\mathbf{x})\,\lvert \nabla_S T(\mathbf{x}) \rvert = 1, \qquad T(\mathbf{x}_0) = t_0 \tag{1}\]

where \(\nabla_S\) is the gradient along the surface and \(\mathbf{x}_0\) is the pacing site. With constant \(v\), \(T\) is simply the shortest distance along the surface divided by \(v\). A scar is a region with \(v = 0\): the wave must go around it. A slow zone has a smaller \(v\).

Fast marching solves this equation in a single ordered sweep (Sethian 1996). The course code uses a simpler scheme that reaches the same answer: each triangle repeatedly offers its third vertex the earliest time a front crossing the opposite edge could reach it, until no time changes. The tests check it against exact answers: distance over speed on a flat sheet, great-circle distance on a sphere, and the detour around a line of block.

Key takeaways

  • The eikonal model gives a known activation map; scar is \(v = 0\), slow conduction a smaller \(v\).
  • It ignores curvature effects, recovery and anything that depends on the previous beat.

What the catheter reports

At each acquired point the system records an electrogram, from which it annotates an activation time and a voltage (the electrograms come from the m03 model, and annotation is covered in m22 and m23). It also records where the catheter was, with error. A simple model of the measured position:

\[ \hat{\mathbf{p}}_i = \mathbf{p}_i + \boldsymbol{\varepsilon}_i + \mathbf{d}(t_i), \qquad \boldsymbol{\varepsilon}_i \sim \mathcal{N}(\mathbf{0}, \sigma^2 I), \quad \mathbf{d}(t) = A \sin\!\left(\frac{2\pi t}{T_{\text{resp}}}\right) \hat{\mathbf{u}} \tag{2}\]

a random error of spread \(\sigma\) in each direction, plus a respiratory displacement of amplitude \(A\) and period \(T_{\text{resp}}\) along a direction \(\hat{\mathbf{u}}\). Real localization errors and respiratory motion are covered in m16–m19; typical values: TODO(source).

Key takeaways

  • A measured point carries random error and slow, correlated motion; the second does not average out over a few points.

From points to the surface

Measured points rarely lie exactly on the surface. Before interpolating, each one is moved to the nearest point of the mesh:

\[ \mathbf{p}_i^{S} = \arg\min_{\mathbf{y} \in S} \lVert \mathbf{y} - \hat{\mathbf{p}}_i \rVert \tag{3}\]

The closest point on each triangle has a closed form (it lies inside the triangle, on an edge or at a vertex), and the mesh’s closest point is the best of those. Projection removes the error normal to the wall but keeps the error along it.

Key takeaways

  • Projection fixes “how far off the wall”, not “where along the wall”.

Filling the gaps

Between points the map is a guess. The simplest guess weights nearby points more:

\[ \hat T(\mathbf{x}) = \frac{\sum_i w_i\, T_i}{\sum_i w_i}, \qquad w_i = d(\mathbf{x}, \mathbf{p}_i^{S})^{-p} \tag{4}\]

with distance measured along the surface, not through the chamber, and a power \(p > 0\). This inverse-distance interpolation reproduces the data at the points, keeps a constant field constant and never leaves the range of the data. It also cannot invent a feature that no point sampled: a slow zone that falls between points is simply smoothed away. Module m24 covers better interpolants.

Key takeaways

  • Interpolate along the surface; inverse-distance weighting is a baseline that stays within the data range.
  • Features smaller than the gaps between points cannot appear in the map.

Conduction velocity

Locally, activation time is close to a plane: \(T \approx a + \mathbf{g}\cdot\mathbf{x}\). The gradient \(\mathbf{g}\) points along the direction of travel and its size is one over the speed, so

\[ \mathbf{v} = \frac{\mathbf{g}}{\lvert \mathbf{g} \rvert^{2}} \tag{5}\]

with \(\mathbf{g}\) fitted by least squares to a few neighbouring points. Many methods exist for this step, and sparse, uneven and uncertain data make it hard (Cantwell et al. 2015); module m25 compares them. The plane fit is exact for a plane wave and biased where fronts curve or collide.

Key takeaways

  • Velocity is the gradient of activation time divided by its squared length.
  • Curved or colliding fronts, and noisy times, bias the estimate.

Scoring the map

Because the truth is known, the map can be scored on every mesh vertex \(\mathbf{x}_j\), \(j = 1, \dots, M\). Two numbers summarize it: the error of the map and how well the points cover the surface.

\[ \mathrm{RMSE} = \sqrt{\frac{1}{M}\sum_{j=1}^{M}\left(\hat T(\mathbf{x}_j) - T(\mathbf{x}_j)\right)^2}, \qquad h = \max_{\mathbf{x}\in S}\, \min_i\, d(\mathbf{x}, \mathbf{p}_i^{S}) \tag{6}\]

The fill distance \(h\) is the radius of the largest region with no point in it. It falls as points are added, but only where they are added; module m26 relates it to interpolation error.

Key takeaways

  • Score maps against truth with RMSE; report the fill distance alongside it.
  • A small average error can hide a large gap; \(h\) shows where the map is pure interpolation.

Clinical correlate

NotePending clinical review

Planned in the outline. Requires sign-off by an EP physician.

Visual summary

Planned in the outline.

How experts think

Planned in the outline.

Cheat sheet

Planned in the outline.

Interview questions

Planned in the outline.

Code lab

Planned in the outline.

Self-check

Planned in the outline.

Literature figures

Planned in the outline.

Further reading

Planned in the outline.

References

Cantwell, C D, C H Roney, F S Ng, et al. 2015. “Techniques for Automated Local Activation Time Annotation and Conduction Velocity Estimation in Cardiac Mapping.” Computers in Biology and Medicine 65: 229–42. https://doi.org/10.1016/j.compbiomed.2015.04.027.
Sethian, J A. 1996. “A Fast Marching Level Set Method for Monotonically Advancing Fronts.” Proceedings of the National Academy of Sciences of the USA 93 (4): 1591–95. https://doi.org/10.1073/pnas.93.4.1591.