I’m working on making a script for “re-BIDSifying” the data imposing the compensation grade to 0 for experimental data. Now I’m running into a strange behavior that I think can be summed up with the following MWE:
from pathlib import Path
import mne
from mne_bids import (
BIDSPath,
read_raw_bids,
write_raw_bids
)
old_bids_root = Path("/home/.../BIDS")
new_bids_root = Path("/home/.../BIDS_for_MNE-BIDS-Pipeline")
target_grade = 0
bp = BIDSPath(
root=old_bids_root,
subject="063",
session="01",
task="rest",
run="01",
datatype="meg"
)
raw = read_raw_bids(bids_path=bp, verbose=False)
print(f"Initial compensation grade: {raw.compensation_grade}")
raw.apply_gradient_compensation(target_grade)
new_bp = bp.copy().update(root=new_bids_root)
write_raw_bids(
raw,
bids_path=new_bp,
overwrite=True,
verbose=False
)
new_raw = mne.io.read_raw_ctf(new_bp.fpath, preload=False)
print(f" → written {new_bp.fpath} with compensation grade {new_raw.compensation_grade}")
(NOTE: I created a new bids_path to go around the issue signalled here )
But strangely the compensation grade of the new raw is still 3:
Initial compensation grade: 3
Compensator constructed to change 3 → 0
...
Current compensation grade : 3
→ written /home/.../BIDS_for_MNE-BIDS-Pipeline/sub-063/ses-01/meg/sub-063_ses-01_task-rest_run-01_meg.ds with compensation grade 3
In the sidecar json:
"SoftwareFilters": {
"SpatialCompensation": {
"GradientOrder": 0
}
}
Why this happens? I saw I could impose in write_raw_bids to have format = ‘FIF’ and that would solve the issue, but I would prefer to keep .ds