===============
Data Structures
===============
Data flows through the pipeline as a sequence of typed structures.
This page documents each type and its array shapes.
.. mermaid::
graph LR
SD[ScanData
raw 5D counts] --> CL[CalibrationLoadFull
gamma, Trec per C,R,A]
SD --> PD[PreparedData
ref_data, ON indices]
CL --> AR[AtmosphereResult
tr_s, tr_i, PWV]
CL --> CR[CalibrationResult]
AR --> CR
PD --> CR[CalibrationResult
spectra, Tsys, flags]
ScanData
--------
Raw observation data for one scan, loaded from L0 Zarr.
- ``data: Vec>`` — per-subscan ``[C, D, R, A]`` arrays
(stored as ``Vec`` instead of a single 5D array to avoid contiguous
allocation of >1 GB)
- ``sobsmode: Vec`` — mode per subscan (ON, OFF, OTF-ON, etc.)
- ``mjd, exptime, elevation, azimuth, pamb, tamb`` — per-subscan metadata
- ``signal_freq, image_freq, freq_res, freq_off, ref_channel`` — frequency info
- ``otf_lon, otf_lat: Option>`` — OTF coordinates (if available)
- ``scan_number, source, instmode, line, rest_freq_hz, velocity_source_kms``
**Source:** ``cal-core/src/scan.rs``
CalibrationSnapshot
-------------------
Raw HOT/COLD calibration data from the nearest calibration scan.
- ``data: Vec>`` — per-subscan ``[C, D, R, A]``
- ``sobsmode: Vec`` — HOT, COLD, COL, SKY, ZERO
- ``thot, tcold: Array1`` — physical load temperatures (K)
- ``load_temp_sig, load_temp_img: Option<...>`` — per-channel load
RJ temperatures (if LOAD_TEMP_ARRAY available)
**Source:** ``cal-core/src/scan.rs``
CalibrationLoad (Single Pixel)
------------------------------
Resolved calibration data for one pixel ``(r, a)``:
- ``hot_counts, cold_counts: Array1`` — ``[C]``
- ``signal_freqs, image_freqs: Array1`` — ``[C]`` Hz
- ``gamma, t_rec_prime, t_rec_ssb: Array1`` — ``[C]``
- ``bad_channels: Array1`` — ``[C]``
- ``ta_prime_hot, ta_prime_cold: Array1`` — ``[C]`` primed temps
- ``a_signal, a_image: Array1`` — ``[C]`` sky coupling coefficients
- ``gsxs, gixi: Array1`` — ``[C]`` sideband gain products
- ``famb, airmass, t_hot, t_cold, t_amb, p_amb: f64`` — scalars
**Source:** ``cal-core/src/scan.rs``
CalibrationLoadFull (All Pixels)
---------------------------------
Same quantities as ``CalibrationLoad`` but with ``[C, R, A]`` arrays,
enabling vectorized calibration without per-pixel loops. Provides
``extract_pixel(r, a) → CalibrationLoad`` for backward compatibility.
**Source:** ``cal-core/src/scan.rs``
PreparedData
------------
Mode-specific ON/OFF pairing result:
- ``ref_data: Array4`` — ``[C, R, A, S_on]`` reference spectra
- ``on_subscan_indices: Vec`` — indices into ``ScanData.data``
for ON subscans (zero-copy access)
- ``t_int: Array1`` — ``[S_on]`` integration times
**Source:** ``cal-core/src/modes/prepare.rs``
CalibrationResult
-----------------
Final calibration output for one scan:
- ``spectra: Array5`` — ``[C, D, R, A, S]`` :math:`T_A^*` (K)
- ``t_sys: Array4`` — ``[C, R, A, S]``
- ``t_int: Array1`` — ``[S]``
- ``t_rec_ssb, gamma: Array3`` — ``[C, R, A]``
- ``tau_signal, tau_image: Array1`` — ``[C]``
- ``t_sky: Array3`` — ``[C, R, A]``
- ``flags: Array5`` — ``[C, D, R, A, S]``
- ``signal_freqs, image_freqs: Array1`` — ``[C]``
- ``otf_lon, otf_lat, otf_airmass: Option>`` — ``[D, S]``
- ``pwv: f64`` — fitted PWV (mm)
- Plus metadata: scan_number, source, arrays, pixels, strategies
**Source:** ``cal-core/src/scan.rs``