MRArbGrad 2.0.1__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0/MRArbGrad.egg-info}/PKG-INFO +9 -6
  2. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/MRArbGrad.egg-info/SOURCES.txt +1 -4
  3. {mrarbgrad-2.0.1/MRArbGrad.egg-info → mrarbgrad-3.0.0}/PKG-INFO +9 -6
  4. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/README.md +8 -5
  5. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/example/example_BuiltInTraj.py +6 -4
  6. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/example/example_ExternalFunction2D.py +15 -14
  7. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/example/example_ExternalSamples2D.py +11 -10
  8. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/example/example_ExternalSamples3D.py +11 -10
  9. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/Function.py +13 -27
  10. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/Utility.py +41 -1
  11. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/__init__.py +2 -2
  12. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/mag/Mag.cpp +16 -16
  13. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/mag/Mag.h +5 -18
  14. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/main.cpp +94 -96
  15. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Cones.h +4 -6
  16. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/MrTraj.h +41 -49
  17. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/MrTraj_2D.h +3 -3
  18. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Rosette.h +12 -12
  19. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Seiffert.h +4 -7
  20. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Shell3d.h +6 -6
  21. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Spiral.h +5 -5
  22. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/TrajFunc.h +1 -1
  23. mrarbgrad-2.0.1/mrarbgrad_src/ext/traj/VarDenSpiral.h → mrarbgrad-3.0.0/mrarbgrad_src/ext/traj/VDSpiral.h +16 -16
  24. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/traj/Yarnball.h +10 -10
  25. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/Intp.h +0 -2
  26. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/global.h +13 -1
  27. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/v3.h +6 -8
  28. mrarbgrad-3.0.0/mrarbgrad_src/trajfunc/__init__.py +1 -0
  29. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/trajfunc/main.py +3 -3
  30. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/pyproject.toml +2 -2
  31. mrarbgrad-2.0.1/mrarbgrad_src/TrajFunc.py +0 -47
  32. mrarbgrad-2.0.1/mrarbgrad_src/ext/mag/GradGen.cpp +0 -439
  33. mrarbgrad-2.0.1/mrarbgrad_src/ext/mag/GradGen.h +0 -191
  34. mrarbgrad-2.0.1/mrarbgrad_src/trajfunc/__init__.py +0 -1
  35. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/LICENSE +0 -0
  36. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/MANIFEST.in +0 -0
  37. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/MRArbGrad.egg-info/dependency_links.txt +0 -0
  38. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/MRArbGrad.egg-info/requires.txt +0 -0
  39. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/MRArbGrad.egg-info/top_level.txt +0 -0
  40. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/LinIntp.h +0 -0
  41. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/SplineIntp.h +0 -0
  42. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/global.cpp +0 -0
  43. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/mrarbgrad_src/ext/utility/v3.cpp +0 -0
  44. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/setup.cfg +0 -0
  45. {mrarbgrad-2.0.1 → mrarbgrad-3.0.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MRArbGrad
3
- Version: 2.0.1
3
+ Version: 3.0.0
4
4
  Summary: Gradient waveform design tool for arbitrary k-space trajectories.
5
5
  Author-email: Ryan <ryan_shanghaitech@proton.me>
6
6
  License-Expression: MIT
@@ -22,18 +22,21 @@ This toolbox is a pip package with C++ backend. The pip package can be called vi
22
22
  ```bash
23
23
  $ conda create -n magtest -y
24
24
  $ conda activate magtest
25
- $ conda install python==3.10 -y
25
+ $ conda install python==3.12 -y
26
26
  ```
27
27
 
28
- This package is **NOT** restricted to use `Python 3.10` or `numpy 1.26` (as specified in the `requirements.txt`). Feel free to adjust at your convenience, just if the package works.
28
+ This package is **NOT** restricted to use `Python 3.12`. Feel free to adjust at your convenience, just if the package works.
29
29
 
30
- To install the pip package of the proposed algorithm (including the trajectory library built on it), and also the dependencies:
30
+ To install the pip package of the proposed algorithm (including the trajectory library built on it):
31
31
  ```bash
32
- $ pip install -r requirements.txt
33
32
  $ bash install.bash
34
33
  ```
34
+ or
35
+ ```bash
36
+ $ pip install mrarbgrad
37
+ ```
35
38
 
36
- It's the best practice to use my script `install.bash` for installation. You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
39
+ You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
37
40
 
38
41
  ## Examples & Usages
39
42
  Examples for generating gradient waveforms for either built-in trajectory (trajectory library) or external trajectory (expressed by trajectory function or trajectory samples) can be found in the `example` folder.
@@ -17,12 +17,9 @@ example/example_ExternalFunction2D.py
17
17
  example/example_ExternalSamples2D.py
18
18
  example/example_ExternalSamples3D.py
19
19
  mrarbgrad_src/Function.py
20
- mrarbgrad_src/TrajFunc.py
21
20
  mrarbgrad_src/Utility.py
22
21
  mrarbgrad_src/__init__.py
23
22
  mrarbgrad_src/ext/main.cpp
24
- mrarbgrad_src/ext/mag/GradGen.cpp
25
- mrarbgrad_src/ext/mag/GradGen.h
26
23
  mrarbgrad_src/ext/mag/Mag.cpp
27
24
  mrarbgrad_src/ext/mag/Mag.h
28
25
  mrarbgrad_src/ext/traj/Cones.h
@@ -33,7 +30,7 @@ mrarbgrad_src/ext/traj/Seiffert.h
33
30
  mrarbgrad_src/ext/traj/Shell3d.h
34
31
  mrarbgrad_src/ext/traj/Spiral.h
35
32
  mrarbgrad_src/ext/traj/TrajFunc.h
36
- mrarbgrad_src/ext/traj/VarDenSpiral.h
33
+ mrarbgrad_src/ext/traj/VDSpiral.h
37
34
  mrarbgrad_src/ext/traj/Yarnball.h
38
35
  mrarbgrad_src/ext/utility/Intp.h
39
36
  mrarbgrad_src/ext/utility/LinIntp.h
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MRArbGrad
3
- Version: 2.0.1
3
+ Version: 3.0.0
4
4
  Summary: Gradient waveform design tool for arbitrary k-space trajectories.
5
5
  Author-email: Ryan <ryan_shanghaitech@proton.me>
6
6
  License-Expression: MIT
@@ -22,18 +22,21 @@ This toolbox is a pip package with C++ backend. The pip package can be called vi
22
22
  ```bash
23
23
  $ conda create -n magtest -y
24
24
  $ conda activate magtest
25
- $ conda install python==3.10 -y
25
+ $ conda install python==3.12 -y
26
26
  ```
27
27
 
28
- This package is **NOT** restricted to use `Python 3.10` or `numpy 1.26` (as specified in the `requirements.txt`). Feel free to adjust at your convenience, just if the package works.
28
+ This package is **NOT** restricted to use `Python 3.12`. Feel free to adjust at your convenience, just if the package works.
29
29
 
30
- To install the pip package of the proposed algorithm (including the trajectory library built on it), and also the dependencies:
30
+ To install the pip package of the proposed algorithm (including the trajectory library built on it):
31
31
  ```bash
32
- $ pip install -r requirements.txt
33
32
  $ bash install.bash
34
33
  ```
34
+ or
35
+ ```bash
36
+ $ pip install mrarbgrad
37
+ ```
35
38
 
36
- It's the best practice to use my script `install.bash` for installation. You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
39
+ You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
37
40
 
38
41
  ## Examples & Usages
39
42
  Examples for generating gradient waveforms for either built-in trajectory (trajectory library) or external trajectory (expressed by trajectory function or trajectory samples) can be found in the `example` folder.
@@ -8,18 +8,21 @@ This toolbox is a pip package with C++ backend. The pip package can be called vi
8
8
  ```bash
9
9
  $ conda create -n magtest -y
10
10
  $ conda activate magtest
11
- $ conda install python==3.10 -y
11
+ $ conda install python==3.12 -y
12
12
  ```
13
13
 
14
- This package is **NOT** restricted to use `Python 3.10` or `numpy 1.26` (as specified in the `requirements.txt`). Feel free to adjust at your convenience, just if the package works.
14
+ This package is **NOT** restricted to use `Python 3.12`. Feel free to adjust at your convenience, just if the package works.
15
15
 
16
- To install the pip package of the proposed algorithm (including the trajectory library built on it), and also the dependencies:
16
+ To install the pip package of the proposed algorithm (including the trajectory library built on it):
17
17
  ```bash
18
- $ pip install -r requirements.txt
19
18
  $ bash install.bash
20
19
  ```
20
+ or
21
+ ```bash
22
+ $ pip install mrarbgrad
23
+ ```
21
24
 
22
- It's the best practice to use my script `install.bash` for installation. You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
25
+ You can also install via `pip install .` but remember to delete `*.egg-info` or pip will run into bug when uninstalling this package in current folder (see comments in `install.bash`).
23
26
 
24
27
  ## Examples & Usages
25
28
  Examples for generating gradient waveforms for either built-in trajectory (trajectory library) or external trajectory (expressed by trajectory function or trajectory samples) can be found in the `example` folder.
@@ -26,16 +26,18 @@ mag.setMagTrajRep(1) # enable trajectory reparameterization (experimental)
26
26
  mag.setDbgPrint(1) # enable debug info (for benchmark purpose)
27
27
 
28
28
  # calculate gradient
29
- # lstArrK0, lstArrGrad = mag.getG_Spiral(is3D=0, **argCom); nAx = 2
30
- # lstArrK0, lstArrGrad = mag.getG_VarDenSpiral(is3D=0, **argCom); nAx = 2
31
- lstArrK0, lstArrGrad = mag.getG_VarDenSpiral_RT(is3D=0, **argCom); nAx = 2
32
- # lstArrK0, lstArrGrad = mag.getG_Rosette(is3D=0, **argCom); nAx = 2
29
+ # lstArrK0, lstArrGrad = mag.getG_Spiral(**argCom); nAx = 2
30
+ # lstArrK0, lstArrGrad = mag.getG_VDSpiral(**argCom); nAx = 2
31
+ # lstArrK0, lstArrGrad = mag.getG_VDSpiral_RT(**argCom); nAx = 2
32
+ lstArrK0, lstArrGrad = mag.getG_Rosette(**argCom); nAx = 2
33
33
  # lstArrK0, lstArrGrad = mag.getG_Rosette_Trad(**argCom); nAx = 2
34
34
  # lstArrK0, lstArrGrad = mag.getG_Shell3d(**argCom); nAx = 3
35
35
  # lstArrK0, lstArrGrad = mag.getG_Yarnball(**argCom); nAx = 3
36
36
  # lstArrK0, lstArrGrad = mag.getG_Seiffert(**argCom); nAx = 3
37
37
  # lstArrK0, lstArrGrad = mag.getG_Cones(**argCom); nAx = 3
38
38
 
39
+ # lstArrGrad = mag.gradClip(lstArrGrad, dtGrad, sLim, gLim) # clip slew/grad amp with hardware constraint
40
+
39
41
  print("")
40
42
  print(f"Intlea Num.: {len(lstArrGrad)}")
41
43
  nRO_Max = amax([arrG.shape[0] for arrG in lstArrGrad])
@@ -6,16 +6,16 @@ import mrarbgrad as mag
6
6
  gamma = 42.5756e6
7
7
  fov = 0.256
8
8
  nPix = 256
9
- dtGrad = 10e-6
10
- dtADC = 2.5e-6
9
+ dtGrad = 10e-6 * 1e-1
10
+ dtADC = 2.5e-6 * 1e-1
11
11
  sLim = 50 * gamma * fov/nPix
12
12
  gLim = 20e-3 * gamma * fov/nPix
13
13
  # gLim = 1/nPix/dtADC
14
14
 
15
15
  # Rosette
16
16
  nAx = 2
17
- om1 = 5*pi
18
- om2 = 3*pi
17
+ om1 = 19*pi
18
+ om2 = 17*pi
19
19
  def Rosette(t):
20
20
  rho = 0.5*sin(om1*t)
21
21
  return array\
@@ -28,13 +28,14 @@ def Rosette(t):
28
28
  pLim = [0,1]
29
29
 
30
30
  # derive slew-rate constrained trajectory
31
- arrG, _ = mag.calGrad4ExFunc(False, fov, nPix, sLim, gLim, dtGrad, Rosette, None, None, pLim[0], pLim[1])
32
- nRO, _ = arrG.shape
31
+ arrGrad = mag.calGrad4ExFunc(fov, nPix, sLim, gLim, dtGrad, Rosette, None, None, pLim[0], pLim[1])[0]
32
+ # arrGrad = mag.gradClip(arrGrad, dtGrad, sLim, gLim) # clip slew/grad amp with hardware constraint
33
+ nRO = arrGrad.shape[0]
33
34
 
34
- arrS = diff(arrG, axis=0)/dtGrad
35
- print(f"sMax: {max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov)}")
35
+ arrSlew = diff(arrGrad, axis=0)/dtGrad
36
+ print(f"sMax: {max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov)}")
36
37
 
37
- arrK, _ = mag.cvtGrad2Traj(arrG, dtGrad, dtADC, 0.5)
38
+ arrK = mag.cvtGrad2Traj(arrGrad, dtGrad, dtADC, 0.5)[0]
38
39
 
39
40
  # derive reference trajectory
40
41
  arrP_Ref = linspace(pLim[0], pLim[1], int(1e4))
@@ -57,21 +58,21 @@ title("k-Space")
57
58
 
58
59
  subplot(222)
59
60
  for iAx in range(nAx):
60
- plot(arrG[:,iAx]/(42.58e6)*(nPix/fov), ".-")
61
+ plot(arrGrad[:,iAx]/(42.58e6)*(nPix/fov), ".-")
61
62
  grid("on")
62
63
  title("Gradient")
63
64
 
64
65
  subplot(223, projection=None if nAx==2 else "3d")
65
- if nAx==2: plot(arrG[:,0], arrG[:,1], ".-")
66
- if nAx==3: plot(arrG[:,0], arrG[:,1], arrG[:,2], ".-")
66
+ if nAx==2: plot(arrGrad[:,0], arrGrad[:,1], ".-")
67
+ if nAx==3: plot(arrGrad[:,0], arrGrad[:,1], arrGrad[:,2], ".-")
67
68
  axis("equal")
68
69
  grid("on")
69
70
  title("g-Space")
70
71
 
71
72
  subplot(224)
72
- plot(norm(arrS,axis=-1)/(42.58e6)*(nPix/fov), ".-")
73
+ plot(norm(arrSlew,axis=-1)/(42.58e6)*(nPix/fov), ".-")
73
74
  ylim(sLim/(42.58e6)*(nPix/fov)*0.9, sLim/(42.58e6)*(nPix/fov)*1.1)
74
75
  grid("on")
75
- title(f"Slewrate, max:{max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
76
+ title(f"Slewrate, max:{max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
76
77
 
77
78
  show()
@@ -32,13 +32,14 @@ nAx = 2
32
32
 
33
33
  # derive slew-rate constrained trajectory
34
34
  for i in range(1):
35
- arrG, _ = mag.calGrad4ExSamp(False, fov, nPix, sLim, gLim, dtGrad, arrK)
36
- nRO, _ = arrG.shape
35
+ arrGrad = mag.calGrad4ExSamp(fov, nPix, sLim, gLim, dtGrad, arrK)[0]
36
+ # arrGrad = mag.gradClip(arrGrad, dtGrad, sLim, gLim) # clip slew/grad amp with hardware constraint
37
+ nRO = arrGrad.shape[0]
37
38
 
38
- arrS = diff(arrG, axis=0)/dtGrad
39
- print(f"sMax: {max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov)}")
39
+ arrSlew = diff(arrGrad, axis=0)/dtGrad
40
+ print(f"sMax: {max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov)}")
40
41
 
41
- arrK, _ = mag.cvtGrad2Traj(arrG, dtGrad, dtADC, 0.5)
42
+ arrK, _ = mag.cvtGrad2Traj(arrGrad, dtGrad, dtADC, 0.5)
42
43
  arrK += TrajFunc(pLim[0])
43
44
  print(f"Err: {norm(arrK[-1,:]-TrajFunc(pLim[1])):.1e}")
44
45
 
@@ -63,21 +64,21 @@ title("k-Space")
63
64
 
64
65
  subplot(222)
65
66
  for iAx in range(nAx):
66
- plot(arrG[:,iAx]/(42.58e6)*(nPix/fov), ".-")
67
+ plot(arrGrad[:,iAx]/(42.58e6)*(nPix/fov), ".-")
67
68
  grid("on")
68
69
  title("Gradient")
69
70
 
70
71
  subplot(223, projection=None if nAx==2 else "3d")
71
- if nAx==2: plot(arrG[:,0], arrG[:,1], ".-")
72
- if nAx==3: plot(arrG[:,0], arrG[:,1], arrG[:,2], ".-")
72
+ if nAx==2: plot(arrGrad[:,0], arrGrad[:,1], ".-")
73
+ if nAx==3: plot(arrGrad[:,0], arrGrad[:,1], arrGrad[:,2], ".-")
73
74
  axis("equal")
74
75
  grid("on")
75
76
  title("g-Space")
76
77
 
77
78
  subplot(224)
78
- plot(norm(arrS,axis=-1)/(42.58e6)*(nPix/fov), ".-")
79
+ plot(norm(arrSlew,axis=-1)/(42.58e6)*(nPix/fov), ".-")
79
80
  ylim(sLim/(42.58e6)*(nPix/fov)*0.9, sLim/(42.58e6)*(nPix/fov)*1.1)
80
81
  grid("on")
81
- title(f"Slewrate, max:{max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
82
+ title(f"Slewrate, max:{max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
82
83
 
83
84
  show()
@@ -24,13 +24,14 @@ arrK = Yarnball(arrP)
24
24
 
25
25
  # derive slew-rate constrained trajectory
26
26
  mag.setDbgPrint(1)
27
- arrG, _ = mag.calGrad4ExSamp(True, fov, nPix, sLim, gLim, dtGrad, arrK)
28
- nRO, _ = arrG.shape
27
+ arrGrad = mag.calGrad4ExSamp(fov, nPix, sLim, gLim, dtGrad, arrK)[0]
28
+ # arrGrad = mag.gradClip(arrGrad, dtGrad, sLim, gLim) # clip slew/grad amp with hardware constraint
29
+ nRO = arrGrad.shape[0]
29
30
 
30
- arrS = diff(arrG, axis=0)/dtGrad
31
- print(f"sMax: {max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov)}")
31
+ arrSlew = diff(arrGrad, axis=0)/dtGrad
32
+ print(f"sMax: {max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov)}")
32
33
 
33
- arrK, _ = mag.cvtGrad2Traj(arrG, dtGrad, dtADC, 0.5)
34
+ arrK, _ = mag.cvtGrad2Traj(arrGrad, dtGrad, dtADC, 0.5)
34
35
 
35
36
  # derive reference trajectory
36
37
  arrP_Ref = linspace(pLim[0], pLim[1], int(1e4))
@@ -51,21 +52,21 @@ title("k-Space")
51
52
 
52
53
  subplot(222)
53
54
  for iAx in range(nAx):
54
- plot(arrG[:,iAx]/(42.58e6)*(nPix/fov), ".-")
55
+ plot(arrGrad[:,iAx]/(42.58e6)*(nPix/fov), ".-")
55
56
  grid("on")
56
57
  title("Gradient")
57
58
 
58
59
  subplot(223, projection=None if nAx==2 else "3d")
59
- if nAx==2: plot(arrG[:,0], arrG[:,1], ".-")
60
- if nAx==3: plot(arrG[:,0], arrG[:,1], arrG[:,2], ".-")
60
+ if nAx==2: plot(arrGrad[:,0], arrGrad[:,1], ".-")
61
+ if nAx==3: plot(arrGrad[:,0], arrGrad[:,1], arrGrad[:,2], ".-")
61
62
  axis("equal")
62
63
  grid("on")
63
64
  title("g-Space")
64
65
 
65
66
  subplot(224)
66
- plot(norm(arrS,axis=-1)/(42.58e6)*(nPix/fov), ".-")
67
+ plot(norm(arrSlew,axis=-1)/(42.58e6)*(nPix/fov), ".-")
67
68
  ylim(sLim/(42.58e6)*(nPix/fov)*0.9, sLim/(42.58e6)*(nPix/fov)*1.1)
68
69
  grid("on")
69
- title(f"Slewrate, max:{max(norm(arrS,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
70
+ title(f"Slewrate, max:{max(norm(arrSlew,axis=-1))/(42.58e6)*(nPix/fov):.3f}")
70
71
 
71
72
  show()
@@ -9,7 +9,6 @@ goldang = getGoldang()
9
9
 
10
10
  def calGrad4ExFunc\
11
11
  (
12
- is3D: bool = False,
13
12
  fov: float64 = 0.256,
14
13
  nPix: int64 = 256,
15
14
 
@@ -30,7 +29,6 @@ def calGrad4ExFunc\
30
29
  '''
31
30
  return ext.calGrad4ExFunc\
32
31
  (
33
- int64(is3D),
34
32
  float64(fov),
35
33
  int64(nPix),
36
34
 
@@ -48,7 +46,6 @@ def calGrad4ExFunc\
48
46
 
49
47
  def calGrad4ExSamp\
50
48
  (
51
- is3D: bool = False,
52
49
  fov: float64 = 0.256,
53
50
  nPix: int64 = 256,
54
51
 
@@ -64,7 +61,6 @@ def calGrad4ExSamp\
64
61
  '''
65
62
  return ext.calGrad4ExSamp\
66
63
  (
67
- int64(is3D),
68
64
  float64(fov),
69
65
  int64(nPix),
70
66
 
@@ -77,7 +73,6 @@ def calGrad4ExSamp\
77
73
 
78
74
  def getG_Spiral\
79
75
  (
80
- is3D: bool = False,
81
76
  fov: float64 = 0.256,
82
77
  nPix: int64 = 256,
83
78
 
@@ -85,6 +80,7 @@ def getG_Spiral\
85
80
  gLim: float64 = 50e-3 * 42.5756e6 * 0.256 / 256,
86
81
  dt: float64 = 10e-6,
87
82
 
83
+ nSlice: int64 = 1,
88
84
  kRhoPhi: float64 = 0.5 / (4 * pi)
89
85
  ) -> tuple[list[NDArray], list[NDArray]]:
90
86
  '''
@@ -93,7 +89,6 @@ def getG_Spiral\
93
89
  '''
94
90
  return ext.getG_Spiral\
95
91
  (
96
- int64(is3D),
97
92
  float64(fov),
98
93
  int64(nPix),
99
94
 
@@ -101,19 +96,20 @@ def getG_Spiral\
101
96
  float64(gLim),
102
97
  float64(dt),
103
98
 
99
+ int64(nSlice),
104
100
  float64(kRhoPhi)
105
101
  )
106
102
 
107
- def getG_VarDenSpiral\
103
+ def getG_VDSpiral\
108
104
  (
109
- is3D: bool = False,
110
105
  fov: float64 = 0.256,
111
106
  nPix: int64 = 256,
112
107
 
113
108
  sLim: float64 = 50 * 42.5756e6 * 0.256 / 256,
114
109
  gLim: float64 = 50e-3 * 42.5756e6 * 0.256 / 256,
115
110
  dt: float64 = 10e-6,
116
-
111
+
112
+ nSlice: int64 = 1,
117
113
  kRhoPhi0: float64 = 0.5 / (8 * pi),
118
114
  kRhoPhi1: float64 = 0.5 / (2 * pi),
119
115
  ) -> tuple[list[NDArray], list[NDArray]]:
@@ -121,9 +117,8 @@ def getG_VarDenSpiral\
121
117
  :return: list of trajectory start, list of gradient waveforms
122
118
  :rtype: tuple[list[NDArray], list[NDArray]]
123
119
  '''
124
- return ext.getG_VarDenSpiral\
120
+ return ext.getG_VDSpiral\
125
121
  (
126
- int64(is3D),
127
122
  float64(fov),
128
123
  int64(nPix),
129
124
 
@@ -131,13 +126,13 @@ def getG_VarDenSpiral\
131
126
  float64(gLim),
132
127
  float64(dt),
133
128
 
129
+ int64(nSlice),
134
130
  float64(kRhoPhi0),
135
131
  float64(kRhoPhi1)
136
132
  )
137
133
 
138
- def getG_VarDenSpiral_RT\
134
+ def getG_VDSpiral_RT\
139
135
  (
140
- is3D: bool = False,
141
136
  fov: float64 = 0.256,
142
137
  nPix: int64 = 256,
143
138
 
@@ -153,9 +148,8 @@ def getG_VarDenSpiral_RT\
153
148
  :return: list of trajectory start, list of gradient waveforms
154
149
  :rtype: tuple[list[NDArray], list[NDArray]]
155
150
  '''
156
- return ext.getG_VarDenSpiral_RT\
151
+ return ext.getG_VDSpiral_RT\
157
152
  (
158
- int64(is3D),
159
153
  float64(fov),
160
154
  int64(nPix),
161
155
 
@@ -171,7 +165,6 @@ def getG_VarDenSpiral_RT\
171
165
 
172
166
  def getG_Rosette\
173
167
  (
174
- is3D: bool = False,
175
168
  fov: float64 = 0.256,
176
169
  nPix: int64 = 256,
177
170
 
@@ -179,6 +172,7 @@ def getG_Rosette\
179
172
  gLim: float64 = 50e-3 * 42.5756e6 * 0.256 / 256,
180
173
  dt: float64 = 10e-6,
181
174
 
175
+ nSlice: int64 = 1,
182
176
  om1: float64 = 5*pi,
183
177
  om2: float64 = 3*pi,
184
178
  tMax: float64 = 1e0,
@@ -189,7 +183,6 @@ def getG_Rosette\
189
183
  '''
190
184
  return ext.getG_Rosette\
191
185
  (
192
- int64(is3D),
193
186
  float64(fov),
194
187
  int64(nPix),
195
188
 
@@ -197,6 +190,7 @@ def getG_Rosette\
197
190
  float64(gLim),
198
191
  float64(dt),
199
192
 
193
+ int64(nSlice),
200
194
  float64(om1),
201
195
  float64(om2),
202
196
  float64(tMax)
@@ -204,7 +198,6 @@ def getG_Rosette\
204
198
 
205
199
  def getG_Rosette_Trad\
206
200
  (
207
- is3D: bool = False,
208
201
  fov: float64 = 0.256,
209
202
  nPix: int64 = 256,
210
203
 
@@ -212,6 +205,7 @@ def getG_Rosette_Trad\
212
205
  gLim: float64 = 50e-3 * 42.5756e6 * 0.256 / 256,
213
206
  dt: float64 = 10e-6,
214
207
 
208
+ nSlice: int64 = 1,
215
209
  om1: float64 = 5*pi,
216
210
  om2: float64 = 3*pi,
217
211
  tMax: float64 = 1e0,
@@ -223,7 +217,6 @@ def getG_Rosette_Trad\
223
217
  '''
224
218
  return ext.getG_Rosette_Trad\
225
219
  (
226
- int64(is3D),
227
220
  float64(fov),
228
221
  int64(nPix),
229
222
 
@@ -231,6 +224,7 @@ def getG_Rosette_Trad\
231
224
  float64(gLim),
232
225
  float64(dt),
233
226
 
227
+ int64(nSlice),
234
228
  float64(om1),
235
229
  float64(om2),
236
230
  float64(tMax),
@@ -239,7 +233,6 @@ def getG_Rosette_Trad\
239
233
 
240
234
  def getG_Shell3d\
241
235
  (
242
- is3D: bool = False,
243
236
  fov: float64 = 0.256,
244
237
  nPix: int64 = 256,
245
238
 
@@ -255,7 +248,6 @@ def getG_Shell3d\
255
248
  '''
256
249
  return ext.getG_Shell3d\
257
250
  (
258
- int64(is3D),
259
251
  float64(fov),
260
252
  int64(nPix),
261
253
 
@@ -268,7 +260,6 @@ def getG_Shell3d\
268
260
 
269
261
  def getG_Yarnball\
270
262
  (
271
- is3D: bool = False,
272
263
  fov: float64 = 0.256,
273
264
  nPix: int64 = 256,
274
265
 
@@ -284,7 +275,6 @@ def getG_Yarnball\
284
275
  '''
285
276
  return ext.getG_Yarnball\
286
277
  (
287
- int64(is3D),
288
278
  float64(fov),
289
279
  int64(nPix),
290
280
 
@@ -297,7 +287,6 @@ def getG_Yarnball\
297
287
 
298
288
  def getG_Seiffert\
299
289
  (
300
- is3D: bool = False,
301
290
  fov: float64 = 0.256,
302
291
  nPix: int64 = 256,
303
292
 
@@ -314,7 +303,6 @@ def getG_Seiffert\
314
303
  '''
315
304
  return ext.getG_Seiffert\
316
305
  (
317
- int64(is3D),
318
306
  float64(fov),
319
307
  int64(nPix),
320
308
 
@@ -328,7 +316,6 @@ def getG_Seiffert\
328
316
 
329
317
  def getG_Cones\
330
318
  (
331
- is3D: bool = False,
332
319
  fov: float64 = 0.256,
333
320
  nPix: int64 = 256,
334
321
 
@@ -344,7 +331,6 @@ def getG_Cones\
344
331
  '''
345
332
  return ext.getG_Cones\
346
333
  (
347
- int64(is3D),
348
334
  float64(fov),
349
335
  int64(nPix),
350
336
 
@@ -1,6 +1,6 @@
1
1
  from numpy import *
2
+ from numpy.linalg import norm
2
3
  from numpy.typing import *
3
- from matplotlib.pyplot import *
4
4
 
5
5
  goldrat = (1+sqrt(5))/2
6
6
  goldang = (2*pi)/(1+goldrat)
@@ -8,6 +8,46 @@ goldang = (2*pi)/(1+goldrat)
8
8
  getGoldrat = lambda: goldrat
9
9
  getGoldang = lambda: goldang
10
10
 
11
+ def gradClip(lstArrGrad:list[NDArray]|NDArray, dt:float, sLim:float, gLim:float) -> list[NDArray]|NDArray:
12
+ """
13
+ Clip the slewrate and gradient amlitude of a list of gradient waveforms
14
+
15
+ Args:
16
+ lstArrGrad: list of gradient waveforms
17
+ sLim: slewrate amplitude limit
18
+ gLim: gradient amplitude limit
19
+
20
+ Returns:
21
+ Clipped gradient waveforms
22
+ """
23
+ if isinstance(lstArrGrad, ndarray): _lstArrGrad = [lstArrGrad.copy()]
24
+ else: _lstArrGrad = lstArrGrad.copy()
25
+ nPE = len(_lstArrGrad)
26
+ for iPE in range(nPE):
27
+ # slew-rate clipping
28
+ arrGrad = _lstArrGrad[iPE]
29
+ arrSlew = diff(arrGrad, 1, 0)/dt
30
+ arrSlewNorm = norm(arrSlew, axis=-1)
31
+ arrSlewNorm[where(arrSlewNorm==0)] += 1e-6
32
+ arrSlewUnit = arrSlew/arrSlewNorm[:,newaxis]
33
+ clip(arrSlewNorm, None, sLim, out=arrSlewNorm)
34
+ arrSlew = arrSlewUnit*arrSlewNorm[:,newaxis]
35
+ # gradient clipping
36
+ arrGrad[:,:] = arrGrad[0,:]
37
+ arrGrad[1:,:] += cumsum(arrSlew*dt, axis=0)
38
+ arrGradNorm = norm(arrGrad, axis=-1)
39
+ arrGradNorm[where(arrGradNorm==0)] += 1e-6
40
+ arrGradUnit = arrGrad/arrGradNorm[:,newaxis]
41
+ clip(arrGradNorm, None, gLim, out=arrGradNorm)
42
+ arrGrad = arrGradUnit*arrGradNorm[:,newaxis]
43
+ #
44
+ _lstArrGrad[iPE] = arrGrad
45
+
46
+ if isinstance(lstArrGrad, ndarray):
47
+ return _lstArrGrad[0]
48
+ else:
49
+ return _lstArrGrad
50
+
11
51
  def rand3d(i:int|NDArray, nAx:int=3, kx=sqrt(2), ky=sqrt(3), kz=sqrt(7)) -> NDArray:
12
52
  return (hstack if size(i)==1 else vstack)\
13
53
  ([
@@ -1,6 +1,6 @@
1
1
  from .Function import calGrad4ExFunc, calGrad4ExSamp
2
- from .Function import getG_Cones, getG_Rosette, getG_Rosette_Trad, getG_Seiffert, getG_Shell3d, getG_Spiral, getG_VarDenSpiral, getG_VarDenSpiral_RT, getG_Yarnball
2
+ from .Function import getG_Cones, getG_Rosette, getG_Rosette_Trad, getG_Seiffert, getG_Shell3d, getG_Spiral, getG_VDSpiral, getG_VDSpiral_RT, getG_Yarnball
3
3
  from .Function import setSolverMtg, setTrajRev, setGoldAng, setShuf, setMaxG0, setMaxG1, setExGEnd, setMagOverSamp, setMagSFS, setMagGradRep, setMagTrajRep, setDbgPrint
4
- from .Utility import _calDiaphony, rotate, _calJacElip, _calCompElipInt, _calSphFibPt, cvtGrad2Traj, getGoldang, getGoldrat, rand3d
4
+ from .Utility import _calDiaphony, rotate, _calJacElip, _calCompElipInt, _calSphFibPt, cvtGrad2Traj, getGoldang, getGoldrat, rand3d, gradClip
5
5
 
6
6
  from . import trajfunc