Package: erwin
erwin — a qMRI toolboxerwinis a Python-based toolbox dedicated to the computation of quantitative maps from MRI data. Accessible through either its Python API or its command-line interface,erwinprovides a unified interface to well-known methods and toolboxes.Field mapping: relative B0 and relative B1Cerebral blood flow: ASL-based models (pulsed ASL, pseudo-continuous ASL)Diffusion: DTI and spherical harmonics, NODDIMotion correctionMagnetization transfer: MTR and single-point qMTMagnetic susceptibility: QSM and R2*T1 and T2 mapping: VFA, bSSFP, pSSFPSince quantitative MRI requires accessing acquisition parameters, often stored in vendor-specific meta-data,erwinincludes tools to access meta-data in a vendor-neutral way. UsingdoitandSpire,erwinallows the definition of complex pipelines with automatic dependency handling.The complete documentation is availableonline.Installationerwinrequires Python ≥ 3.7 The easiest way to installerwinand its dependencies is throughPyPiandpip:python3 -m pip install erwinIf this fails, you may need toadjust thepython3executable to match your local installationupgradepip(python3 -m pip install --upgrade pip, especially on Debian ≤ 10 and Ubuntu ≤ 18.04)installCythoninstall BLAS and LAPACKUsing the following methods requires additional dependencies:Diffusion tensor and spherical harmonics:MRtrix; conversion from Bruker or Siemens DICOM also requiresDicomifierMotion correction:ANTsQSM:MEDICommand-line usageOn the command-line, the main executable is callederwin; a list of all methods can be obtained byerwin--listThe documentation of each individual method is accessed by appending--helpto its name, e.g.erwinb0_map.double_echo--helpDue to the large number of parameters -- input and output paths, flip angles, echo times, imaging frequencies, etc. -- each command line argument is named. Parameters corresponding to physical quantities are expressed in SI units in order to avoid discrepancies between standards: DICOM uses "usual" units, e.g. milliseconds for TR or degrees for flip angles, while BIDS uses seconds for TR, but keeps degrees for flip angles.erwinb0_map--magnitude/path/to/m1.nii.gz/path/to/m2.nii.gz--phase/path/to/p1.nii.gz/path/to/p2.nii.gz--echo-times0.010.02--targetB0_map.nii.gzerwinincludes a generic meta-data reader to facilitate the conversion to SI: from either a DICOM or a JSON file, meta-data can be queried using specific units. A flip angle can be read and converted to radians using one of the two following examples, from a DICOM file or from a BIDS sidecar file:ALPHA=$(erwinmeta_data.get-p/path/to/some_file-qFlipAngle-udeg)The same tool can be used for array-like meta-data (erwin meta_data.get -p /path/to/file.dcm -q ImageType.0) or for nested structures, including vendor-specific elements. For example, Siemens-specific meta-data from the sequence card can be queried byerwinmeta_data.get-p/path/to/some_file-q00291020.MrPhoenixProtocol.0.sWiPMemBlock.adFree.0Usage in a Python programSeen from a Python program, all methods defined inerwinare task objects and not function. This enables to easily connect steps in a pipeline: in the following example, the T1 mapping requires the output of the B1 mapping. Note that the path to the B1 map is only defined once, and that the maps will only be computed when callingerwin.run.importerwinB1_map=erwin.b1_map.AFI(["afi1.nii.gz","afi2.nii.gz"],afi_flip_angle,afi_tr_ratio,"B1.nii.gz")T1_map=erwin.t1_map.VFA(["vfa1.nii.gz","vfa2.nii.gz"],vfa_flip_angles,vfa_tr,B1_map.target)erwin.run([B1_map,T1_map])Even for such a small pipeline, it is beneficial to automate the ordering of tasks, and to keep track of which ones have already been executed. This is handled bydoitandSpire-- both requirements oferwin, so they should be already installed. By dropping the last instruction (erwin.run([B1_map, T1_map])) and storing the following file in e.g.pipeline.py, the pipeline can be run by callingdoit -f pipeline.py.importerwinB1_map=erwin.b1_map.AFI("afi.nii.gz",afi_flip_angle,afi_tr_ratio,"B1.nii.gz")T1_map=erwin.t1_map.VFA(["vfa1.nii.gz","vfa2.nii.gz"],vfa_flip_angles,vfa_te,vfa_tr,B1_map.target,"T1_map.nii.gz")Note that re-running doit will not re-run the tasks: since neither the original images nor the code have been modified, everything is up-to-date. Refer to thedoitdocumentation for more details about running tasks.The complete API is available in themain documentation.