capa.calibration¶
Tune-procedure artifacts (the heater-setpoint → delivered-flux table
written by the heat-flux tune procedure). Distinct from
:mod:capa.channels.calibration, which is the channel-level
raw-to-engineering-unit transform.
Narrative guides:
- Calibration overview — the two layers ("channel calibration" vs "tune artifact") and where each lives.
- Calibration sets — on-disk format.
- Tuning workflow.
- Heat-flux tune procedure.
- Tune artifacts.
capa.calibration ¶
Operational tune-result artifacts.
This package holds artifact models that record the outcome of a
calibration / tune procedure — distinct from the channel-level
:class:~capa.channels.calibration.Calibration family, which models
raw-acquisition to engineering-unit transforms attached to a
:class:~capa.channels.spec.ChannelSpec.
The first member is :class:~capa.calibration.tune_artifact.HeatFluxTuneArtifact,
written by capa.builtin.heat_flux_tune. A heater-setpoint to
delivered-flux mapping is not a channel calibration (there is no
ChannelSpec whose raw unit is "commanded °C" and whose derived unit
is "kW/m²"), so it lives in its own model with its own storage path.
HeatFluxTuneArtifact ¶
Bases: BaseModel
Result of one tune session.
The artifact is rig-specific (rig, heater_device,
heater_setpoint_channel, heater_pv_channel, flux_channel)
so a downstream consumer can refuse to apply it on a different rig.
gauge_calibration_ref links to the wire-side V→kW/m² calibration
that was active during the tune; if that changes, the artifact's
setpoints no longer correspond to the same delivered flux.
points is ordered by acceptance, which is the same as the order
of the operator-supplied targets_kw_m2 (ascending in the typical
daily-tune workflow). A partial session that aborted on target #N of
M still produces an artifact with N points — :func:save_artifact
is called after each accepted point.
setpoint_for_target ¶
Linearly interpolate target_kw_m2 against accepted points.
Returns None when the artifact has no points or when the
target falls outside the bracket of accepted targets and would
require extrapolation. Extrapolation is refused because a
flux↔setpoint curve outside the brackets is not characterised
by this session.
Used by the experiment-method UI to pre-populate
HeaterProgram.heater_setpoint_c from
HeaterProgram.target_heat_flux_kw_m2.
Source code in src/capa/calibration/tune_artifact.py
local_df_dt ¶
Local d(flux)/d(setpoint) around target_kw_m2, kW/m² per °C.
Returned as the secant slope of the bracketing accepted points.
None when fewer than two points are accepted, or when the
target sits outside any bracket. Used as the step-size prior for
the first iteration of a future tune session.
Source code in src/capa/calibration/tune_artifact.py
HeatFluxTunePoint ¶
Bases: BaseModel
One accepted (target flux, heater setpoint) point in a tune session.
All measured fields are reported in the channel's calibrated units
(kW/m² for flux, °C for the heater process variable). soak_s is
the total dwell from the iteration's setpoint command to acceptance.
TuneArtifactError ¶
Bases: CapaError
Raised when a tune artifact cannot be read, written, or parsed.
Distinct from :class:~capa.core.errors.CalibrationError (which the
channel-calibration family raises) so a tune-artifact problem is
recognisable as an operational-tune issue rather than a per-channel
calibration issue.
load_artifact ¶
Read and validate a single tune artifact file.
Source code in src/capa/calibration/tune_artifact.py
load_latest ¶
Return the artifact pointed to by <directory>/latest.toml.
Returns None when the directory does not exist, when
latest.toml is missing, or when its id pointer references a
file that no longer exists. Any parse failure on the pointed-at
file raises :class:TuneArtifactError — a corrupt artifact is
different from an absent one.
Source code in src/capa/calibration/tune_artifact.py
save_artifact ¶
Persist artifact under directory and update latest.toml.
Writes <directory>/<artifact.id>.toml. Refuses to overwrite an
existing file with that id — a clash means the caller picked a
non-unique id and the operator deserves to see it rather than have
yesterday's tune silently clobbered.
Updates latest.toml to point at the new id. If latest.toml
previously pointed at a different artifact, its target file is
copied to <old-id>.toml.bak-<YYYY-MM-DD> first; that file is
not removed (the on-disk record stays available under its own
name, the .bak-… copy is the audit ledger of "this was the
latest on this date").
Source code in src/capa/calibration/tune_artifact.py
to_toml ¶
Serialize an artifact to TOML text.
datetime is preserved as a native TOML datetime via tomli_w,
so a round-trip through :func:from_toml reconstructs an equal
object. None-valued optional fields are emitted as missing keys
rather than as empty strings.