Last active
June 12, 2020 20:46
-
-
Save oesteban/9d51d93bf6ecff8d68f3ec1bdadd4ac2 to your computer and use it in GitHub Desktop.
fixing slicetiming in all sidecar jsons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
from glob import glob | |
import numpy as np | |
import json | |
import datalad | |
files = glob('sub-*/func/*_bold.json') | |
def get_parser(): | |
"""Build parser object""" | |
from argparse import ArgumentParser | |
from argparse import RawTextHelpFormatter | |
parser = ArgumentParser(description='Fix SliceTiming', | |
formatter_class=RawTextHelpFormatter) | |
parser.add_argument('file_list', action='store', nargs='+', | |
help='list of files to be updated') | |
return parser | |
def main(): | |
"""Entry point""" | |
opts = get_parser().parse_args() | |
for f in opts.file_list: | |
with open(f) as fh: | |
sidecar = json.load(fh) | |
sidecar["SliceTiming"] = (np.array(sidecar["SliceTiming"], dtype=float) * 1.e-3).tolist() | |
# As per Yaric, it is better to just remove the file before writing. | |
os.remove(f) | |
with open(f, 'w') as fh: | |
json.dump(sidecar, fh, indent=4) | |
datalad.utils.rotree(f, ro=True, chmod_files=True) | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment