Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix in ext_test_report() #205

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

`Compatible with Pulseq 1.4.0`


🚨🚨🚨 **NOTE:** This is the `dev` branch which hosts the bleeding edge version. For the most recent, stable release,
switch to the `master` branch by clicking [here](https://github.com/imr-framework/pypulseq/tree/master). 🚨🚨🚨

## Table of contents 🧾
1. [👥 Contributors][section-contributors]
2. [📚 Citations][section-relevant-literature]
Expand Down
3 changes: 2 additions & 1 deletion pypulseq/Sequence/ext_test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def ext_test_report(self) -> str:
TR = t_ex_tmp1[0] - t_ex_tmp[-1]

# Check sequence dimensionality and spatial resolution
k_extent = np.max(np.abs(k_traj_adc), axis=1)
# Small error made for non-symmetric k-space, e.g. if you sample from -32 to +31 with 64 samples
k_extent = 0.5 * (np.max(k_traj_adc, axis=1) - np.min(k_traj_adc, axis=1))
k_scale = np.max(k_extent)
is_cartesian = False
if k_scale != 0:
Expand Down
258 changes: 258 additions & 0 deletions pypulseq/seq_examples/notebooks/ESMRMB_DEMO_GRE_20211215.ipynb
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": []
}
]
}