Skip to main content

BrainVoyager Tools - An object-oriented approach to create, read and write common plain-text BrainVoyager input formats with Python

Project description

BrainVoyager Tools

An object-oriented approach to create, read and write common plain-text BrainVoyager input formats with Python.

Currently supported:

  • .ctr
  • .mdm
  • .prt
  • .sdm
  • .voi

Installation

BrainVoyager Tools can be easily installed with pip:

pip install brainvoyagertools

Usage

ctr

Build a contrast definition from scratch:

from brainvoyagertools import ctr

contrasts = ctr.ContrastsDefinition()
contrasts.add_contrast(ctr.Contrast("All vs. Baseline", [1, 1, 0]))
contrasts.add_contrast(ctr.Contrast("House vs. Faces", [1, -1, 0]))
contrasts.save("contrasts.ctr")

Add contrasts to contrast definition file:

from brainvoyagertools import ctr

contrasts = ctr.ContrastsDefinition(load="contrasts.ctr")
contrasts.add_contrast(ctr.Contrast("Faces vs. Houses", [-1, 1, 0]))
contrasts.save("contrasts2.ctr")

mdm

Build a design matrix from scratch:

from brainvoyagertools import mdm

design = mdm.DesignMatrix()
design.add_study(mdm.Study("path/to/MyStudy1.vtc", "path/to/MyStudy1.sdm")
design.add_study(mdm.Study("path/to/MyStudy2.vtc", "path/to/MyStudy2.sdm")
design.add_study(mdm.Study("path/to/MyStudy3.vtc", "path/to/MyStudy3.sdm")
design.add_study(mdm.Study("path/to/MyStudy4.vtc", "path/to/MyStudy4.sdm")
design.add_study(mdm.Study("path/to/MyStudy5.vtc", "path/to/MyStudy5.sdm")
design.add_study(mdm.Study("path/to/MyStudy6.vtc", "path/to/MyStudy6.sdm")
design.add_study(mdm.Study("path/to/MyStudy7.vtc", "path/to/MyStudy7.sdm")
design.add_study(mdm.Study("path/to/MyStudy8.vtc", "path/to/MyStudy8.sdm")
design.add_study(mdm.Study("path/to/MyStudy9.vtc", "path/to/MyStudy9.sdm")
design.add_study(mdm.Study("path/to/MyStudy10.vtc", "path/to/MyStudy10.sdm")
design.rfx_glm = True
design.transformation = 'z'
design.separate_predictors = True
design.save("design.mdm")

Also works for MTC data:

from brainvoyagertools import mdm

design = mdm.DesignMatrix()
design.add_study(mdm.Study(["path/to/MyStudy1.ssm", "path/to/MyStudy1.mtc"], "path/to/MyStudy1.sdm")
design.add_study(mdm.Study(["path/to/MyStudy2.ssm", "path/to/MyStudy2.mtc"], "path/to/MyStudy2.sdm")
design.add_study(mdm.Study(["path/to/MyStudy3.ssm", "path/to/MyStudy3.mtc"], "path/to/MyStudy3.sdm")
design.save("design2.mdm")

prt

Build a stimulation protocol from scratch:

from brainvoyagertools import prt

protocol = prt.StimulationProtocol(experiment_name="MyExperiment")
protocol.add_condition(prt.Condition("Rest", [[x+1,x+8] for x in range(1,80,16], colour=[255,0,0]))
protocol.add_condition(prt.Condition("Task", [[x+1,x+8] for x in range(8,80,16], colour=[0,255,0]))
protocol.save("MyExperiment.prt")

Change time units to milliseconds and add condition to other protocol:

from brainvoyagertools import prt

protocol = prt.StimulationProtocol(load="MyExperiment.prt")
protocol.convert_to_msec(tr=2000)
protocol2 = prt.StimulationProtocol(experiment_name="MyExperiment2", time_units="msec")
protocol2.add_condition(prt.conditions[-1])
protocol2.save("MyExperiment2.prt")

Add combination of conditions into new protocol:

from brainvoyagertools import prt

protocol = prt.StimulationProtocol(load="MyExperiment.prt")
protocol2 = prt.StimulationProtocol(experiment_name="MyExperiment3"
protocol2.add_condition(protocol.condition[0] + protocol.conditions[1])
protocol2.save("MyExperiment3.prt")

sdm

Build a design matrix from scratch:

from brainvoyagertools import sdm

design = sdm.DesignMatrix()
design.add_predictor(sdm.Predictor("FirstHalf", 100*[1] + 100*[0], colour=[255,0,0]))
design.add_predictor(sdm.Predictor("SecondHalf", 100*[0] + 100*[1], colour=[0,255,0]))
for p in design.predictors:
    p.convolve_with_hrf(tr=2000)
design.save("design.sdm")

Add z-transformed motion regressors, their first and second derivatives, and a constant:

from brainvoyagertools import sdm

design = sdm.DesignMatrix(load="design.sdm")
motion = sdm.DesignMatrix(load="3DMC.sdm")
for p in motion.predictors:
    p.ztransform()
    design.add_confound_predictor(p)
    design.add_confound_predictor(p.get_derivative(1))
    design.add_confound_predictor(p.get_derivative(2))
design.add_constant()
design.save("design_and_motion.sdm")

Define predictors from a prt file:

from brainvoyagertools import prt, sdm

protocol = prt.StimulationProtocol(load="protocol.prt")
design = sdm.DesignMatrix()
design.define_predictors(protocol, data_points=400, tr=2000)
design.add_constant()
design.save("design.sdm")

voi

Save a single a VOI with three coordinates :

from brainvoyagertools import voi

vois = voi.VOIsDefinition(reference_space="MNI")
vois.add_voi(voi.VOI("VOI_1", [[15, 30, 40], [16, 30, 40]]
vois.save("my_voi.voi")

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

brainvoyagertools-0.4.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

brainvoyagertools-0.4.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file brainvoyagertools-0.4.0.tar.gz.

File metadata

  • Download URL: brainvoyagertools-0.4.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.6

File hashes

Hashes for brainvoyagertools-0.4.0.tar.gz
Algorithm Hash digest
SHA256 28e33837f17b624355bbc497a052a8725451ad0c3eaa46b38e8820e0c2e3a0f8
MD5 1dbec3ab970cfeafa1aab7333ea0a96c
BLAKE2b-256 18a9ac73b7b3be8b6ea84461e14a351ffe39eda97a870b936b46448fb514cf33

See more details on using hashes here.

File details

Details for the file brainvoyagertools-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: brainvoyagertools-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.6

File hashes

Hashes for brainvoyagertools-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 711a24bb23e6eef362ffc95433b52897e88b99279bb994016cb611714a36c4ae
MD5 429b8b80d2fdeb08c321a3ea4700a545
BLAKE2b-256 11311ff2f79efdf818fcea28ae6230cfeb94211aae8db2fd48f07ebbd5cd64c3

See more details on using hashes here.

Supported by

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