provenance
lacuna.core.provenance
¶
Provenance tracking utilities for reproducibility.
Functions for recording and managing transformation history.
TransformationRecord
dataclass
¶
Record of a spatial transformation operation.
Attributes: source_space: Source coordinate space identifier (e.g., 'MNI152NLin6Asym') source_resolution: Source resolution in mm target_space: Target coordinate space identifier target_resolution: Target resolution in mm method: Transformation method (e.g., 'nitransforms') interpolation: Interpolation method used (e.g., 'linear', 'nearest') timestamp: ISO 8601 timestamp of transformation rationale: Optional explanation for transformation strategy choice transform_file: Optional path/identifier of transform file used
Source code in src/lacuna/core/provenance.py
to_dict()
¶
Convert to dictionary for provenance tracking.
Source code in src/lacuna/core/provenance.py
create_provenance_record(function, parameters, version, output_space=None)
¶
Create a provenance record for a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
str
|
Fully qualified function name (e.g., 'lacuna.analysis.RegionalDamage'). |
required |
parameters
|
dict
|
Function parameters (must be JSON-serializable). |
required |
version
|
str
|
Package version at time of execution. |
required |
output_space
|
str
|
Resulting coordinate space (if spatial operation). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Provenance record with function, parameters, timestamp, version. |
Raises:
| Type | Description |
|---|---|
ProvenanceError
|
If parameters are not JSON-serializable. |
Examples:
>>> record = create_provenance_record(
... function="lacuna.analysis.RegionalDamage",
... parameters={"parcel_names": ["schaefer2018parcels100networks7"]},
... version="0.1.0",
... )
>>> record['function']
'lacuna.analysis.RegionalDamage'
Source code in src/lacuna/core/provenance.py
merge_provenance(base_provenance, new_provenance)
¶
Merge two provenance lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_provenance
|
list
|
Base provenance history. |
required |
new_provenance
|
list
|
New provenance to append. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Merged provenance list (ordered chronologically). |
Source code in src/lacuna/core/provenance.py
validate_provenance_record(record)
¶
Validate a provenance record structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict
|
Provenance record to validate. |
required |
Raises:
| Type | Description |
|---|---|
ProvenanceError
|
If record structure is invalid. |