Skip to main content

compile-dcm2bids-config

Combine dcm2bids and d2b config files into a single config file while preserving the integrity of each separate config file's various IntendedFor fields.

PyPI Version codecov Tests Code Style Type Check

Installation

For the basic functionality:

pip install compile-dcm2bids-config

If you have config files written in YAML you can install the yaml extra, for example:

pip install 'compile-dcm2bids-config[yaml]'

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']}]}

YAML Configuration Files

This package can handle dcm2bids (or d2b) configuration files written in YAML, the user just has to install the PyYAML package, either separately:

pip install pyyaml

or all at once via the installation "extra":

pip install 'compile-dcm2bids-config[yaml]'

If PyYAML is available, then configuration files ending with .yml or .yaml can be passed as input files:

compile-dcm2bids-config config1.json config2.yaml > combined.json

The combined configuration file can also be formatted as YAML by adding the --to-yaml flag:

compile-dcm2bids-config --to-yaml config1.json config2.yaml > combined.yaml

Contributing

  1. Have or install a recent version of poetry (version >= 1.1)
  2. Fork the repo
  3. Setup a virtual environment (however you prefer)
  4. Run poetry install
  5. Run pre-commit install
  6. Add your changes (adding/updating tests is always nice too)
  7. Commit your changes + push to your fork
  8. Open a PR

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compile-dcm2bids-config-1.4.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compile_dcm2bids_config-1.4.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file compile-dcm2bids-config-1.4.3.tar.gz.

File metadata

  • Download URL: compile-dcm2bids-config-1.4.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.10.0 Linux/5.8.0-1042-azure

File hashes

Hashes for compile-dcm2bids-config-1.4.3.tar.gz
Algorithm Hash digest
SHA256 f439578e39275ae149014ac377747b791ba0085d352de6b62cbb1b0067c7e89c
MD5 18e30eaa57317530da6351b8b23fcc08
BLAKE2b-256 155d8186fe40d52b986d4f58c986f55992a7a6dc6a455d0e2dc10488641fb7c5

See more details on using hashes here.

File details

Details for the file compile_dcm2bids_config-1.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for compile_dcm2bids_config-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8076d787bb70c93501883f1b5c58d9b9ce125296dffd22d1e2bb4b2031681e80
MD5 0ded077a0470f95c332a07fd8448b3a9
BLAKE2b-256 9dfd30f0310ff12c4d1883f5b0f16ca49b2b65ec22f3456b8851d13a8a1b059e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.3 This release

2 files

1.4.2

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0.post0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page