Skip to content

Commit ba5fcd0

Browse files
committed
Adding provenance record for the JSON sidecar
1 parent 87f562c commit ba5fcd0

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

examples/dcm2niix_4/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ We use:
3030
* the `GeneratedBy` field of JSON sidecar, already existing in the BIDS specification
3131
* modality agnostic files inside the `prov/` directory
3232

33+
Note that we assume that both `sub-02_T1w.nii` and its JSON sidecar `sub-02_T1w.json` were generated by the same Activity.
34+
3335
## Provenance merge
3436

3537
The python script `code/merge_prov.py` aims at merging all provenance records into one JSON-LD graph.

examples/dcm2niix_4/code/merge_prov.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,31 @@
7070
with open(sidecar_file, encoding = 'utf-8') as file:
7171
data = json.load(file)
7272
if 'GeneratedBy' in data:
73-
activity_id = data['GeneratedBy']
73+
74+
# Get activity data and id
75+
activity_data = data['GeneratedBy']
76+
activity_id = ""
77+
if "Id" in activity_data:
78+
activity_id = activity_data['Id']
79+
else:
80+
activity_id = activity_data
81+
82+
# Provenance for the data file
7483
for data_file in data_files:
75-
base_provenance['Records']['Entities'].append({
76-
"Id": f"bids::{data_file}",
84+
base_provenance['Records']['Entities'].append(
85+
{
86+
"Id": f"bids::{data_file}",
87+
"GeneratedBy": activity_data
88+
}
89+
)
90+
91+
# Provenance for the sidecar
92+
base_provenance['Records']['Entities'].append(
93+
{
94+
"Id": f"bids::{sidecar_filename}",
7795
"GeneratedBy": activity_id
78-
})
96+
}
97+
)
7998

8099
# Write jsonld
81100
with open('prov/merged/prov-dcm2niix.prov.jsonld', 'w', encoding = 'utf-8') as file:

examples/dcm2niix_4/prov/merged/prov-dcm2niix.prov.jsonld

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
{
3333
"Id": "bids::sub-02/anat/sub-02_T1w.nii",
3434
"GeneratedBy": "bids::prov/#conversion-00f3a18f"
35+
},
36+
{
37+
"Id": "bids::sub-02/anat/sub-02_T1w.json",
38+
"GeneratedBy": "bids::prov/#conversion-00f3a18f"
3539
}
3640
]
3741
},
8.38 KB
Loading

0 commit comments

Comments
 (0)