nutate 0.1.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 (55) hide show
  1. nutate-0.1.0/.github/workflows/ci.yml +23 -0
  2. nutate-0.1.0/.github/workflows/release.yml +62 -0
  3. nutate-0.1.0/.gitignore +9 -0
  4. nutate-0.1.0/CHANGELOG.md +26 -0
  5. nutate-0.1.0/CITATION.cff +10 -0
  6. nutate-0.1.0/LICENSE +202 -0
  7. nutate-0.1.0/NOTICE +1 -0
  8. nutate-0.1.0/PKG-INFO +211 -0
  9. nutate-0.1.0/README.md +174 -0
  10. nutate-0.1.0/examples/b1_abstruse.py +39 -0
  11. nutate-0.1.0/examples/b1_chirp.py +32 -0
  12. nutate-0.1.0/examples/b1_chorus.py +44 -0
  13. nutate-0.1.0/examples/b1_composite.py +22 -0
  14. nutate-0.1.0/examples/b1_double_chirp.py +42 -0
  15. nutate-0.1.0/examples/b1_hard.py +30 -0
  16. nutate-0.1.0/examples/chirp.py +20 -0
  17. nutate-0.1.0/examples/chirp_rewind.py +26 -0
  18. nutate-0.1.0/examples/chorus.py +45 -0
  19. nutate-0.1.0/examples/composite.py +29 -0
  20. nutate-0.1.0/examples/compressed_chorus_epr.py +69 -0
  21. nutate-0.1.0/examples/hard_pulse.py +22 -0
  22. nutate-0.1.0/examples/waveform.py +43 -0
  23. nutate-0.1.0/pyproject.toml +68 -0
  24. nutate-0.1.0/src/nutate/__init__.py +36 -0
  25. nutate-0.1.0/src/nutate/_format.py +20 -0
  26. nutate-0.1.0/src/nutate/_scene.py +422 -0
  27. nutate-0.1.0/src/nutate/b1.py +91 -0
  28. nutate-0.1.0/src/nutate/profiles.py +177 -0
  29. nutate-0.1.0/src/nutate/pulses/__init__.py +8 -0
  30. nutate-0.1.0/src/nutate/pulses/composite/__init__.py +5 -0
  31. nutate-0.1.0/src/nutate/pulses/composite/composite.py +59 -0
  32. nutate-0.1.0/src/nutate/pulses/swept_frequency/__init__.py +17 -0
  33. nutate-0.1.0/src/nutate/pulses/swept_frequency/chirp.py +68 -0
  34. nutate-0.1.0/src/nutate/pulses/swept_frequency/chorus.py +97 -0
  35. nutate-0.1.0/src/nutate/pulses/swept_frequency/hs.py +31 -0
  36. nutate-0.1.0/src/nutate/pulses/swept_frequency/phase_correction.py +35 -0
  37. nutate-0.1.0/src/nutate/render.py +268 -0
  38. nutate-0.1.0/src/nutate/run.py +127 -0
  39. nutate-0.1.0/src/nutate/segment.py +155 -0
  40. nutate-0.1.0/src/nutate/simulate.py +222 -0
  41. nutate-0.1.0/tests/conftest.py +7 -0
  42. nutate-0.1.0/tests/helpers.py +18 -0
  43. nutate-0.1.0/tests/test_b1.py +73 -0
  44. nutate-0.1.0/tests/test_chorus.py +77 -0
  45. nutate-0.1.0/tests/test_composite.py +36 -0
  46. nutate-0.1.0/tests/test_examples.py +162 -0
  47. nutate-0.1.0/tests/test_format.py +20 -0
  48. nutate-0.1.0/tests/test_packaging.py +40 -0
  49. nutate-0.1.0/tests/test_profiles.py +77 -0
  50. nutate-0.1.0/tests/test_render.py +260 -0
  51. nutate-0.1.0/tests/test_run.py +142 -0
  52. nutate-0.1.0/tests/test_segment.py +111 -0
  53. nutate-0.1.0/tests/test_simulate.py +163 -0
  54. nutate-0.1.0/tests/test_swept_frequency.py +79 -0
  55. nutate-0.1.0/uv.lock +1295 -0
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ workflow_call: # the release workflow runs the tests first
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
15
+ steps:
16
+ - uses: actions/checkout@v7
17
+ - uses: actions/setup-python@v7
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - uses: pyvista/setup-headless-display-action@v5
21
+ - run: pip install -e ".[dev]"
22
+ - run: ruff check .
23
+ - run: pytest -v
@@ -0,0 +1,62 @@
1
+ name: Release
2
+
3
+ # Push a tag vX.Y.Z matching the version in pyproject.toml: the tests run, then the package
4
+ # is built, published to PyPI (trusted publishing, no token) and attached to a GitHub release.
5
+
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+
10
+ jobs:
11
+ test:
12
+ uses: ./.github/workflows/ci.yml
13
+
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v7
18
+ - uses: actions/setup-python@v7
19
+ with:
20
+ python-version: "3.13"
21
+ - name: Check the tag matches the package version
22
+ run: |
23
+ version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
24
+ if [ "${GITHUB_REF_NAME#v}" != "$version" ]; then
25
+ echo "::error::tag $GITHUB_REF_NAME does not match version $version in pyproject.toml"
26
+ exit 1
27
+ fi
28
+ - run: python -m pip install build twine
29
+ - run: python -m build
30
+ - run: twine check --strict dist/*
31
+ - uses: actions/upload-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+
36
+ publish:
37
+ needs: [test, build]
38
+ runs-on: ubuntu-latest
39
+ environment: pypi
40
+ permissions:
41
+ id-token: write # trusted publishing
42
+ steps:
43
+ - uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+ - uses: pypa/gh-action-pypi-publish@release/v1
48
+
49
+ github-release:
50
+ needs: publish
51
+ runs-on: ubuntu-latest
52
+ permissions:
53
+ contents: write
54
+ steps:
55
+ - uses: actions/download-artifact@v4
56
+ with:
57
+ name: dist
58
+ path: dist/
59
+ - uses: softprops/action-gh-release@v2
60
+ with:
61
+ generate_release_notes: true
62
+ files: dist/*
@@ -0,0 +1,9 @@
1
+ output/
2
+ .venv/
3
+ __pycache__/
4
+ *.egg-info
5
+ .idea/
6
+ .DS_Store
7
+ .superpowers/
8
+ dist/
9
+ build/
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.1.0] - 2026-10-19
8
+
9
+ First release.
10
+
11
+ ### Added
12
+
13
+ - Rotating-frame Bloch simulation of any pulse sequence for many offsets at once, stepped
14
+ with the exact SU(2) propagator; phase cycling and drive (B1) amplitude scaling.
15
+ - Pulses as a waveform normalised to 1 plus its Rabi frequency: `nt.waveform` from
16
+ amplitude and phase or I and Q, with `rabi` or the hard 90° length `t90`; `nt.delay` for
17
+ free precession.
18
+ - `nt.run`: one call from a pulse or sequence to a Bloch-sphere video, a still, B1
19
+ robustness figures (offset × B1 map, surface, phase sensitivity) or interactive windows.
20
+ - Rendering with PyVista to MP4/GIF and PNG or an interactive viewer: arrows or ribbons,
21
+ fading trails, drive amplitude and phase insets, light and dark themes, orbiting camera.
22
+ - Optional pulse families: `nutate.pulses.swept_frequency` (chirps, hyperbolic-secant
23
+ pulses, CHORUS, phase correction) and `nutate.pulses.composite` (composite pulses and
24
+ presets).
25
+
26
+ [0.1.0]: https://github.com/mforoozandeh/nutate/releases/tag/v0.1.0
@@ -0,0 +1,10 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ title: Nutate
4
+ abstract: Bloch simulations of any pulse sequence rendered as 3D Bloch-sphere videos.
5
+ authors:
6
+ - family-names: Foroozandeh
7
+ given-names: Mohammadali
8
+ license: Apache-2.0
9
+ repository-code: https://github.com/mforoozandeh/nutate
10
+ version: 0.1.0
nutate-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
nutate-0.1.0/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Nutate — Copyright 2026 Mohammadali Foroozandeh
nutate-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.5
2
+ Name: nutate
3
+ Version: 0.1.0
4
+ Summary: Bloch simulations of any pulse sequence rendered as 3D Bloch-sphere videos
5
+ Project-URL: Homepage, https://github.com/mforoozandeh/nutate
6
+ Project-URL: Repository, https://github.com/mforoozandeh/nutate
7
+ Project-URL: Issues, https://github.com/mforoozandeh/nutate/issues
8
+ Project-URL: Changelog, https://github.com/mforoozandeh/nutate/blob/main/CHANGELOG.md
9
+ Author: Mohammadali Foroozandeh
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: Bloch simulation,Bloch sphere,EPR,ESR,NMR,magnetic resonance,pulse,qubit,visualization
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
25
+ Classifier: Topic :: Scientific/Engineering :: Physics
26
+ Classifier: Topic :: Scientific/Engineering :: Visualization
27
+ Requires-Python: >=3.11
28
+ Requires-Dist: imageio-ffmpeg>=0.6
29
+ Requires-Dist: imageio>=2.31
30
+ Requires-Dist: matplotlib>=3.10
31
+ Requires-Dist: numpy>=1.24
32
+ Requires-Dist: pyvista>=0.45
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=8; extra == 'dev'
35
+ Requires-Dist: ruff>=0.6; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # Nutate
39
+
40
+ Bloch simulations of any pulse sequence, rendered as 3D Bloch-sphere videos.
41
+
42
+ ![A composite pulse on the Bloch sphere](https://raw.githubusercontent.com/mforoozandeh/nutate/main/docs/media/composite.webp)
43
+
44
+ Full-quality video (1080p):
45
+
46
+ https://github.com/user-attachments/assets/1848f607-e421-4923-b198-bb7745c69010
47
+
48
+ Nutate takes any pulse, given as a waveform (amplitude and phase, or I and Q) with its
49
+ duration and Rabi frequency, whether it drives nuclear spins (NMR), electron spins (EPR/ESR)
50
+ or a qubit. It simulates the Bloch vector in the rotating frame for many offsets at once,
51
+ renders the trajectories with [PyVista](https://pyvista.org) as MP4/GIF videos, PNG stills
52
+ or an interactive viewer, and maps robustness to drive (B1) amplitude errors. Optional pulse
53
+ families (chirps, hyperbolic-secant pulses, CHORUS, composite pulses) live in
54
+ `nutate.pulses`.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ pip install nutate
60
+ ```
61
+
62
+ Python ≥ 3.11. Video encoding uses the ffmpeg binary bundled with `imageio-ffmpeg`; no
63
+ system ffmpeg or LaTeX needed.
64
+
65
+ ## Quickstart
66
+
67
+ A generator makes the pulse: a waveform normalised to 1 plus its duration and Rabi frequency
68
+ ν1 (the drive amplitude, RF or MW, at waveform value 1). `nt.run` simulates it and writes
69
+ the video and/or the B1 robustness figures.
70
+
71
+ ```python
72
+ import nutate as nt
73
+ from nutate.pulses.swept_frequency import chirp
74
+
75
+ pulse = chirp(10e-3, 20e3, 500, smoothing=10) # pulse.amp (peak 1), .phase, .duration, .rabi
76
+ nt.run(pulse, 10e3, still=True, b1=True, out="output", name="chirp")
77
+ # output/chirp.mp4, chirp.png, chirp_b1_map.png, chirp_b1_surface.png, chirp_b1_phase.png
78
+ ```
79
+
80
+ Units are SI throughout (seconds, hertz, radians); arguments in degrees end in `_deg`.
81
+
82
+ The package core holds the pulse type, `nt.waveform` (your own arrays) and `nt.delay` (free
83
+ precession). Pulse families live in `nutate.pulses`:
84
+
85
+ - `nutate.pulses.swept_frequency`: `chirp`, `hs`, `chorus` (a list including its delay),
86
+ `CHORUS_CYCLE`, `phase_correction` and `chorus_phase_correction`
87
+ - `nutate.pulses.composite`: `composite` (a list, one pulse per element) and `PRESETS`
88
+
89
+ `pulse.with_rabi(ν1)` changes the Rabi frequency and keeps the waveform.
90
+
91
+ ### Your own waveform
92
+
93
+ `nt.waveform` turns arrays from any other generator (an optimiser, a shape tool) into a
94
+ pulse: amplitude and phase, or I and Q, normalised to 1. `rabi` is the Rabi frequency in
95
+ Hz, or give `t90`, the hard 90° pulse length (`rabi = 1/(4·t90)`). Slight overshoot above 1
96
+ is simulated as given; a peak above 1.5 is an error.
97
+
98
+ ```python
99
+ p1 = nt.waveform(amp, phase, duration=2e-3, rabi=15e3) # or phase_deg=...
100
+ p2 = nt.waveform(i=I, q=Q, duration=1e-3, t90=10e-6)
101
+ result = nt.run([p1, p2], 300e3, b1=True, out="output", name="my_pulse")
102
+ ```
103
+
104
+ ### Sequences and delays
105
+
106
+ A sequence is a list, played back to back. Put `nt.delay(duration, n_steps)` between
107
+ pulses for free precession (no drive); `n_steps` sets how finely the delay is sampled, i.e.
108
+ how smoothly the video shows it.
109
+
110
+ ```python
111
+ sequence = [p1, nt.delay(500e-6, 100), p2] # p1, 500 µs of free precession, then p2
112
+ nt.run(sequence, 300e3, out="output", name="echo")
113
+ ```
114
+
115
+ ### `nt.run` options
116
+
117
+ - Offsets span `±bandwidth/2`: `n_offsets` (31) for the video, `b1_offsets` (101) for the
118
+ B1 map. Or pass `offsets=` (Hz) for both.
119
+ - `video` (on), `still` (last frame as PNG), `b1` (off), `show` (interactive windows
120
+ instead of files). Pulses in a list play back to back; `phase_cycle=` is passed through.
121
+ - `video_options` go to `nt.render`; those that apply also go to the still and the viewer:
122
+ - `offsets`: draw only `k` evenly spaced offsets, or given indices
123
+ - `mode`: `"arrows"`, `"ribbon"` (a curve through all tips) or `"both"`
124
+ - `trail`: fading tip trails, as a fraction of the sequence
125
+ - `inset` / `inset_phase`: drive amplitude (and phase) vs time with a moving cursor
126
+ - `theme`: `"light"` (default) or `"dark"`
127
+ - `camera=nt.Camera(orbit=90)`, `style=nt.Style(...)` (colours, sizes, font), `duration`,
128
+ `size`
129
+ - B1 figures plot `−My` by default; `component="z"` for inversion. `b1_scales` (0.5–1.5) and
130
+ `rabi_ref` (the highest ν1, for the `Δ/Ω1(0)` axis) can be changed.
131
+ - The result holds the trajectory, the B1 map, the phase sensitivity and the files written.
132
+
133
+ ### Lower level
134
+
135
+ ```python
136
+ import numpy as np
137
+
138
+ traj = nt.simulate([pulse], offsets=np.linspace(-5e3, 5e3, 31))
139
+ nt.render(traj, "chirp.mp4", duration=12)
140
+ ```
141
+
142
+ `nt.snapshot(...)` writes a PNG still; `nt.show(traj)` opens an interactive window with a
143
+ time slider. `nt.plot_profiles(traj)` and `nt.plot_map(traj)` make the 2D excitation
144
+ profile and time–offset map plots.
145
+
146
+ ### B1 robustness
147
+
148
+ ```python
149
+ pulse = nt.waveform([1.0], [0.0], duration=10e-6, t90=10e-6) # hard 90°, ν1 = 25 kHz
150
+ offsets = np.linspace(-100e3, 100e3, 101) # Δ/Ω1(0) from −4 to 4
151
+ scales = np.linspace(0.5, 1.5, 101) # Ω1 / Ω1(0)
152
+ bmap = nt.b1_map([pulse], offsets, scales)
153
+ nt.plot_b1_map(bmap, "y", sign=-1) # contours over Δ/Ω1(0) × Ω1/Ω1(0)
154
+ nt.plot_b1_map(bmap, "y", sign=-1, surface=True)
155
+ nt.plot_b1_phase(scales, nt.b1_phase_sensitivity([pulse], scales))
156
+ ```
157
+
158
+ Sequences whose phase varies quickly across the band, such as a single chirp, need dense
159
+ offsets; `examples/b1_chirp.py` uses 1000, as the original script did.
160
+
161
+ `simulate(..., b1=...)` scales every drive amplitude (one factor, or one per offset);
162
+ `simulate_final` returns only the final states, which keeps large grids small in memory.
163
+ `nutate.pulses.swept_frequency.phase_correction(sequence, bandwidth, ...)` fits the
164
+ first-chirp phase correction for any CHORUS-like sequence.
165
+
166
+ ## Examples
167
+
168
+ Each script generates its pulses and passes them to `nt.run`. Video scripts write
169
+ `output/<name>.mp4` and `.png`; the `b1_*` scripts (and `waveform.py`) write
170
+ `output/<name>_b1_map.png`, `_b1_surface.png` and `_b1_phase.png`. To change what they
171
+ produce, edit the `nt.run` call: `show=True` for interactive windows, `out=` for another
172
+ folder, `video_options={"theme": "dark"}` for a dark video.
173
+
174
+ | Example | Shows |
175
+ |---|---|
176
+ | [`examples/chirp.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/chirp.py) | linear chirp excitation |
177
+ | [`examples/chirp_rewind.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/chirp_rewind.py) | a chirp, then an ideal rewind of its quadratic phase |
178
+ | [`examples/hard_pulse.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/hard_pulse.py) | a hard 90° pulse over a wide offset range |
179
+ | [`examples/composite.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/composite.py) | a composite pulse (preset 9 on a 10 µs 90° pulse) |
180
+ | [`examples/chorus.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/chorus.py) | CHORUS with phase correction, plus excitation profiles |
181
+ | [`examples/compressed_chorus_epr.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/compressed_chorus_epr.py) | compressed CHORUS for EPR, plus a time–offset map and phase paths |
182
+ | [`examples/waveform.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/waveform.py) | your own I/Q arrays (a shifted Gaussian 90°): video, still and B1 figures |
183
+ | [`examples/b1_hard.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_hard.py) | B1 map and phase sensitivity: hard 90° pulse |
184
+ | [`examples/b1_composite.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_composite.py) | B1 map and phase sensitivity: composite pulses |
185
+ | [`examples/b1_chirp.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_chirp.py) | B1 map and phase sensitivity: single chirp |
186
+ | [`examples/b1_double_chirp.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_double_chirp.py) | B1 map and phase sensitivity: double chirp |
187
+ | [`examples/b1_chorus.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_chorus.py) | B1 map and phase sensitivity: CHORUS |
188
+ | [`examples/b1_abstruse.py`](https://github.com/mforoozandeh/nutate/blob/main/examples/b1_abstruse.py) | B1 map and phase sensitivity: ABSTRUSE (hyperbolic-secant pulses) |
189
+
190
+ ## Conventions
191
+
192
+ - Rotating frame, no relaxation; initial magnetization `(0, 0, 1)`.
193
+ - Each step rotates the magnetization by `+α = 2π·sqrt(Ω² + Δ²)·dt` (right-handed) about
194
+ `n = (sinθ cosφ, sinθ sinφ, cosθ)` with `θ = atan2(Ω, Δ)`, for drive amplitude `Ω`
195
+ (waveform × ν1), phase `φ` and offset `Δ` — i.e. `Rz(φ)·Ry(θ)·Rz(α)·Ry(−θ)·Rz(−φ)`. So an
196
+ on-resonance 90° pulse with phase 0 takes `z → −y`.
197
+ - Profile phase is `angle(My + i·Mx)`.
198
+
199
+ ## Headless rendering
200
+
201
+ Videos are rendered off-screen. On a server without a display, VTK needs an off-screen
202
+ OpenGL context (OSMesa/EGL or a virtual display); see the off-screen rendering notes in the
203
+ [PyVista documentation](https://docs.pyvista.org).
204
+
205
+ ## Citation
206
+
207
+ If you use `nutate` in published work, please cite it; see [`CITATION.cff`](https://github.com/mforoozandeh/nutate/blob/main/CITATION.cff).
208
+
209
+ ## License
210
+
211
+ Apache License 2.0 — see [`LICENSE`](https://github.com/mforoozandeh/nutate/blob/main/LICENSE) and [`NOTICE`](https://github.com/mforoozandeh/nutate/blob/main/NOTICE).