Skip to content
Skip to Content

Bring your own data

Any table that has the shape of a normalized schema enters the engine without code, through cohortix-data.

The data pipeline is a separate program, cohortix-data. It meets the engine only through versioned files: normalized Parquet tables and a data manifest, data-manifest.toml, that lists each table with its schema, source, licence, restriction and BLAKE3 fingerprint. A scenario reads the manifest named in data.manifest.

Any table you hold (census, HDSS, PMA, MICS, your own estimates) enters the engine once it has the shape of a normalized schema. The format is the contract, not the source.

Register a table

  1. Pick the schema and lay your table out with its columns. The published schemas are in schemas/normalized/<id>/v1.toml; an unknown --schema lists the known ids. Write it as CSV with a header row (an empty field is missing) or as Parquet. Extra columns are ignored.
  2. Say where it comes from: --source, --licence and --restriction are required. Use --restriction restricted for data that must never leave your machine, such as DHS or HDSS microdata: no value of the table is then printed in any message.
  3. Run register. Every problem is reported at once. Fix them and run again; nothing is written until the table passes.

The repository has a synthetic HDSS mortality table to try it with:

Terminal
cp crates/cohortix-data/tests/fixtures/register/hdss_mortality.csv /tmp/
cohortix-data register /tmp/hdss_mortality.csv \
    --schema rate.hazard --source "HDSS synthetic" --licence CC0-1.0 --restriction open
Output
hdss_mortality: converted /tmp/hdss_mortality.csv to the normalized Parquet table /tmp/hdss_mortality.parquet
hdss_mortality: registered /tmp/hdss_mortality.parquet (parquet, schema [email protected], 5 rows, blake3 311bda24...) in /tmp/data-manifest.toml

A CSV is converted into a normalized Parquet table beside the manifest, because the engine reads Parquet only; the same CSV always gives the same bytes. Had the column age_lo been called age_low, the command would have stopped with:

Standard error
error[E8037]: column `age_lo` of schema [email protected] (int32, unit age_year) is missing from the table
  = fix: Add the column `age_lo`, or rename the column that holds it.
error[E8038]: column `age_low` is not declared by schema [email protected]
  = fix: Rename it to the missing schema column it holds, or remove it.

Your own layout

When your table has its own column names, extra rows, other age bands or probabilities instead of rates, describe the conversion in a pipeline.toml and run it with cohortix-data run, without code. Five generic steps sit between reading the CSV and writing the normalized table:

StepWhat it does
rename_columnsRenames columns to the schema's names and sets constant columns.
filter_valuesKeeps or drops rows by declared values.
probability_to_hazardTurns a probability q over dt years into a hazard per year, −ln(1 − q)/dt: the exact inverse of the kernel's conversion.
split_agesSplits age bands into narrower bands, assuming a constant hazard within each band.
group_agesGroups age bands into wider ones, weighting rates by exposure.

The other commands

CommandWhat it does
cohortix-data run <PIPELINE>Runs a pipeline file. Steps whose fingerprint changed execute, the others come from the cache, then the output folder is replaced as a whole.
cohortix-data status <PIPELINE>Shows each step's cache state (new, fresh or stale); nothing runs.
cohortix-data manifest <MANIFEST>Lists the entries of a manifest and checks each table still matches its fingerprint.

Every pipeline error is an E8xxx diagnostic with a fix; each has a page under errors.

Survey data stays with you

No survey data is stored in the cohortix repository or used in its continuous integration. DHS microdata is restricted: register with the DHS Program, obtain access to the surveys you need, then point the pipeline at your own copy.

On this page

You are reading the docs for 0.1. Keys can change between versions: use the version that matches cohortix --version.