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] 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.
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*"
}
},
{
"dataType": "func",
"modalityLabel": "bold",
"customLabels": "task-rest",
"criteria": {
"SeriesDescription": "rs_fMRI"
},
"sidecarChanges": {
"SeriesDescription": "rsfMRI"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-3*"
},
"IntendedFor": [0, 2]
}
]
}
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*"
}
},
{
"dataType": "func",
"modalityLabel": "bold",
"customLabels": "task-rest",
"criteria": {
"SeriesDescription": "rs_fMRI"
},
"sidecarChanges": {
"SeriesDescription": "rsfMRI"
}
},
{
"dataType": "fmap",
"modalityLabel": "fmap",
"criteria": {
"SidecarFilename": "*echo-3*"
},
"IntendedFor": [
2,
4
]
}
]
}
Notice that the IntendedFor
fields have been updated appropriately.
NOTE: Other fields at the top level of the config file (i.e. at the same level as
descriptions
), for example:searchMethod
ordefaceTpl
, are omitted in the merged config file output bycompile-dcm2bids-config
. Since different config file may have different top-level paramters it is upto the user to determine which parameters should be retained and/or whether or not it makes sense to even combine the provided configuration files.
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*'}},
{'dataType': 'func',
'modalityLabel': 'bold',
'customLabels': 'task-rest',
'criteria': {'SeriesDescription': 'rs_fMRI'},
'sidecarChanges': {'SeriesDescription': 'rsfMRI'}},
{'dataType': 'fmap',
'modalityLabel': 'fmap',
'criteria': {'SidecarFilename': '*echo-3*'},
'IntendedFor': [2, 4]}]}
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
TODO
- Add e2e tests
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
Hashes for compile-dcm2bids-config-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b03b38e79049fdb374cb2cf6392fe9cae52e13c51b54fff2c5b1f8ce5ae8fd54 |
|
MD5 | 4ad672b562dc2601198b8a79ca2e3519 |
|
BLAKE2b-256 | 0600bf819f1fafa3092d5da85eda3c0264ad1b66fe80579d51c7dc1a40f2b436 |
Hashes for compile_dcm2bids_config-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 600933b894e8c49a104b3c17ebd1ceb86d0ee9e6df65d5ccfdee95c91ce67e35 |
|
MD5 | de930adad58013d66bb0fec4647e8ec1 |
|
BLAKE2b-256 | e5824408103772b2291edeb2500f6c424438354c21978cebdf2a3522ef33f466 |