|
1 | | -Examples: k-Wave-Python Step-by-Step |
2 | | -======================= |
| 1 | +Examples |
| 2 | +======== |
3 | 3 |
|
4 | | -The k-Wave Python examples are organized to help you progress from basic wave physics to advanced applications. Each example demonstrates the four-component framework (Grid, Medium, Source, Sensor) with increasing complexity. |
| 4 | +k-Wave-python examples are organized by topic. Each example uses the ``setup()/run()`` pattern and can be run directly: |
5 | 5 |
|
6 | | -Start with the :doc:`get_started/first_simulation` tutorial, then follow this suggested learning path: |
| 6 | +.. code-block:: bash |
7 | 7 |
|
8 | | -Basic Wave Propagation (IVP - Initial Value Problems) |
9 | | ------------------------------------------------------ |
| 8 | + uv run python examples/ivp_homogeneous_medium.py |
10 | 9 |
|
11 | | -**Start Here**: Learn fundamental wave physics using initial pressure distributions (the simplest source type). |
| 10 | +No GPU required — all examples run on CPU with NumPy. |
12 | 11 |
|
13 | | -.. list-table:: |
14 | | - :header-rows: 1 |
15 | | - :widths: 40 40 20 |
| 12 | +Start with the :doc:`get_started/first_simulation` tutorial, then explore by topic: |
16 | 13 |
|
17 | | - * - Example |
18 | | - - Core Concept |
19 | | - - Topics |
20 | | - * - :ghdir:`examples/legacy/ivp_photoacoustic_waveforms/` |
21 | | - - 2D vs 3D wave propagation physics |
22 | | - - **IVP** • Wave spreading • Compact support |
| 14 | +Initial Value Problems (IVP) |
| 15 | +---------------------------- |
23 | 16 |
|
24 | | -Simple Transducers & Sources |
25 | | ------------------------------ |
| 17 | +Learn fundamental wave physics using initial pressure distributions. |
26 | 18 |
|
27 | | -**Next Step**: Introduction to time-varying sources and practical transducer modeling. |
| 19 | +- :ghfile:`Homogeneous medium <examples/ivp_homogeneous_medium.py>` — simplest 2D simulation |
| 20 | +- :ghfile:`Heterogeneous medium <examples/ivp_heterogeneous_medium.py>` — spatially varying sound speed and density |
| 21 | +- :ghfile:`1D simulation <examples/ivp_1D_simulation.py>` — reflections at impedance boundaries |
| 22 | +- :ghfile:`3D simulation <examples/ivp_3D_simulation.py>` — extending to three dimensions |
| 23 | +- :ghfile:`Binary sensor mask <examples/ivp_binary_sensor_mask.py>` — defining sensor regions |
| 24 | +- :ghfile:`Recording particle velocity <examples/ivp_recording_particle_velocity.py>` — velocity field output |
| 25 | +- :ghfile:`Photoacoustic waveforms <examples/ivp_photoacoustic_waveforms.py>` — 2D vs 3D wave spreading |
| 26 | +- :ghfile:`Loading external image <examples/ivp_loading_external_image.py>` — image-based initial pressure |
28 | 27 |
|
29 | | -.. list-table:: |
30 | | - :header-rows: 1 |
31 | | - :widths: 40 40 20 |
| 28 | +Time-Varying Pressure Sources (TVSP) |
| 29 | +------------------------------------- |
32 | 30 |
|
33 | | - * - Example |
34 | | - - Core Concept |
35 | | - - Topics |
36 | | - * - :ghdir:`examples/legacy/us_defining_transducer/` |
37 | | - - Basic ultrasound transducer setup |
38 | | - - **US** • Transducer basics • Time-varying sources |
39 | | - * - :ghdir:`examples/legacy/at_circular_piston_3D/` |
40 | | - - Simple focused geometry |
41 | | - - **AT** • 3D focusing • Geometric sources |
42 | | - * - :ghdir:`examples/legacy/at_circular_piston_AS/` |
43 | | - - Computational efficiency with symmetry |
44 | | - - **AT** • Axisymmetric • Computational optimization |
| 31 | +Transducer-driven simulations with time-varying sources. |
45 | 32 |
|
46 | | -Medical Imaging Applications |
47 | | ----------------------------- |
| 33 | +- :ghfile:`Monopole source <examples/tvsp_homogeneous_medium_monopole.py>` — single point source |
| 34 | +- :ghfile:`Dipole source <examples/tvsp_homogeneous_medium_dipole.py>` — dipole radiation pattern |
| 35 | +- :ghfile:`Steering linear array <examples/tvsp_steering_linear_array.py>` — beam steering with delays |
| 36 | +- :ghfile:`Snell's law <examples/tvsp_snells_law.py>` — refraction at material boundaries |
| 37 | +- :ghfile:`Doppler effect <examples/tvsp_doppler_effect.py>` — moving source frequency shift |
| 38 | +- :ghfile:`3D simulation <examples/tvsp_3D_simulation.py>` — time-varying source in 3D |
| 39 | + |
| 40 | +Sensor Directivity (SD) |
| 41 | +------------------------ |
| 42 | + |
| 43 | +How sensor geometry affects measurements. |
| 44 | + |
| 45 | +- :ghfile:`Directivity modelling 2D <examples/sd_directivity_modelling_2D.py>` — finite sensor size effects |
| 46 | +- :ghfile:`Directivity modelling 3D <examples/sd_directivity_modelling_3D.py>` — 3D directivity |
| 47 | +- :ghfile:`Focused detector 2D <examples/sd_focussed_detector_2D.py>` — directional sensitivity |
| 48 | +- :ghfile:`Focused detector 3D <examples/sd_focussed_detector_3D.py>` — 3D focused sensors |
| 49 | +- :ghfile:`Directional array elements <examples/sd_directional_array_elements.py>` — multi-element arrays |
| 50 | + |
| 51 | +Photoacoustic Reconstruction (PR) |
| 52 | +---------------------------------- |
| 53 | + |
| 54 | +Image reconstruction from sensor data. |
| 55 | + |
| 56 | +- :ghfile:`2D FFT line sensor <examples/pr_2D_FFT_line_sensor.py>` — FFT-based reconstruction |
| 57 | +- :ghfile:`3D FFT planar sensor <examples/pr_3D_FFT_planar_sensor.py>` — 3D FFT reconstruction |
| 58 | + |
| 59 | +Numerical Analysis (NA) |
| 60 | +------------------------ |
| 61 | + |
| 62 | +Computational methods and optimization. |
48 | 63 |
|
49 | | -**Practical Applications**: See how basic concepts combine into real-world medical imaging systems. |
50 | | - |
51 | | -.. list-table:: |
52 | | - :header-rows: 1 |
53 | | - :widths: 40 40 20 |
54 | | - |
55 | | - * - Example |
56 | | - - Application |
57 | | - - Topics |
58 | | - * - :ghdir:`examples/legacy/us_beam_patterns/` |
59 | | - - Understanding acoustic beam formation |
60 | | - - **US** • Beam focusing • Field patterns |
61 | | - * - :ghdir:`examples/legacy/us_bmode_linear_transducer/` |
62 | | - - Complete ultrasound imaging pipeline |
63 | | - - **US** • Medical imaging • Signal processing |
64 | | - * - :ghdir:`examples/legacy/pr_2D_FFT_line_sensor/` |
65 | | - - Photoacoustic image reconstruction |
66 | | - - **PR** • Image reconstruction • FFT methods |
67 | | - * - :ghdir:`examples/legacy/pr_2D_TR_line_sensor/` |
68 | | - - Alternative reconstruction approach |
69 | | - - **PR** • Time reversal • Reconstruction |
70 | | - |
71 | | -Advanced Transducer Modeling (AT - Array Transducers) |
72 | | ------------------------------------------------------ |
73 | | - |
74 | | -**Complex Geometries**: Learn sophisticated techniques for modeling complex transducer arrays using Cartesian space methods. |
75 | | - |
76 | | -.. list-table:: |
77 | | - :header-rows: 1 |
78 | | - :widths: 40 40 20 |
79 | | - |
80 | | - * - Example |
81 | | - - Advanced Technique |
82 | | - - Topics |
83 | | - * - :ghdir:`examples/legacy/at_array_as_source/` |
84 | | - - kWaveArray for complex geometries |
85 | | - - **AT** • Array modeling • Anti-aliasing |
86 | | - * - :ghdir:`examples/legacy/at_array_as_sensor/` |
87 | | - - Complex sensor array geometries |
88 | | - - **AT** • Sensor arrays • Flexible positioning |
89 | | - * - :ghdir:`examples/legacy/at_linear_array_transducer/` |
90 | | - - Multi-element linear arrays |
91 | | - - **AT** • Linear arrays • Element spacing |
92 | | - * - :ghdir:`examples/legacy/at_focused_bowl_3D/` |
93 | | - - 3D focused ultrasound therapy |
94 | | - - **AT** • Therapeutic US • 3D focusing |
95 | | - * - :ghdir:`examples/legacy/at_focused_annular_array_3D/` |
96 | | - - Multi-element focused systems |
97 | | - - **AT** • Annular arrays • Complex focusing |
98 | | - |
99 | | -Advanced Imaging & Reconstruction (PR - Pressure/Photoacoustic Reconstruction) |
100 | | -------------------------------------------------------------------------------- |
101 | | - |
102 | | -**3D Reconstruction**: Advanced reconstruction techniques for photoacoustic and pressure field imaging. |
103 | | - |
104 | | -.. list-table:: |
105 | | - :header-rows: 1 |
106 | | - :widths: 40 40 20 |
107 | | - |
108 | | - * - Example |
109 | | - - Reconstruction Method |
110 | | - - Topics |
111 | | - * - :ghdir:`examples/legacy/pr_3D_FFT_planar_sensor/` |
112 | | - - 3D FFT-based reconstruction |
113 | | - - **PR** • 3D imaging • Planar arrays |
114 | | - * - :ghdir:`examples/legacy/pr_3D_TR_planar_sensor/` |
115 | | - - 3D time reversal reconstruction |
116 | | - - **PR** • 3D time reversal • Volumetric imaging |
117 | | - * - :ghdir:`examples/legacy/us_bmode_phased_array/` |
118 | | - - Advanced ultrasound beamforming |
119 | | - - **US** • Phased arrays • Electronic steering |
120 | | - |
121 | | -Sensor Physics & Directivity (SD - Sensor Directivity) |
122 | | ------------------------------------------------------- |
123 | | - |
124 | | -**Sensor Modeling**: Understanding how sensor size, shape, and directivity affect measurements. |
125 | | - |
126 | | -.. list-table:: |
127 | | - :header-rows: 1 |
128 | | - :widths: 40 40 20 |
129 | | - |
130 | | - * - Example |
131 | | - - Physics Concept |
132 | | - - Topics |
133 | | - * - :ghdir:`examples/legacy/sd_directivity_modelling_2D/` |
134 | | - - How sensor size affects measurements |
135 | | - - **SD** • Directivity • Finite sensor size |
136 | | - * - :ghdir:`examples/legacy/sd_focussed_detector_2D/` |
137 | | - - Directional sensor sensitivity |
138 | | - - **SD** • Focused detection • Sensor design |
139 | | - * - :ghdir:`examples/legacy/sd_focussed_detector_3D/` |
140 | | - - 3D focused sensor modeling |
141 | | - - **SD** • 3D detection • Sensor focusing |
142 | | - |
143 | | -Computational Optimization (NA - Numerical Analysis) |
144 | | ----------------------------------------------------- |
145 | | - |
146 | | -**Advanced Numerics**: Optimize simulations and understand computational aspects. |
147 | | - |
148 | | -.. list-table:: |
149 | | - :header-rows: 1 |
150 | | - :widths: 40 40 20 |
151 | | - |
152 | | - * - Example |
153 | | - - Optimization Topic |
154 | | - - Topics |
155 | | - * - :ghdir:`examples/legacy/na_controlling_the_pml/` |
156 | | - - Boundary conditions and efficiency |
157 | | - - **NA** • PML boundaries • Computational domains |
158 | | - |
159 | | -Understanding the Prefixes |
160 | | --------------------------- |
161 | | - |
162 | | -- **IVP** = Initial Value Problems (wave propagation from initial pressure) |
163 | | -- **US** = Ultrasound (medical and therapeutic ultrasound applications) |
164 | | -- **AT** = Array Transducers (complex geometries using Cartesian space methods) |
165 | | -- **PR** = Pressure/Photoacoustic Reconstruction (image reconstruction techniques) |
166 | | -- **SD** = Sensor Directivity (sensor physics and measurement effects) |
167 | | -- **NA** = Numerical Analysis (computational optimization and methods) |
168 | | - |
169 | | -Learning Strategy |
170 | | ------------------ |
171 | | - |
172 | | -1. **Start with IVP**: Understand basic wave physics |
173 | | -2. **Move to simple US/AT**: Learn transducer basics |
174 | | -3. **Apply to imaging**: See concepts in real applications (US, PR) |
175 | | -4. **Master advanced AT**: Handle complex geometries |
176 | | -5. **Understand sensors**: Learn about measurement physics (SD) |
177 | | -6. **Optimize**: Improve computational efficiency (NA) |
178 | | - |
179 | | -Each example builds on the four-component framework, but with increasing sophistication in how the components are configured and used. |
| 64 | +- :ghfile:`Controlling the PML <examples/na_controlling_the_PML.py>` — boundary absorption settings |
| 65 | +- :ghfile:`Source smoothing <examples/na_source_smoothing.py>` — spatial filtering of sources |
| 66 | +- :ghfile:`Filtering part 1 <examples/na_filtering_part_1.py>` — grid-imposed frequency limits |
| 67 | +- :ghfile:`Filtering part 2 <examples/na_filtering_part_2.py>` — filtering source signals |
| 68 | +- :ghfile:`Filtering part 3 <examples/na_filtering_part_3.py>` — combined filtering |
| 69 | +- :ghfile:`Modelling nonlinearity <examples/na_modelling_nonlinearity.py>` — nonlinear wave propagation |
| 70 | +- :ghfile:`Optimising performance <examples/na_optimising_performance.py>` — speed and memory tips |
0 commit comments