---
jupytext:
  text_representation:
    format_name: myst
kernelspec:
  display_name: Python 3 (ipykernel)
  language: python
  name: python3
---

# Data provenance

{.lead}
Data provenance is the record of where data came from and what was done to it. This page covers what to record with a recording, and how to keep that record in Nominal beside the data.

{download}`Download this page as a notebook <data-provenance.md>` to run its code in JupyterLab. [Running the notebooks](notebooks/running.md) explains how to set it up.

## Why record it

A result you can't trace back to its data, and the steps applied to it, is hard to check or repeat. The FAIR principles, written for scientific data, ask that metadata record detailed provenance, and that data be described with rich metadata.[^fair] Traceability is the other half: from a result back to the recording, the software and the steps, and from a unit forward to every recording of it.

## What to record

For a recording of a test, keep:

- **The source.** Which instrument or sensor produced each channel, its {gloss}`calibration`, and the system's configuration for the run.
- **The units.** Each channel's {gloss}`engineering units`, stored with the data.
- **The software.** The version of the program that wrote the data, and of any that changed it.
- **The steps.** Each change made to the data after it was recorded, such as a filter or a unit conversion, in order.
- **The unit under test.** Which unit the recording tested, so you can trace from a unit to its data and back. See {gloss}`Genealogy`.

## A manifest

This code builds a manifest, a small JSON document with those items, for a made-up recording. It hashes the file's bytes with SHA-256, so you can later check that a file is the one the manifest describes:

```{code-cell} ipython3
import hashlib
import json
from datetime import datetime, timezone

import pandas as pd

recording = (
    "timestamp,temperature\n"
    "2026-01-01T12:00:00Z,21.0\n"
    "2026-01-01T12:00:01Z,21.1\n"
    "2026-01-01T12:00:02Z,21.1\n"
).encode()

manifest = {
    "file": "oven-0042-soak.csv",
    "sha256": hashlib.sha256(recording).hexdigest(),
    "recorded_at": datetime(2026, 1, 1, 12, tzinfo=timezone.utc).isoformat(),
    "unit_under_test": {"serial": "0042", "type": "oven"},
    "source": {
        "channel": "temperature",
        "sensor": "thermocouple t_1",
        "calibrated": "2025-12-01",
    },
    "channels": {
        "temperature": {"unit": "Cel", "description": "Oven air temperature"}
    },
    "software": {"logger": "soak-logger 1.4.2"},
    "steps": ["none: the file is as recorded"],
}
print(json.dumps(manifest, indent=2))
```

```{code-cell} ipython3
# Later: check that a file is the one the manifest describes
file_hash = hashlib.sha256(recording).hexdigest()
print("matches the manifest:", file_hash == manifest["sha256"])
pd.DataFrame(manifest["channels"]).T
```

The names and values above are made up. The point is that the manifest travels with the file, and that it records each step as it happens, since a step you didn't record can't be recovered afterwards.

## In Nominal

A Nominal dataset carries properties, key-value pairs such as `"serial"="ABADCAFE"`, and labels.[^nominal-data-model] A run names a span of time for one test, and references data rather than copying it.[^nominal-runs] Store the manifest's items as properties, so they stay with the data and you can search by them. This code creates a dataset and a run from the manifest:

```python
from datetime import datetime, timedelta, timezone

from nominal.core import ChannelDataType, NominalClient

client = NominalClient.from_profile("default")
start = datetime(2026, 1, 1, 12, tzinfo=timezone.utc)

dataset = client.create_dataset(
    "Oven 0042 soak",
    properties={
        "sha256": manifest["sha256"],
        "serial": manifest["unit_under_test"]["serial"],
        "logger": manifest["software"]["logger"],
        "calibrated": manifest["source"]["calibrated"],
    },
    labels=["soak"],
)
dataset.add_tabular_data("oven-0042-soak.csv", timestamp_column="timestamp", timestamp_type="iso_8601")
dataset.add_channel("temperature", ChannelDataType.DOUBLE, unit="Cel", description="Oven air temperature")

run = client.create_run(
    "Oven 0042 soak",
    start=start,
    end=start + timedelta(seconds=2),
    properties={"serial": manifest["unit_under_test"]["serial"]},
)
```

The client's `create_dataset`, `add_channel` and `create_run` take the properties, labels and units used above.[^nominal-client]

## Further reading

- [Engineering data and warehousing](engineering-data.md), on file formats and finding data later.
- [Measurement quality](measurement-quality.md), on calibration.
- M. D. Wilkinson et al., [The FAIR Guiding Principles for scientific data management and stewardship](https://www.nature.com/articles/sdata201618).

## References

[^fair]: M. D. Wilkinson et al., ["The FAIR Guiding Principles for scientific data management and stewardship"](https://www.nature.com/articles/sdata201618), *Scientific Data* 3, 160018, 2016. Retrieved 2026-11-24.
[^nominal-data-model]: Nominal, ["Data model core concepts"](https://dev.nominal.io/platform/data-model/). Retrieved 2026-11-24.
[^nominal-runs]: Nominal, ["Runs"](https://dev.nominal.io/python/guides/runs/), Python client guide. Retrieved 2026-11-24.
[^nominal-client]: Nominal, `NominalClient.create_dataset`, `NominalClient.create_run` and `Dataset.add_channel` in the [nominal](https://pypi.org/project/nominal/) Python client, version 1.186.0. Retrieved 2026-11-30.
