Skip to main content

Plugin for the d2b package to deterministically uniquify different acquisition runs

Project description

d2b-nth-of-type

PyPI Version Code Style Type Check Tests

Plugin for the d2b package to deterministically uniquify different acquisition runs

Intallation

pip install d2b-nth-of-type

Getting Started

This plugin will inject properties into each JSON sidecar which distinguish different runs from one another, which can subsequently be used in criteria specifications in d2b config files.

Specifically, this plugin will inject a property, __nth_of_type__, into each JSON sidecar. The value of this property is a 0-indexed integer.

This plugin groups acquisitions and gives each run in the group a unique (0-indexed) label, incrementing in the specified order.

By default, acquisitions are grouped by SeriesDescription and are ordered by SeriesNumber (in ascending order).

For example, if a subject has a session in which 3 fieldmaps are acquired, and say, for example, the 3 sidecars (truncated) are of the form:

  • fieldmap 1:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 3
    }
    
  • fieldmap 2:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 16
    }
    
  • fieldmap 3:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 24
    }
    

Then, when running d2b run with this plugin installed, this plugin will inject __nth_of_type__ into each sidecar, resulting in sidecars (truncated) which look like:

  • fieldmap 1:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 3,
      "__nth_of_type__": 0
    }
    
  • fieldmap 2:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 16,
      "__nth_of_type__": 1
    }
    
  • fieldmap 3:

    {
      "SeriesDescription": "my_fmap",
      "SeriesNumber": 24,
      "__nth_of_type__": 2
    }
    

The utility is that these values will be invariant under changes to SeriesNumber.

So, if the "first" fmap is intended for a BOLD acquisition, and the "second" fmap is intended for a PCASL acquisition, we can safely pick-out each fmap using the __nth_of_type__ field.

For example, we could have a d2b configuration file of the following form (NOTE: d2b-yaml plugin required for yaml config files, and you probably also want the d2b-asl plugin for ASL data):

descriptions:
  # BOLD Resting State
  - id: my-bold-rs
    dataType: func
    modalityLabel: bold
    customLabels: task-rest

    criteria:
      # ...

  # PCASL
  - id: my-pcasl
    dataType: perf
    modalityLabel: asl
    customLabels:
      acq: pcasl

    criteria:
      # ...
    aslContext:
      # ...

  # FIRST FMAP - for BOLD - phase encoding = AP
  - dataType: fmap
    modalityLabel: epi
    customLabels:
      dir: AP
    IntendedFor:
      - my-bold-rs
    criteria:
      ManufacturersModelName: Prisma_fit
      SidecarFilename: "*SpinEchoFieldMap_AP*"
      __nth_of_type__: 0 # <-- HERE

  # FIRST FMAP - for BOLD - phase encoding = PA
  - dataType: fmap
    modalityLabel: epi
    customLabels:
      dir: PA
    IntendedFor:
      - my-bold-rs
    criteria:
      ManufacturersModelName: Prisma_fit
      SidecarFilename: "*SpinEchoFieldMap_PA*"
      __nth_of_type__: 0 # <-- HERE

  # SECOND FMAP - for PCASL - phase encoding = AP
  - dataType: fmap
    modalityLabel: epi
    customLabels:
      dir: AP
    IntendedFor:
      - my-pcasl
    criteria:
      ManufacturersModelName: Prisma_fit
      SidecarFilename: "*SpinEchoFieldMap_AP*"
      __nth_of_type__: 1 # <-- HERE

  # SECOND FMAP - for PCASL - phase encoding = PA
  - dataType: fmap
    modalityLabel: epi
    customLabels:
      dir: PA
    IntendedFor:
      - my-pcasl
    criteria:
      ManufacturersModelName: Prisma_fit
      SidecarFilename: "*SpinEchoFieldMap_PA*"
      __nth_of_type__: 1 # <-- HERE

Configuration

This plugin can be configured by via options to the d2b run command or via the environment:

  • --nth-of-type-enabled | --nth-of-type-disabled

    Enable or disable this plugin. (default: enabled)

    Can also be configured via the D2B_NTH_OF_TYPE_ENABLED environment variable. The command line argument takes precedence over the environment variable.

  • --nth-of-type-sort-by <string>

    Which sidecar field to sort the acquisitions by (default: SeriesNumber:asc).

    To sort in descending order append :desc onto the fieldname, ex: SeriesNumber:desc. If no direction/ordering suffix (:asc/:desc) is present then the acquisitions are sorted in ascending order.

    Can also be configured via the D2B_NTH_OF_TYPE_SORT_BY environment variable. The command line argument takes precedence over the environment variable.

  • --nth-of-type-group-by <string>

    Which sidecar field(s) to group acquisitions by (default: SeriesDescription).

    To group by more then one field pass a comma separated list, ex: SeriesDescription,RepetitionTime

    Can also be configured via the D2B_NTH_OF_TYPE_GROUP_BY environment variable. The command line argument takes precedence over the environment variable.

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

Project details


Download files

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

Source Distribution

d2b-nth-of-type-1.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

d2b_nth_of_type-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file d2b-nth-of-type-1.0.1.tar.gz.

File metadata

  • Download URL: d2b-nth-of-type-1.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for d2b-nth-of-type-1.0.1.tar.gz
Algorithm Hash digest
SHA256 66b3575ea8e9f153a4a70315973f959c3554ceaa0e6b295ba902f5d3b84819cc
MD5 fe5d79d5128fba803e157f547f9ed1f7
BLAKE2b-256 a034650a2fc876541204ef8662153d11181523e4571acc8ac94238cd25993349

See more details on using hashes here.

File details

Details for the file d2b_nth_of_type-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: d2b_nth_of_type-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for d2b_nth_of_type-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 25082ee04fb91f0664f2dd913b0f891438dbffad9bf392e217546c9fb3e60454
MD5 3466a5fa6a2d2d05610d3e69270a9f2c
BLAKE2b-256 5e89434360d4ebc7754766568186962ca7a603244e07cd2be664578899b5e25b

See more details on using hashes here.

Supported by

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