Skip to content

Commit

Permalink
Smooth individually CSF and SC T2starw signal before taking the ratio
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
jcohenadad committed Jan 24, 2024
1 parent febb3c6 commit 2ab713a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions data_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"# Go back to root data folder\n",
"os.chdir(path_data)\n",
"\n",
"def smooth_data(data, window_size=40):\n",
"def smooth_data(data, window_size=50):\n",
" \"\"\" Apply a simple moving average to smooth the data. \"\"\"\n",
" return uniform_filter1d(data, size=window_size, mode='nearest')\n",
"\n",
Expand Down Expand Up @@ -371,14 +371,16 @@
" file_csv = os.path.join(path_results, f\"{subject}_acq-{shim_method}_T2starw_label-SC.csv\")\n",
" df = pd.read_csv(file_csv)\n",
" data_sc = df['WA()']\n",
" data_sc_smoothed = smooth_data(data_sc)\n",
"\n",
" # Get signal in CSF\n",
" file_csv = os.path.join(path_results, f\"{subject}_acq-{shim_method}_T2starw_label-CSF.csv\")\n",
" df = pd.read_csv(file_csv)\n",
" data_csf = df['WA()']\n",
" data_csf_smoothed = smooth_data(data_csf)\n",
" \n",
" # Compute ratio\n",
" data_sc_csf_ratio = data_csf / data_sc\n",
" data_sc_csf_ratio = data_csf_smoothed / data_sc_smoothed\n",
"\n",
" # Normalize the x-axis to a 0-1 scale for each subject\n",
" x_subject = np.linspace(0, 1, len(data_sc_csf_ratio))\n",
Expand All @@ -387,10 +389,7 @@
" interp_func = interp1d(x_subject, data_sc_csf_ratio, 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",
"\n",
" method_data.append(smoothed_data)\n",
" method_data.append(resampled_data)\n",
"\n",
" # If there's data for this shim method, plot it\n",
" if method_data:\n",
Expand Down

0 comments on commit 2ab713a

Please sign in to comment.