# Field validation: captures, holdouts and the comparison

> **What this is.** A workflow for comparing a Sommerwire model with calibrated measurements of a built antenna:
> what to measure, how a measurement is written down so that it can be checked, which data are held back, and a
> tool that compares the two at the plane where the instrument was calibrated.
> **No measurement exists in this repository.** It holds templates and holdout registrations only, and a test fails if
> anything else appears here. Nothing in this directory shows that a model is right, and the workflow as it stands
> does not show that any model matches any hardware. It is the way to find out.

    node validation/field/fieldwork.js check <capture.json>...                  # complete? are the files the ones it names?
    node validation/field/fieldwork.js compare <capture.json> [--freeze <file>] [--points N]
    node validation/field/fieldwork.js lock                                     # the holdouts against their lock; the openings on record
    node validation/field/fieldwork.js hash <file>...                           # sha256, for a capture's "sha256" fields
    node --test validation/field/                                               # the tool's own tests

| File | What it is |
|---|---|
| [templates/termiloop-vna.capture.json](templates/termiloop-vna.capture.json), [templates/dx-commander-vna.capture.json](templates/dx-commander-vna.capture.json) | Capture templates for calibrated complex S11 sweeps. No values. |
| [templates/termiloop-current.capture.json](templates/termiloop-current.capture.json), [templates/dx-commander-current.capture.json](templates/dx-commander-current.capture.json) | Capture templates for branch currents, with the branches each antenna needs. No values. |
| [templates/model.freeze.json](templates/model.freeze.json) | The record that freezes a model before a holdout is opened. |
| [holdouts/termiloop.holdout.json](holdouts/termiloop.holdout.json), [holdouts/dx-commander.holdout.json](holdouts/dx-commander.holdout.json) | The registered holdouts: what is held back, and what agreement means. They hold no state and are never edited. |
| [holdouts/LOCK.json](holdouts/LOCK.json) | The hash of each registration. |
| [holdouts/OPENED.json](holdouts/OPENED.json) | The record of openings: which case was judged, when, with which capture and which frozen model. Empty: the holdouts are untouched. |
| [fieldwork.js](fieldwork.js) | The tool: checks captures, checks the lock, compares. |

## The order of work

1. **Build and measure the antenna's geometry.** Draw the as-built model in Sommerwire from the tape measure, not
   from a preset as shipped. The presets and `models/DX Commander 16 radials.maa` are starting points; the
   TermiLoop presets say themselves that they are approximations. Save the model as a share link in a text file.
2. **Measure the parts that can be measured alone** (below), and put them in the model: the termination's own
   impedance as a load of type 3 ([validation/feed-network](../feed-network/README.md)).
3. **Capture** impedance and branch currents with the templates. Decide before any sweep which data are fit data
   and which belong to a holdout case.
4. **Adjust the model on fit data only.** The tool leaves every held-out band out of a fit comparison.
5. **Freeze the model** ([templates/model.freeze.json](templates/model.freeze.json)): the sha256 of its share-link
   file, and the captures it was adjusted to.
6. **Open each holdout case once**, with the frozen model, and add the opening to
   [holdouts/OPENED.json](holdouts/OPENED.json) in the same change as the capture (`compare` prints the entry).
   Report the outcome whatever it is.

## What to measure

### Impedance (capture kind `vna-s11`)

- Calibrate the analyser **at a known plane**, with a kit whose standard definitions are known, and measure a known
  device afterwards before connecting the antenna (`calibration.verification`).
- Save the **complex** sweep as the instrument writes it (Touchstone `.s1p`). SWR, |S11| or return loss alone are
  not accepted: they cannot be compared at a plane.
- **At least 3 sweeps**, the connection made again before each. Take the antenna down and put it up again at least
  once to learn what that changes; it is its own component of the uncertainty.
- Say where the plane is (`reference_plane`) in one of three ways:

| `transformer` | Meaning | Model source |
|---|---|---|
| `none` | The plane is at the wire terminals. | ratio 1 |
| `in-fixture` | The transformer, and anything else between the plane and the wire terminals, was measured as a two-port (`.s2p`, port 1 at the plane, port 2 at the wire terminals) and is named in `fixture`. The tool moves the **model** through it to the plane; measured data are never inverted or de-embedded numerically. | ratio 1 |
| `ideal-ratio-in-model` | The plane is on the feeder side of the real transformer and the model keeps its ideal ratio. Allowed, but the report says that a difference is then not attributable to the wires or to the transformer. | the ideal ratio |

