-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrect_PED.py
More file actions
34 lines (27 loc) · 1.1 KB
/
correct_PED.py
File metadata and controls
34 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
# Time-stamp: <02-12-2025 m.utrosa@bcbl.eu>
import json
from bids import BIDSLayout
from pathlib import Path
bids_root = "/home/mutrosa/Documents/projects/select_fMRI/data_MRI/sourcedata/raw"
# Initialize BIDS layout
layout = BIDSLayout(bids_root, validate=False)
# Get json files of single-band reference images
sbref_files = layout.get(suffix='sbref', extension='.json', return_type='filename')
print(f"Found {len(sbref_files)} sbref files.")
for sbref_path in sbref_files:
# Identify the run number from file metadata
entities = layout.parse_file_entities(sbref_path)
run = entities.get("run", None)
if run != "02" and run != 2:
continue
with open(sbref_path, 'r') as f:
meta = json.load(f)
# Modify PED only if it is exactly "j-"
if meta.get("PhaseEncodingDirection") == "j-":
meta["PhaseEncodingDirection"] = "i"
with open(sbref_path, 'w') as f:
json.dump(meta, f, indent=4)
print(f"Updated PED in: {sbref_path}")
else:
print(f"Skipping {sbref_path}: PED is {meta.get('PhaseEncodingDirection')}")