From 619f2754e3adb4d7d93c1921e34aac15d9c18707 Mon Sep 17 00:00:00 2001 From: jcohenadad Date: Tue, 23 Jan 2024 22:38:44 -0500 Subject: [PATCH] Output CSV for B1+ values under derivatives/results/ --- data_processing.ipynb | 47 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/data_processing.ipynb b/data_processing.ipynb index d3428ca..6093aab 100644 --- a/data_processing.ipynb +++ b/data_processing.ipynb @@ -430,7 +430,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cf0074dc", + "id": "f2a6d765", "metadata": {}, "outputs": [], "source": [ @@ -604,7 +604,8 @@ "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"fmap\"))\n", " for shim_mode in shim_modes:\n", - " !sct_extract_metric -i {subject}_acq-{shim_mode}_TB1map.nii.gz -f {subject}_acq-anat{shim_mode}_TB1TFL_seg.nii.gz -method wa -vert 3:9 -vertfile {subject}_acq-anat{shim_mode}_TB1TFL_seg_labeled.nii.gz -perslice 1 -o TB1map_{shim_mode}.csv" + " fname_result_b1plus = os.path.join(path_results, f\"{subject}_TB1map_{shim_mode}.csv\")\n", + " !sct_extract_metric -i {subject}_acq-{shim_mode}_TB1map.nii.gz -f {subject}_acq-anat{shim_mode}_TB1TFL_seg.nii.gz -method wa -vert 3:9 -vertfile {subject}_acq-anat{shim_mode}_TB1TFL_seg_labeled.nii.gz -perslice 1 -o {fname_result_b1plus}" ] }, { @@ -661,32 +662,32 @@ " # Initialize list to collect data for this shim method\n", " method_data = []\n", "\n", - " for file_path in glob.glob(f\"TB1map_*{shim_mode}*.csv\"):\n", - " df = pd.read_csv(file_path)\n", - " wa_data = df['WA()']\n", + " file_csv = os.path.join(path_results, f\"{subject}_TB1map_{shim_mode}.csv\")\n", + " df = pd.read_csv(file_csv)\n", + " wa_data = df['WA()']\n", "\n", - " # Normalize the x-axis to a 0-1 scale for each subject\n", - " x_subject = np.linspace(0, 1, len(wa_data))\n", + " # Normalize the x-axis to a 0-1 scale for each subject\n", + " x_subject = np.linspace(0, 1, len(wa_data))\n", "\n", - " # Interpolate to the fixed grid\n", - " interp_func = interp1d(x_subject, wa_data, kind='linear', bounds_error=False, fill_value='extrapolate')\n", - " resampled_data = interp_func(x_grid)\n", + " # Interpolate to the fixed grid\n", + " interp_func = interp1d(x_subject, wa_data, kind='linear', bounds_error=False, fill_value='extrapolate')\n", + " resampled_data = interp_func(x_grid)\n", "\n", - " # Apply smoothing\n", - " smoothed_data = smooth_data(resampled_data)\n", + " # Apply smoothing\n", + " smoothed_data = smooth_data(resampled_data)\n", "\n", - " method_data.append(smoothed_data)\n", + " method_data.append(smoothed_data)\n", "\n", - " # If there's data for this shim method, plot it\n", - " if method_data:\n", - " # Plotting each file's data separately\n", - " for resampled_data in method_data:\n", - " ax.plot(x_grid, resampled_data, label=f\"{shim_mode}\")\n", + " # If there's data for this shim method, plot it\n", + " if method_data:\n", + " # Plotting each file's data separately\n", + " for resampled_data in method_data:\n", + " ax.plot(x_grid, resampled_data, label=f\"{shim_mode}\")\n", "\n", - " # Compute stats on the non-resampled data (to avoid interpolation errors)\n", - " mean_data = np.mean(wa_data)\n", - " sd_data = np.std(wa_data)\n", - " data_stats.append([subject, shim_mode, mean_data, sd_data])\n", + " # Compute stats on the non-resampled data (to avoid interpolation errors)\n", + " mean_data = np.mean(wa_data)\n", + " sd_data = np.std(wa_data)\n", + " data_stats.append([subject, shim_mode, mean_data, sd_data])\n", "\n", " # Set custom x-ticks\n", " ax.set_xticks(custom_xticks)\n", @@ -710,7 +711,7 @@ { "cell_type": "code", "execution_count": null, - "id": "90cdb2f6", + "id": "f062f23d", "metadata": {}, "outputs": [], "source": [