A fixture two-port carries the differential quantities of one port pair. It adds or removes no common-mode path:
what the feed line's outside does must be drawn in the model as a wire and measured as a branch current. A real
transformer or choke is a multiport, and a solver element for it is deferred
([INTERFACE-PROPOSAL.md](../feed-network/INTERFACE-PROPOSAL.md)).

### The termination alone (TermiLoop)

Measure the terminating part by itself at its two leads, calibrated at the fixture, over the whole range, with
enough rows to follow any resonance. Import the `.s1p` in the app (Loads, type "Measured Z(f) table") and write the
plane into the table's reference-plane text. That is fit data for the part and no evidence about the antenna.

### Branch currents (capture kind `branch-current`)

- A **calibrated** probe whose transfer impedance is known over the band, and whose insertion impedance was measured
  and is small against the circuit where it sits. Closed around nothing it must read nothing; turned round on one
  conductor the phase must turn by 180° (`probe.balance_check`).
- Every branch is measured **together with the reference branch** on a second channel, so that what is recorded is
  a complex ratio. Magnitudes alone are accepted, and are then compared as magnitudes only.
- For each branch the capture gives the wire number in the as-built model, the distance of the probe from that wire's
  end 1 in metres, and which way the probe's arrow pointed (`sense`). The model current is taken at that place.
- **At least 3 repeats** per frequency and branch, the probe taken off and put back between them.
- The reduced table is `MHz,branch,repeat,ratio,phase_deg`: `ratio` is |I branch| / |I reference| as a plain number,
  `phase_deg` the phase of the branch minus the reference in degrees (e^{jωt}: a branch that leads is positive). The
  instrument's own files are kept beside it and named with their hashes.

| Antenna | Branches in the template | Why |
|---|---|---|
| TermiLoop | feed (reference); feed line on the antenna side and on the station side of the choke; termination; return run | The accuracy study found the drawn shield path decisive for the result. The shield current on both sides of the choke says whether the drawn path and the choke are what the model assumes. |
| DX Commander | feed conductor (reference); the base of each of the six elements; one radial; the feed line below the feed point | The elements share the feed and carry large currents off their own band. The study's model had 2.26, 0.71 and 0.52 times the feed current in three elements at 14.175 MHz: simulated figures that only arm currents can confirm or refute. |

In the shipped starting-point models the wires are: TermiLoop far-end preset, w1 fed run, w2 drawn shield path,
w4 return run, w5 far-end jumper with the termination; `models/DX Commander 16 radials.maa`, w10, w13, w14, w11, w15
and w12 the six elements from longest to shortest, w19 the feed conductor, w20 to w35 the radials. An as-built model
has its own numbering; the capture names the wires of the model it was compared with.

## Uncertainty

A capture declares an **expanded uncertainty (k = 2)** and the **standard uncertainties (k = 1)** it is made of, kept
apart, with how each was obtained (`uncertainty.basis`):

| Capture | Declared | Components |
|---|---|---|
| `vna-s11` | `gamma`: the radius, in the complex plane of the reflection coefficient, around each measured point | calibration residual, connector repeatability, installation repeatability, noise and drift |
| `branch-current` | `ratio_db` and `phase_deg` of the current ratio | probe transfer calibration, probe insertion, positioning along the wire, repeatability |

The tool refuses a capture whose declared uncertainty is smaller than twice the root sum of squares of its own
components, or smaller than the spread of its own repeats. It cannot check that the components are honest.

Soil constants, wire lengths and heights are **inputs of the model**, not part of the measurement. Their tolerance
is not folded into the measurement uncertainty: solve the as-built model at both ends of each tolerance, one at a
time, and report the range beside the comparison. The tool does not do this for you.

## Capture files

A capture is a JSON file beside the files it names. Copy a template, set `"status": "measured"`, give it its own
`id` and fill in every `null`; the `guide` in each template explains each field. A field that does not apply says so
and why. `check` lists everything that is missing or contradicts itself, and refuses:

