Browse Source

update script to add IntentedFor to fieldmap jsons and add scripts to documentation

Lennart Wittkuhn 3 years ago
parent
commit
962f0de47d

+ 5 - 4
code/bids_conversion/highspeed-bids-fieldmaps.py

@@ -17,16 +17,17 @@
 import os
 import glob
 import json
-import sys
 import stat
 # ======================================================================
 # DEFINE PATHS
 # ======================================================================
 # to run type python3 bids_fieldmaps_info.py $PATH_BIDS
 # where $PATH_BIDS is the path to your BIDS directory
-path_bids = str(sys.argv[1])
-path_fmap = os.path.join(path_bids, '*', '*', 'fmap', '*.json')
-path_func = os.path.join(path_bids, '*', '*', 'func', '*.nii.gz')
+# path to the project root:
+project_name = 'highspeed-bids'
+path_root = os.getcwd().split(project_name)[0] + project_name
+path_fmap = os.path.join(path_root, '*', '*', 'fmap', '*.json')
+path_func = os.path.join(path_root, '*', '*', 'func', '*.nii.gz')
 # ======================================================================
 # UPDATE FIELDMAP JSON FILES
 # ======================================================================

+ 42 - 1
code/docs/highspeed-bids-docs.Rmd

@@ -157,4 +157,45 @@ In order to replace the original structural images with the defaced once ([as re
 ### Resources
 
 * ["Pydeface defaces structural data only?!"](https://neurostars.org/t/pydeface-defaces-structural-data-only/903) - Discussion on neurostars.org if any other data than structural acquisitions should be defaced (short answer: no!)
-* ["Is/how much fmriprep (freesurfer et al) is resilient to “defacing”?"](https://neurostars.org/t/is-how-much-fmriprep-freesurfer-et-al-is-resilient-to-defacing/2642) - Discussion on neurostars.org if `fMRIPrep` works well with defaced data (short answer: yes!)
+* ["Is/how much fmriprep (freesurfer et al) is resilient to “defacing”?"](https://neurostars.org/t/is-how-much-fmriprep-freesurfer-et-al-is-resilient-to-defacing/2642) - Discussion on neurostars.org if `fMRIPrep` works well with defaced data (short answer: yes!)
+
+## Step 3: Adding additional information to the BIDS dataset
+
+### Code and software
+
+First, we created a virtual environment using Python version 3.8.5 to install all dependencies and required packages.
+
+A list of all required packages can be found in `requirements.txt` (created using `pip freeze > requirements.txt`) and installed via `pip install -r requirements.txt`.
+
+```bash
+mkvirtualenv highspeed-bids -p $(which python3)
+````
+
+```bash
+(highspeed-bids) lip-osx-003854:highspeed-bids wittkuhn$ python --version
+Python 3.8.5
+````
+
+#### Updating `dataset_description.json`: `python highspeed-bids-description.py`
+
+`highspeed-bids-description.py` is a short Python script that loads the `dataset_description.json` file that is pre-generated by HeuDiConv and populates it with the relevant study informtion.
+
+```{python, echo=TRUE, code=readLines(file.path(path_root, "code", "bids_conversion", "highspeed-bids-description.py")), eval=FALSE, python.reticulate=FALSE}
+```
+
+#### Updating the `.json` files of fieldmap data: `python highspeed-bids-fieldmaps.py`
+
+During later pre-processing of MRI data with `fMRIPrep`, we want to use our fieldmap data for distortion correction.
+To ensure that `fMRIPrep` detects and uses the fieldmap data, we need to add the `IntendedFor` field to the `.json` files of the fieldmap data and provide relative paths to the functional task data (see [here](https://bids-specification.readthedocs.io/en/latest/04-modality-specific-files/01-magnetic-resonance-imaging-data.html#fieldmap-data) for more information).
+
+This is done using the `code/bids_conversion/highspeed-bids-fieldmaps.py` file.
+To detect the provencance of the run command in our DataLad dataset, we run:
+
+```bash
+datalad run -m "create IntendedFor fields in fieldmap .json files" \
+--input "./*/*/*/*.nii.gz" --output "./*/*/fmap/*.json" \ "python3 code/code/bids_conversion/highspeed_bids_fieldmaps.py ."
+```
+
+```{python, echo=TRUE, code=readLines(file.path(path_root, "code", "bids_conversion", "highspeed-bids-fieldmaps.py")), eval=FALSE, python.reticulate=FALSE}
+```
+