-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path00_trajectory3D.py
More file actions
80 lines (65 loc) · 2.29 KB
/
Copy path00_trajectory3D.py
File metadata and controls
80 lines (65 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Generate trajectories for the benchmarks.
This script generates 3D trajectories for MRI benchmarks using the mrinufft library.
It allows setting the shape of the 3D image and the resolution. The generated trajectories
can be of different types (spiral, floret, Seiffert spiral) and are saved to files.
Usage:
python 00_trajectory3D.py shape_dim1 shape_dim2 shape_dim3 --res resolution
Output:
Files containing the generated trajectories saved in the 'trajs' directory.
"""
import os
import numpy as np
from mrinufft.trajectories import (
initialize_3D_floret,
initialize_2D_spiral,
stack,
initialize_3D_seiffert_spiral,
)
from mrinufft.io import write_trajectory
import argparse
def get_parser():
"""
Create and return an argument parser for the script.
"""
parser = argparse.ArgumentParser(
description="Generate 3D trajectories for the benchmarks."
)
parser.add_argument(
"shape",
type=int,
nargs=3,
default=[192, 192, 128],
help="Shape of the 3D image.",
)
parser.add_argument("--res", type=float, default=0.5, help="Resolution.")
return parser
if __name__ == "__main__":
# Create an argument parser and parse the command line arguments
parser = get_parser()
args = parser.parse_args()
# Extract 3D shape and field of view (FOV) from arguments
SHAPE3D = args.shape
FOV = np.array(SHAPE3D) * args.res
# Base string for filenames
base_string = f"{SHAPE3D[0]}x{SHAPE3D[1]}x{SHAPE3D[2]}_{args.res}"
# Generate and save stack of spiral trajectories
stack_of_spiral = stack(
initialize_2D_spiral(Nc=64, Ns=10240, nb_revolutions=7), nb_stacks=208
)
write_trajectory(
stack_of_spiral,
FOV,
SHAPE3D,
os.path.join("trajs", f"stack_of_spiral_{base_string}"),
)
# Generate and save floret trajectories
floret = initialize_3D_floret(Nc=3994 // 6, Ns=10240, nb_revolutions=6)
write_trajectory(
floret, FOV, SHAPE3D, os.path.join("trajs", f"floret_{base_string}")
)
# Generate and save seiffert Spiraltrajectories
seiffert = initialize_3D_seiffert_spiral(Nc=3994 // 6, Ns=10240, nb_revolutions=6)
write_trajectory(
seiffert, FOV, SHAPE3D, os.path.join("trajs", f"seiffert_{base_string}")
)