- a file that is absent or whose sha256 is not the recorded one (the model, every raw file, the fixture, the table);
- fewer than 3 repeats, repeat sweeps on different frequency lists, a sweep that is not complex data;
- a fixture two-port that is not passive, a reflection coefficient above 1 (measured data are never repaired);
- an uncertainty that contradicts its components or its repeats;
- a holdout case that is not registered.

`"origin"` is `"instrument"` for a measurement. `"synthetic-self-test"` marks data computed from the solver to drive
the tool's own tests in a temporary directory: the same rules apply to it, and it is **never reported as
evidence**. The tool cannot tell an invented number from a measured one. What it can do is make a capture carry its
raw files, its calibration and its uncertainty budget, so that a reader can.

## Holdouts

For each antenna a frequency, a geometry and an installation are held back
([TermiLoop](holdouts/termiloop.holdout.json), [DX Commander](holdouts/dx-commander.holdout.json)):

| | TermiLoop | DX Commander |
|---|---|---|
| Frequency (in the fit installation) | 5.0 to 5.7, 17.6 to 18.6 and 24.4 to 25.4 MHz | 10.0 to 10.3, 17.9 to 18.3 and 24.7 to 25.2 MHz |
| Geometry | the choke at the second of two positions chosen beforehand | the radials at a second measured height, nothing else changed |
| Installation | put up again with the flat top at least 2 m higher or lower | put up again at a second position with other ground |

They were registered on 2026-11-29, before any measurement existed, and are **untouched**: the record of openings
is empty. The rules are in the registrations:

- No holdout capture and no row inside a held-out band is looked at before the model is frozen. `compare` leaves
  held-out bands out of every fit comparison and says how many rows it left out.
- A holdout capture is compared only with a freeze record that names the same model file by the same sha256 and
  does not list the capture among the fit data.
- A case is opened once. The opening goes into [holdouts/OPENED.json](holdouts/OPENED.json): antenna, case, date,
  the capture's id and the sha256 of the frozen model. From then on the case is fit data: `compare` refuses to judge
  another model on it, and calls a comparison with the same model a repeat.
- A registration is never edited, which is why it holds no state: [holdouts/LOCK.json](holdouts/LOCK.json) holds the
  hash of its content, and `compare` refuses to run when they differ.

**Agreement** is registered as: the complex reflection coefficient within the capture's declared expanded
uncertainty, and each complex current ratio within its declared uncertainty, at 95 % or more of the held-out
points. A model with measured feed-network data counts as an improvement over the ideal-component model only if
both its median reflection-coefficient distance and its largest current-ratio difference are smaller on the same
points. SWR, return-loss magnitude, gain and pattern figures are not criteria.

## The comparison

`compare` reads the model the capture names as the app reads it, solves it at measured frequencies only (measured
data are not interpolated; up to `--points` rows of a sweep, evenly chosen, default 41), and reports for each:

- `vna-s11`: measured and model impedance and reflection coefficient at the plane, their distance in the complex
  plane, and whether it is within the declared uncertainty;
- `branch-current`: measured and model ratio and phase, their difference in dB and degrees, and whether both are
  within the declared uncertainties.

The report carries the sha256 of the model file and of `engine.js`, the number of held-out rows left out, notes on
what limits the comparison, and a verdict in fixed words: `self-test: computed data, not a measurement and not
evidence`, `fit data: not a validation result`, or for a holdout the share of points inside or outside the
uncertainty against the registered 95 %.

## Limits

- Agreement at one plane and a few branch currents is not agreement of the radiated field. Nothing here measures
  gain, efficiency or pattern.
- The model current is constant over half a segment, so a probe position is resolved to that length.
- The fixture algebra is the differential mode of one port pair. Common-mode behaviour is compared through branch
  currents only.
- Linear interpolation of a fixture's S parameters between its rows needs rows dense enough for the fixture.
- A freeze fixes the model file. The solver that made a prediction is recorded by hash; compare a holdout with the
  solver version the freeze was made with, or say that it changed.
- The lock and the record of openings are files in this repository. The tool reads them and never writes them; it
  cannot stop anyone from changing the lock together with a registration, or from removing an opening. The
  repository's history is the record of that, and a reviewer has to look at it.
- The tool reads one registration per antenna. Once its cases are opened, a further holdout for the same antenna
  needs a new registration, and with it a change to this tool: that is not built. Until then the registered bands
  stay left out of fit comparisons, also after they were opened.
