diff --git a/data_processing.ipynb b/data_processing.ipynb index 02c19b7..7123f0d 100644 --- a/data_processing.ipynb +++ b/data_processing.ipynb @@ -56,12 +56,15 @@ "\n", "For each subject:\n", "\n", - "- Segment the SC from the GRE scan\n", - "- Extract the signal intensity within this mask from the GRE scans\n", - "- Coregister the TFL_B1map to the corresponding GRE scan from each subfolder (CVred, Noshim, etc.)\n", - "- Apply the computed warping field to bring the SC segmentation to the TFL_B1map\n", - "- Convert the B1+ maps to nT/V units\n", - "- Extract the B1+ value within the registered mask" + "- Segment the SC on GRE scan\n", + "- Label vertebral levels on GRE scan using existing manual disc labels\n", + "- Extract the signal intensity on the GRE scan within the spinal cord\n", + "- Register each B1 map (CP, CoV, etc.) to the GRE scan\n", + "- Apply the computed warping field to bring the segmentation and vertebral levels to the B1 map\n", + "- Convert the B1 map to nT/V units\n", + "- Extract the B1 map value within the spinal cord\n", + "\n", + "Slow processes are indicated with the emoji ⏳" ] }, { @@ -98,8 +101,8 @@ "\n", "!datalad install https://github.com/OpenNeuroDatasets/ds004906.git\n", "os.chdir(\"ds004906\")\n", - "# !datalad get . # uncomment for production\n", - "!datalad get sub-01/ # comment for debugging" + "!datalad get . # uncomment for production\n", + "# !datalad get sub-01/ # comment for debugging" ] }, { @@ -144,7 +147,17 @@ { "cell_type": "code", "execution_count": null, - "id": "34fd14bc", + "id": "ab6a7dbe", + "metadata": {}, + "outputs": [], + "source": [ + "os.path.join(path_data, \"derivatives\", \"labels\", subject, \"anat\", f\"{subject}_acq-CoV_T2starw_label-discs_dseg.nii.gz\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e1a6ae1", "metadata": {}, "outputs": [], "source": [ @@ -153,7 +166,8 @@ "# Given the low resolution of the GRE scan, the automatic detection of C2-C3 disc is unreliable. Therefore we need to use the manual disc labels that are part of the dataset.\n", "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"anat\"))\n", - "# !sct_label_vertebrae -i {subject}_acq-CoV_T2starw.nii.gz -s {subject}_acq-CoV_T2starw_seg.nii.gz -c t2 -initz -qc {path_qc}" + " fname_label_discs = os.path.join(path_data, \"derivatives\", \"labels\", subject, \"anat\", f\"{subject}_acq-CoV_T2starw_label-discs_dseg.nii.gz\")\n", + " !sct_label_vertebrae -i {subject}_acq-CoV_T2starw.nii.gz -s {subject}_acq-CoV_T2starw_seg.nii.gz -c t2 -discfile {fname_label_discs} -qc {path_qc}" ] }, { @@ -168,7 +182,8 @@ "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"anat\"))\n", " !sct_crop_image -i {subject}_acq-CoV_T2starw.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop.nii.gz\n", - " !sct_crop_image -i {subject}_acq-CoV_T2starw_seg.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop_seg.nii.gz" + " !sct_crop_image -i {subject}_acq-CoV_T2starw_seg.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop_seg.nii.gz\n", + " !sct_crop_image -i {subject}_acq-CoV_T2starw_seg_labeled.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop_seg_labeled.nii.gz " ] }, { @@ -178,7 +193,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Register TFL B1maps to the GRE scan\n", + "# Register TFL B1maps to the GRE scan ⏳\n", "\n", "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"fmap\"))\n", @@ -188,7 +203,7 @@ }, { "cell_type": "markdown", - "id": "4952bdfa", + "id": "679f1193", "metadata": {}, "source": [ "## Verify QC report (B1maps to GRE registration)\n", @@ -199,22 +214,23 @@ { "cell_type": "code", "execution_count": null, - "id": "5fb3101a", + "id": "623c26cd", "metadata": {}, "outputs": [], "source": [ - "# Warping spinal cord segmentation to each B1 map\n", + "# Warping spinal cord segmentation and vertebral level to each B1 map\n", "\n", "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"fmap\"))\n", " for shim_mode in shim_modes:\n", - " !sct_apply_transfo -i ../anat/{subject}_acq-CoV_T2starw_crop_seg.nii.gz -d {subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -w warp_{subject}_acq-CoV_T2starw_crop2{subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -x linear" + " !sct_apply_transfo -i ../anat/{subject}_acq-CoV_T2starw_crop_seg.nii.gz -d {subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -w warp_{subject}_acq-CoV_T2starw_crop2{subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -x linear -o {subject}_acq-anat{shim_mode}_TB1TFL_seg.nii.gz\n", + " !sct_apply_transfo -i ../anat/{subject}_acq-CoV_T2starw_crop_seg_labeled.nii.gz -d {subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -w warp_{subject}_acq-CoV_T2starw_crop2{subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -x nn -o {subject}_acq-anat{shim_mode}_TB1TFL_seg_labeled.nii.gz" ] }, { "cell_type": "code", "execution_count": null, - "id": "f476b7ac", + "id": "ef34c2a1", "metadata": {}, "outputs": [], "source": [