-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
258 additions
and
0 deletions.
There are no files selected for viewing
258 changes: 258 additions & 0 deletions
258
pypulseq/seq_examples/notebooks/ESMRMB_DEMO_GRE_20211215.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"name": "ESMRMB_DEMO_20211215.ipynb", | ||
"provenance": [], | ||
"collapsed_sections": [], | ||
"toc_visible": true | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# **ESMRMB 2021 PyPulseq LIVE DEMO** - 12/15/2021" | ||
], | ||
"metadata": { | ||
"id": "hc3VbKKCOidq" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "AuVzrkgEaVTG" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install pypulseq" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import pypulseq" | ||
], | ||
"metadata": { | ||
"id": "hZqtcYtQXhGN" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"### **IMPORT PACKAGES**" | ||
], | ||
"metadata": { | ||
"id": "dXeeFq6Bc5-9" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import math\n", | ||
"\n", | ||
"import numpy as np\n", | ||
"from matplotlib import pyplot as plt\n", | ||
"\n", | ||
"import pypulseq as pp" | ||
], | ||
"metadata": { | ||
"id": "cwuaHdp_a8ub" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"#### **SETUP**" | ||
], | ||
"metadata": { | ||
"id": "qQ7uenQcdAWA" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# ======\n", | ||
"# SETUP\n", | ||
"# ======\n", | ||
"# Create a new sequence object\n", | ||
"seq = pp.Sequence()\n", | ||
"\n", | ||
"# Define FOV and resolution\n", | ||
"fov = 256e-3\n", | ||
"Nx = 256\n", | ||
"Ny = 256\n", | ||
"alpha = 10 # flip angle\n", | ||
"slice_thickness = 3e-3 # slice\n", | ||
"# TE = np.array([7.38]) * 1e-3 # give a vector here to have multiple TEs (e.g. for field mapping)\n", | ||
"TE = np.array([4.3e-3])\n", | ||
"TR = 10e-3\n", | ||
"\n", | ||
"rf_spoiling_inc = 117 # RF spoiling increment\n", | ||
"\n", | ||
"system = pp.Opts(max_grad=28, grad_unit='mT/m', max_slew=150, slew_unit='T/m/s', rf_ringdown_time=20e-6,\n", | ||
" rf_dead_time=100e-6, adc_dead_time=10e-6)" | ||
], | ||
"metadata": { | ||
"id": "EnvyC9kDbHwE" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"#### **CREATE EVENTS**" | ||
], | ||
"metadata": { | ||
"id": "JEUIGiM0dZqG" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# ======\n", | ||
"# CREATE EVENTS\n", | ||
"# ======\n", | ||
"rf, gz, gzr = pp.make_sinc_pulse(flip_angle=alpha * math.pi / 180, duration=3e-3, slice_thickness=slice_thickness,\n", | ||
" apodization=0.5, time_bw_product=4, system=system, return_gz=True)\n", | ||
"# Define other gradients and ADC events\n", | ||
"delta_k = 1 / fov\n", | ||
"gx = pp.make_trapezoid(channel='x', flat_area=Nx * delta_k, flat_time=3.2e-3, system=system)\n", | ||
"adc = pp.make_adc(num_samples=Nx, duration=gx.flat_time, delay=gx.rise_time, system=system)\n", | ||
"gx_pre = pp.make_trapezoid(channel='x', area=-gx.area / 2, duration=1e-3, system=system)\n", | ||
"gz_reph = pp.make_trapezoid(channel='z', area=-gz.area / 2, duration=1e-3, system=system)\n", | ||
"phase_areas = (np.arange(Ny) - Ny / 2) * delta_k\n", | ||
"\n", | ||
"# gradient spoiling\n", | ||
"gx_spoil = pp.make_trapezoid(channel='x', area=2 * Nx * delta_k, system=system)\n", | ||
"gz_spoil = pp.make_trapezoid(channel='z', area=4 / slice_thickness, system=system)\n", | ||
"\n", | ||
"# Calculate timing\n", | ||
"delay_TE = np.ceil((TE - pp.calc_duration(gx_pre) - gz.fall_time - gz.flat_time / 2 - pp.calc_duration(\n", | ||
" gx) / 2) / seq.grad_raster_time) * seq.grad_raster_time\n", | ||
"delay_TR = np.ceil((TR - pp.calc_duration(gz) - pp.calc_duration(gx_pre) - pp.calc_duration(\n", | ||
" gx) - delay_TE) / seq.grad_raster_time) * seq.grad_raster_time\n", | ||
"\n", | ||
"assert np.all(delay_TE >= 0)\n", | ||
"assert np.all(delay_TR >= pp.calc_duration(gx_spoil, gz_spoil))\n", | ||
"\n", | ||
"rf_phase = 0\n", | ||
"rf_inc = 0\n" | ||
], | ||
"metadata": { | ||
"id": "2TXWjpBkdVMm" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"#### **CONSTRUCT SEQUENCE**" | ||
], | ||
"metadata": { | ||
"id": "zBlSefhqdhix" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# ======\n", | ||
"# CONSTRUCT SEQUENCE\n", | ||
"# ======\n", | ||
"# Loop over phase encodes and define sequence blocks\n", | ||
"for i in range(Ny):\n", | ||
" for j in range(len(TE)):\n", | ||
" rf.phase_offset = rf_phase / 180 * np.pi\n", | ||
" adc.phase_offset = rf_phase / 180 * np.pi\n", | ||
" rf_inc = divmod(rf_inc + rf_spoiling_inc, 360.0)[1]\n", | ||
" rf_phase = divmod(rf_phase + rf_inc, 360.0)[1]\n", | ||
"\n", | ||
" seq.add_block(rf, gz)\n", | ||
" gy_pre = pp.make_trapezoid(channel='y', area=phase_areas[i], duration=pp.calc_duration(gx_pre), system=system)\n", | ||
" seq.add_block(gx_pre, gy_pre, gz_reph)\n", | ||
" seq.add_block(pp.make_delay(delay_TE[j]))\n", | ||
" seq.add_block(gx, adc)\n", | ||
" gy_pre.amplitude = -gy_pre.amplitude\n", | ||
" seq.add_block(pp.make_delay(delay_TR[j]), gx_spoil, gy_pre, gz_spoil)" | ||
], | ||
"metadata": { | ||
"id": "rOM1mAKfdb2t" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"#### **VISUALIZE**" | ||
], | ||
"metadata": { | ||
"id": "i5zQHVxadmTa" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# ======\n", | ||
"# VISUALIZATION\n", | ||
"# ======\n", | ||
"seq.plot(time_range=[0, TR])" | ||
], | ||
"metadata": { | ||
"id": "jI-QNyKkdpO7" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"#### **DOWNLOAD `.SEQ` FILE**" | ||
], | ||
"metadata": { | ||
"id": "YkctaLKud8uV" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"from google.colab import files\n", | ||
"\n", | ||
"seq.write('esmrmb_demo_20211215.seq')\n", | ||
"\n", | ||
"files.download('esmrmb_demo_20211215.seq')" | ||
], | ||
"metadata": { | ||
"id": "Kr1KW5JkdqcS" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"" | ||
], | ||
"metadata": { | ||
"id": "l9IZS6R-eN_j" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |