DRMHB / examples /README.md
AlejandroGZ's picture
v2.6 generator update
e776436
|
Raw History Blame Contribute Delete
6.74 kB
# DRMHB conversion and evaluation examples
Use Python 3.12 and `vibframe-anndata==0.3.0`. Run from the repository root.
These examples explicitly request complete annotations; the package itself
keeps ground-truth import disabled by default.
```bash
python -m pip install -r examples/requirements.txt
python examples/01_create_featureless_anndata.py data/DRMHB-compact.vibframe.zip derived/DRMHB-compact.v0.3.0.raw.h5ad
python examples/02_inspect_anndata.py derived/DRMHB-compact.v0.3.0.raw.h5ad --waveform-details
python examples/03_add_features.py derived/DRMHB-compact.v0.3.0.raw.h5ad derived/DRMHB-compact.v0.3.0.features.h5ad
```
## 01 — Import once
Accepts a ZIP or extracted VibFrame. The base is featureless: `X` has zero
columns; raw waveforms, spectra, tachometers, identities and metadata remain
available for later features. The default is `float32`, 8 MiB raw blocks,
`scope=all`, strict missing truth and unchanged uncompressed raw HDF5 arrays.
`--ground-truth-scope snapshot` selects the legacy footprint; `none` (or
`--without-ground-truth`) excludes evaluation labels. `--max-sidecar-mib 512`
limits original encoded sidecars, not total memory. `--block-size-mib` and
`--dtype` are explicit. Existing destinations require `--overwrite`; inputs
cannot be used as outputs.
No feature is computed from `trends.parquet` or from construction/diagnostic
labels. The published dataset itself contains no scalar trends.
## 02 — Inspect without loading multi-GiB raw signals
The inspector uses `h5py` group metadata, small `obs`/`var`/package metadata and
public ground-truth accessors. It never calls `anndata.read_h5ad(backed="r")`
as a blanket out-of-core solution: that mode does not make all `obsm`/`uns`
objects lazy. `--waveform-details` expands annotations only. `--verify-hashes`
reads one original annotation file at a time and checks its SHA-256.
## 03 — Add the reference features
The thirteen feature requests remain the same as in the published EDA:
velocity/acceleration RMS, subsynchronous/1X/low-harmonic bands, 1X/2X/BPFO/BPFI
amplitudes, VPF-family RMS, and waveform RMS/crest factor/kurtosis.
For the current 2.6.0 fleet they materialized 468 machine/source-scoped columns.
Each machine populates its relevant descriptors; structural NaNs are not zeros.
The EDA constructs a common logical descriptor matrix without averaging different
machines. Preserve `var` units, processing mode, point and algorithm/options
when aligning columns. Do not match columns by short display name alone.
`--block-rows 256` controls feature block size. `--features-config FILE.yaml`
accepts an alternative package feature configuration. The original VibFrame
is not reopened. Dimension counts and original-annotation manifest identities
are compared before and after feature generation.
## 04 — Upgrade existing H5ADs
```bash
python examples/04_add_complete_ground_truth.py \
derived/DRMHB-compact.v0.3.0.no-truth.h5ad data/DRMHB-compact.vibframe.zip \
derived/DRMHB-compact.v0.3.0.enriched.h5ad
```
Uses `add_ground_truth_to_h5ad`. It preserves signals and features and creates a
transactional disk copy. Supply the matching source set and retain `obs.source`,
`obs.machine` and integer `obs.snap_t`. Roughly one extra H5AD of free disk is
needed temporarily. Source-name/path collisions must not be repaired by guessing.
Legacy capture-time companions are not populated retrospectively: reimport raw
signals to obtain those arrays. Per-waveform crop offsets remain available from
original and aligned waveform truth.
## 05 — Read originals and DiagGT
```bash
python examples/05_read_evaluation.py derived/DRMHB-compact.v0.3.0.features.h5ad
python examples/05_read_evaluation.py derived/DRMHB-compact.v0.3.0.features.h5ad \
--path ground-truth/observations.parquet
python examples/05_read_evaluation.py derived/DRMHB-compact.v0.3.0.features.h5ad \
--export derived/recovered-evaluation
```
Use the exact path from the printed inventory; the layout is not assumed.
Use `--source SOURCE_ID` when a relative path occurs in several sources.
`read_evaluation_table()` returns Arrow types; `read_evaluation_json()` returns
parsed JSON; `read_evaluation_file()` returns the exact original bytes.
Export refuses overwrites and retains dataset-wide originals, even for a sliced
AnnData. No implicit DiagGT interval-to-snapshot labelling is performed.
## Complete information and model input
`obsm['ground_truth']` and `obsm['waveform_ground_truth']` follow `obs_names`.
The byte archive in `uns['vibframe_evaluation']` is dataset-wide. `snap_t` is the
snapshot key in integer microseconds UTC; raw capture `t` may include a crop
offset. Waveform bindings include source/machine/point and supplied mode identity.
Unknown sidecars/fields are retained instead of silently discarded.
For normality learning, fit scaling, missing-value rules and models only on
calibration. Set thresholds on normal holdout. Evaluate on the future stream
using timestamps. Faults, severities, OOD, nuisance and latent physical state
are targets/audit fields, not automatic inputs. Declare explicitly any use of
regime or RPM. Keep a separately generated controls dataset in a separate H5AD;
controls are in `data/DRMHB-compact-controls.vibframe.zip`, separate from the
current longitudinal ZIP. Use a distinct output basename for their H5AD.
## Resources and verification
No raw compression settings or VibFrame bytes are changed. The current complete 0.3.0 base and feature H5ADs measure 8.169 and
8.265 GiB respectively; both retain 97 original files (26,874,052 bytes).
Verify local derivatives with `python tools/audit_dataset.py --deep`. Metadata decoding also consumes RAM, so the raw block size and
512 MiB encoded-sidecar budget are not process-memory caps.
For a quick end-to-end check using the smaller controls ZIP:
```bash
python examples/01_create_featureless_anndata.py \
data/DRMHB-compact-controls.vibframe.zip derived/DRMHB-compact-controls.v0.3.0.raw.h5ad
python examples/02_inspect_anndata.py \
derived/DRMHB-compact-controls.v0.3.0.raw.h5ad --verify-hashes
python examples/03_add_features.py \
derived/DRMHB-compact-controls.v0.3.0.raw.h5ad \
derived/DRMHB-compact-controls.v0.3.0.features.h5ad
python examples/05_read_evaluation.py \
derived/DRMHB-compact-controls.v0.3.0.features.h5ad
```
To exercise example 04, first create an H5AD with `--without-ground-truth`
from that same controls ZIP, then pass it and the ZIP to example 04. These
commands validate the conversion workflow without regenerating the campaign.
Package documentation: https://413hq.github.io/vibframe-anndata-docs/0.3.0/
Ground truth guide: https://413hq.github.io/vibframe-anndata-docs/0.3.0/guides/ground-truth/