Added ky kz undersampling pattern.

This commit is contained in:
jupfi 2024-08-05 13:03:50 +02:00
parent 7ee78882d7
commit a27b222671

View file

@ -130,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "5abe217f-02ba-4ca4-9de2-7862af2d0ce6",
"metadata": {},
"outputs": [
@ -215,7 +215,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"id": "c60a8e73-8a0b-4cb8-9724-891d860307e4",
"metadata": {},
"outputs": [
@ -245,7 +245,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"id": "f7b7800e-8a4c-4852-b94c-2b47cd4a52de",
"metadata": {},
"outputs": [],
@ -378,7 +378,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"id": "f1883fa9-f260-47a3-9598-474905d10f89",
"metadata": {},
"outputs": [
@ -428,7 +428,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"id": "96b28fec-ff5a-44a3-8a0c-9b01b60cff0c",
"metadata": {},
"outputs": [],
@ -447,7 +447,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"id": "5f93fcca-48ab-4d42-9061-91361aadfb35",
"metadata": {},
"outputs": [
@ -475,7 +475,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 12,
"id": "77d36186-04bb-422d-9ec3-a2032fcbceda",
"metadata": {},
"outputs": [],
@ -686,11 +686,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "a0a45c91-da70-4fdf-b1ab-a35b5d92b63c",
"metadata": {},
"outputs": [],
"source": []
"source": [
"%%bash\n",
"bart ecalib -m1 data/ksp data/coilsens_fully"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "3db83274-63d1-4ae1-abcf-3c5d7baac3cc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Size: 2048000 Samples: 2047999 Acc: 1.00\n",
"l1 regularization: 0.030000\n",
"Regularization terms: 1, Supporting variables: 0\n",
"FISTA\n",
"Total Time: 9.526724\n"
]
}
],
"source": [
"%%bash\n",
"bart pics -RI:$(bart bitmask 5):3e-2 -i150 -S data/ksp data/coilsens_fully data/pics_fully\n",
"#bart pics -l1 -r 0.03 -i 150 -S data/kSpace_upat_combined data/nlinv_coilsens data/pics3_upat"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "0a2bf699-4d04-4a76-a717-3085154e096c",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"# Fit the model:\n",
"bart mobafit -T data/echo_times_final data/pics_fully data/fit_pics_fully\n",
"\n",
"# Now some values will be very large so we can apply a threshold to obtain a mask\n",
"MAX_T2=1000\n",
"\n",
"bart threshold -M $MAX_T2 data/fit_pics_fully data/mask_pics_fully\n",
"\n",
"# Multiply the fit with the mask\n",
"bart fmac data/fit_pics_fully data/mask_pics_fully data/fit_mask_pics_fully\n",
"\n",
"# Select slice\n",
"bart slice 6 1 data/fit_mask_pics_fully data/R2_map_pics_fully\n",
"\n",
"# Invert the data to get T2\n",
"bart invert data/R2_map_pics_fully data/T2_map_pics_fully"
]
},
{
"cell_type": "markdown",
@ -959,14 +1012,14 @@
},
{
"cell_type": "code",
"execution_count": 229,
"execution_count": 17,
"id": "a9aa3845-2dc3-4e83-b68f-49b965af11ab",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"ACC_Y=2\n",
"ACC_Z=2\n",
"ACC_Y=4\n",
"ACC_Z=4\n",
"CENTER_SIZE=8\n",
"\n",
"bart upat -Y 80 -Z 16 -y $ACC_Y -z $ACC_Z -c $CENTER_SIZE data/upat"
@ -974,18 +1027,10 @@
},
{
"cell_type": "code",
"execution_count": 230,
"execution_count": 18,
"id": "ad44e09a-a74e-493e-bb3f-3cd3f7607eb6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scaling: 0.349421\n"
]
}
],
"outputs": [],
"source": [
"%%bash\n",
"bart fmac data/upat data/kSpace_transposed data/kSpace_upat\n",
@ -995,9 +1040,13 @@
"\n",
"bart nlinv -i 30 -x 80:80:16 -S data/kSpace_upat_transposed data/nlinv_upat\n",
"# bart fft -i $(bart bitmask 0 1 2) data/kSpace_upat data/fft_upat\n",
"#bart pics -RI:$(bart bitmask 5):3e-2 -i150 -S data/kSpace_upat_transposed data/nlinv_coilsens data/nlinv_upat \n",
"\n",
"# bart transpose 3 5 data/fft_upat data/fft_upat_transposed\n",
"\n",
"# Calculate the pattern\n",
"bart pattern data/kSpace_upat_transposed data/calc_pattern_upat\n",
"\n",
"# Fit the model:\n",
"bart mobafit -T data/echo_times_final data/nlinv_upat data/fit_upat\n",
"\n",
@ -1018,7 +1067,7 @@
},
{
"cell_type": "code",
"execution_count": 231,
"execution_count": 6,
"id": "5132b2af-0e1d-44b9-90ba-d6031ca4d10a",
"metadata": {},
"outputs": [
@ -1030,19 +1079,15 @@
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFAAAAAQCAIAAAAOK2+WAAAARklEQVRIie3RIRIAMAgDwdD//5mKeqYiqemtwMJw6m5J/8xS3tl0qSp70nrz13sUNqNwAIUnFDajcACFJxQ2o3AAhScUNtsCZEIXIDnDpQAAAABJRU5ErkJggg==",
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 231,
"metadata": {
"image/png": {
"width": 1000
}
},
"output_type": "execute_result"
"ename": "NameError",
"evalue": "name 'Image' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbart transpose 1 2 data/upat data/img\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbart toimg -w 1.0 data/img fig/upat_mask.png\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 3\u001b[0m \u001b[43mImage\u001b[49m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfig/upat_mask.png\u001b[39m\u001b[38;5;124m\"\u001b[39m, width\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1000\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'Image' is not defined"
]
}
],
"source": [
@ -1062,7 +1107,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 18,
"id": "0882a788-ecd2-4968-9715-a57816d66e9c",
"metadata": {},
"outputs": [
@ -1117,18 +1162,10 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 19,
"id": "d14780bc-dd5a-4710-a52b-ef491caae213",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scaling: 0.347030\n"
]
}
],
"outputs": [],
"source": [
"%%bash\n",
"# For nlinv the echos can't be in the coil dimension (3) also to make it work with the upat_combined\n",
@ -1164,7 +1201,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 20,
"id": "821f937e-64ef-4ad3-9848-df50ee3faac3",
"metadata": {},
"outputs": [
@ -1182,7 +1219,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 34,
"execution_count": 20,
"metadata": {
"image/png": {
"width": 1000
@ -1209,18 +1246,10 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 21,
"id": "3ea47c87-480b-434e-a451-f5dc246968c2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done.\n"
]
}
],
"outputs": [],
"source": [
"%%bash\n",
"bart ecalib -m1 data/kSpace_upat_combined data/upat_coilsens"
@ -1228,7 +1257,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 1,
"id": "5b6a3b3d-9bd1-4e2f-b4b1-fd33513f984c",
"metadata": {},
"outputs": [
@ -1240,7 +1269,7 @@
"l1 regularization: 0.030000\n",
"Regularization terms: 1, Supporting variables: 0\n",
"FISTA\n",
"Total Time: 6.242878\n"
"Total Time: 9.607770\n"
]
}
],
@ -1252,7 +1281,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 2,
"id": "c28b7fa1-4acb-4cfc-98b3-d8af9cf21025",
"metadata": {},
"outputs": [],
@ -1439,7 +1468,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 30,
"id": "c74d227b-ff58-4ffb-a511-be3865c5618e",
"metadata": {},
"outputs": [
@ -1450,9 +1479,10 @@
"Basis: [ 80 80 16 1 1 20 3 1 1 1 1 1 1 1 1 1 ]\n",
"Max: [ 80 80 16 1 1 1 3 1 1 1 1 1 1 1 1 1 ]\n",
"Size: 2048000 Samples: 2047999 Acc: 1.00\n",
"Regularization terms: 0, Supporting variables: 0\n",
"conjugate gradients\n",
"Total Time: 2.095993\n"
"l1 regularization: 0.030000\n",
"Regularization terms: 1, Supporting variables: 0\n",
"FISTA\n",
"Total Time: 9.596245\n"
]
}
],
@ -1475,7 +1505,7 @@
"\n",
"# Now we get a coefficient map\n",
"# bart nlinv -B data/basis data/kSpace data/coeff data/sens\n",
"bart pics -B data/basis data/ksp data/nlinv_coilsens data/coeff\n",
"bart pics -B data/basis -RI:$(bart bitmask 5):3e-2 -i150 -S data/ksp data/nlinv_coilsens data/coeff\n",
"\n",
"# From the coefficients and the basis we can get the image\n",
"bart fmac -s $(bart bitmask 6) data/basis data/coeff data/imgs\n",
@ -1486,7 +1516,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 31,
"id": "bd942687-35f8-455f-a794-922bf19eb822",
"metadata": {},
"outputs": [],
@ -1509,7 +1539,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 36,
"id": "450ddbe5-dad6-4f34-89c1-58db4ca1968c",
"metadata": {},
"outputs": [
@ -1519,10 +1549,11 @@
"text": [
"Basis: [ 80 80 16 1 1 20 3 1 1 1 1 1 1 1 1 1 ]\n",
"Max: [ 80 80 16 1 1 1 3 1 1 1 1 1 1 1 1 1 ]\n",
"Size: 2048000 Samples: 1228800 Acc: 1.67\n",
"Regularization terms: 0, Supporting variables: 0\n",
"conjugate gradients\n",
"Total Time: 2.317959\n"
"Size: 2048000 Samples: 819199 Acc: 2.50\n",
"l1 regularization: 0.030000\n",
"Regularization terms: 1, Supporting variables: 0\n",
"FISTA\n",
"Total Time: 9.529222\n"
]
}
],
@ -1530,7 +1561,7 @@
"%%bash\n",
"# Now we get a coefficient map\n",
"# bart nlinv -B data/basis data/kSpace_upat_combined data/coeff_upat data/sens_upat\n",
"bart pics -B data/basis data/kSpace_upat_combined data/nlinv_coilsens data/coeff_upat\n",
"bart pics -B data/basis -RI:$(bart bitmask 5):3e-2 -i150 -S data/kSpace_upat_combined data/nlinv_coilsens data/coeff_upat\n",
"\n",
"## Coeffs are on dim 7\n",
"\n",
@ -1547,10 +1578,111 @@
"bart invert data/R2_fit_subreco_upat data/T2_fit_subreco_upat"
]
},
{
"cell_type": "markdown",
"id": "bb1744d3-9ee0-4af0-a3a3-09ddbea9db47",
"metadata": {},
"source": [
"## Two dim USP"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "d491fd0f-5131-4496-944d-e07cb6bf7a79",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pattern creation completed. Output file: upat_combined_new\n"
]
}
],
"source": [
"%%bash\n",
"# Parameters\n",
"R_Y=2 # Undersampling factor in the Y dimension\n",
"R_Z=2 # Undersampling factor in the Z dimension\n",
"Y=80 # Dimension Y\n",
"Z=16 # Dimension Z\n",
"N_ECHO=20 # Number of ECHO shifts\n",
"CENTER_SIZE=16\n",
"\n",
"# Create the center\n",
"bart ones 2 $CENTER_SIZE $CENTER_SIZE data/mask_center_new\n",
"bart transpose 0 2 data/mask_center_new data/mask_center_new_transposed\n",
"\n",
"# Zero-pad the second (index 1) dimension to the full k-space dimension \n",
"bart resize -c 1 $Y 2 $Z data/mask_center_new_transposed data/mask_full_new\n",
"\n",
"# Create pattern with undersampling in phase and slice directions by R_Y and R_Z\n",
"bart upat -Y $Y -Z $Z -y $R_Y -z $R_Z -c 1 data/upat_new\n",
"\n",
"# Initialize the final combined pattern file\n",
"bart saxpy 1 data/mask_full_new data/upat_new data/upat_combined_new\n",
"\n",
"# Loop over N_ECHO times to apply shifts and join them\n",
"for ((i=1; i<N_ECHO; i++))\n",
"do\n",
" # Apply a circular shift of one along the phase direction\n",
" bart circshift 1 $i data/upat_new data/upat_shifted_new\n",
"\n",
" # Combine the center mask and the \n",
" bart saxpy 1 data/mask_full_new data/upat_shifted_new data/tmp\n",
"\n",
" # Join the shifted pattern along the 5th dimension \n",
" bart join 5 data/upat_combined_new data/tmp data/upat_combined_new\n",
"done\n",
"\n",
"bart threshold -B 0.1 data/upat_combined_new data/upat_combined_new\n",
"\n",
"echo \"Pattern creation completed. Output file: upat_combined_new\"\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "1c045e2a-3180-4d06-8cb5-d8d7fe2c4531",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"\n",
"bart fmac data/upat_combined_new data/ksp data/ksp_upat_new\n",
"\n",
"# Compute pattern (just to check)\n",
"bart pattern data/ksp_upat_new data/calc_pattern_upat_new\n",
"\n",
"# PICS reco\n",
"# bart pics -RI:$(bart bitmask 5):3e-2 -i150 -S data/ksp_upat_new data/nlinv_coilsens data/pics_upat_new\n",
"\n",
"# nlinv\n",
"bart nlinv -i 30 -x 80:80:16 -S data/ksp_upat_new data/pics_upat_new\n",
"\n",
"# Fit the model:\n",
"bart mobafit -T data/echo_times_final data/pics_upat_new data/fit_upat_new\n",
"\n",
"# Now some values will be very large so we can apply a threshold to obtain a mask\n",
"MAX_T2=1000\n",
"\n",
"bart threshold -M $MAX_T2 data/fit_upat_new data/mask_upat_combined_new\n",
"\n",
"# Multiply the fit with the mask\n",
"bart fmac data/fit_upat_new data/mask_upat_combined_new data/fit_mask_upat_combined_new\n",
"\n",
"# Select slice\n",
"bart slice 6 1 data/fit_mask_upat_combined_new data/R2_map_upat_combined_new\n",
"\n",
"# Invert the data to get T2\n",
"bart invert data/R2_map_upat_combined_new data/T2_map_upat_combined_new"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cde1499e-4d97-4d21-b413-a2cccc21bd04",
"id": "3754d681-ba36-4d7f-9c30-573af2cf624a",
"metadata": {},
"outputs": [],
"source": []