Note
Go to the end to download the full example code.
Select the FOV and target resolution of the phantom#
from snake.core import Phantom, SimConfig, GreConfig
from snake.core.engine.utils import get_ideal_phantom
from snake.toolkit.plotting import axis3dcut
shape = (90, 110,90) Original FOV And size of the phantom
shape = (181, 217, 181)
fov_mm = (181, 217, 181)
TR = 50
TE = 30
FA = 40 # np.degrees(np.arccos(np.exp((-TR/2000))))
field = "7T" # "1T5"
sim_conf = SimConfig(
max_sim_time=3, seq=GreConfig(TR=TR, TE=TE, FA=FA), fov_mm=fov_mm, shape=shape
)
sim_conf.hardware.n_coils = 32 # Update to get multi coil results.
sim_conf.hardware.field_strength = 7
sim_conf.res_mm
(1.0, 1.0, 1.0)
phantom = Phantom.from_brainweb(sub_id=4, sim_conf=sim_conf, tissue_file="tissue_1T5")
Traceback (most recent call last):
File "/home/runner/work/snake-fmri/snake-fmri/examples/anatomical/example_fov_select.py", line 30, in <module>
phantom = Phantom.from_brainweb(sub_id=4, sim_conf=sim_conf, tissue_file="tissue_1T5")
File "/home/runner/work/snake-fmri/snake-fmri/src/snake/core/phantom/static.py", line 112, in from_brainweb
tissues_mask = get_mri(sub_id, contrast="fuzzy").astype(np.float32)
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/brainweb_dl/mri.py", line 173, in get_mri
data = _get_mri_sub20(
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/brainweb_dl/mri.py", line 91, in _get_mri_sub20
filename = get_brainweb20(
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/brainweb_dl/_brainweb.py", line 329, in get_brainweb20
Parallel(n_jobs=-1, backend="threading")(
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 2007, in __call__
return output if self.return_generator else list(output)
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 1650, in _get_outputs
yield from self._retrieve()
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 1754, in _retrieve
self._raise_error_fast()
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 1789, in _raise_error_fast
error_job.get_result(self.timeout)
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 745, in get_result
return self._return_or_raise()
File "/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/joblib/parallel.py", line 763, in _return_or_raise
raise self._result
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='brainweb.bic.mni.mcgill.ca', port=80): Max retries exceeded with url: /cgi/brainweb1/?do_download_alias=subject04_bck&format_value=raw_short&zip_value=gnuzip&download_for_real=%5BStart+download%21%5D (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7f2a322094e0>, 'Connection to brainweb.bic.mni.mcgill.ca timed out. (connect timeout=None)'))
sim_conf
from snake.core.handlers.fov import FOVHandler
# the center and size target_res are all in millimeters.
fov_handler = FOVHandler(
center=(90, 110, 100),
size=(192, 192, 128),
angles=(5, 0, 0),
target_res=(2.0, 2.0, 2.0),
)
new_phantom = fov_handler.get_static(phantom, sim_conf)
new_contrast = get_ideal_phantom(new_phantom, sim_conf)
new_contrast.shape
axis3dcut(new_contrast.T, z_score=None, cuts=(0.5, 0.6, 0.5))
Total running time of the script: (2 minutes 14.456 seconds)