Compile Dcm2Bids configuration files into a single config file.
Project description
compile-dcm2bids-config
Combine dcm2bids
config files into a single config file while preserving the integrity of each separate config file's various IntendedFor
fields.
Usage
$ compile-dcm2bids-config --help
usage: compile-dcm2bids-config [-h] [-o OUT_FILE] [-v] in_file [in_file ...]
Combine multiple dcm2bids config files into a single config file.
positional arguments:
in_file The JSON config files to combine
optional arguments:
-h, --help show this help message and exit
-o OUT_FILE, --out-file OUT_FILE
The file to write the combined config file to. If not specified
outputs are written to stdout.
-v, --version show program's version number and exit
Getting Started
Suppose you have two config files:
example/config1.json
:
{
"descriptions": [
{
"dataType": "anat",
"modalityLabel": "SWI",
"criteria": {
"SeriesDescription": "*SWI*"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-4*"
},
"IntendedFor": 0
}
]
}
example/config2.json
:
{
"descriptions": [
{
"dataType": "dwi",
"modalityLabel": "dwi",
"criteria": {
"SeriesDescription": "*DWI*"
}
},
{
"dataType": "anat",
"modalityLabel": "SWI",
"criteria": {
"SeriesDescription": "*SWI*"
}
},
{
"id": "my-func",
"dataType": "func",
"modalityLabel": "bold",
"customLabels": "task-rest",
"criteria": {
"SeriesDescription": "rs_fMRI"
},
"sidecarChanges": {
"SeriesDescription": "rsfMRI"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-3*"
},
"IntendedFor": [0, "my-func"]
}
]
}
Then we can combine the two using the following command (outputs are written to stdout by default):
$ compile-dcm2bids-config example/config1.json example/config2.json
{
"descriptions": [
{
"dataType": "anat",
"modalityLabel": "SWI",
"criteria": {
"SeriesDescription": "*SWI*"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-4*"
},
"IntendedFor": 0
},
{
"dataType": "dwi",
"modalityLabel": "dwi",
"criteria": {
"SeriesDescription": "*DWI*"
}
},
{
"dataType": "anat",
"modalityLabel": "SWI",
"criteria": {
"SeriesDescription": "*SWI*"
}
},
{
"id": "my-func",
"dataType": "func",
"modalityLabel": "bold",
"customLabels": "task-rest",
"criteria": {
"SeriesDescription": "rs_fMRI"
},
"sidecarChanges": {
"SeriesDescription": "rsfMRI"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-3*"
},
"IntendedFor": [
2,
"my-func"
]
}
]
}
Notice that the IntendedFor
fields have been updated appropriately.
Python API
You can also use this tool from within python:
import json
from pathlib import Path
from pprint import pp
from compile_dcm2bids_config import combine_config
config1 = json.loads(Path("example/config1.json").read_text())
config2 = json.loads(Path("example/config2.json").read_text())
all_together = combine_config([config1, config2])
pp(all_together)
The result being:
{'descriptions': [{'dataType': 'anat',
'modalityLabel': 'SWI',
'criteria': {'SeriesDescription': '*SWI*'}},
{'dataType': 'fmap',
'modalityLabel': 'fmap',
'criteria': {'SidecarFilename': '*echo-4*'},
'IntendedFor': 0},
{'dataType': 'dwi',
'modalityLabel': 'dwi',
'criteria': {'SeriesDescription': '*DWI*'}},
{'dataType': 'anat',
'modalityLabel': 'SWI',
'criteria': {'SeriesDescription': '*SWI*'}},
{'id': 'my-func',
'dataType': 'func',
'modalityLabel': 'bold',
'customLabels': 'task-rest',
'criteria': {'SeriesDescription': 'rs_fMRI'},
'sidecarChanges': {'SeriesDescription': 'rsfMRI'}},
{'dataType': 'fmap',
'modalityLabel': 'fmap',
'criteria': {'SidecarFilename': '*echo-3*'},
'IntendedFor': [2, 'my-func']}]}
Contributing
- Have or install a recent version of
poetry
(version >= 1.1) - Fork the repo
- Setup a virtual environment (however you prefer)
- Run
poetry install
- Run
pre-commit install
- Add your changes (adding/updating tests is always nice too)
- Commit your changes + push to your fork
- Open a PR
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for compile-dcm2bids-config-1.2.0.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0eba59399e26dc9071463dd1f7c7ef0264ca5d68b40d1f9dfac13507b199acf |
|
MD5 | a56f3127f1f575ff064a33158b21f967 |
|
BLAKE2b-256 | c59ef2738425467d7403b48b485bca82a37299a5964d1bd27cb980cd4e128f42 |
Close
Hashes for compile_dcm2bids_config-1.2.0.post0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bda0be14697634882c7a4d598d83702c110f2407f1a3b9fbe2da149c239c0d3b |
|
MD5 | d0777462de20c68d2f8e2d1c9e0355f3 |
|
BLAKE2b-256 | 866b053081293fba0d068b0c8b4b6de4c78e6c73eb32d79c476b9b7b88ae7706 |