Skip to content

Commit dd8a272

Browse files
📝 Add docstrings to fix-test-syntax-bug-600
Docstrings generation was requested by @waltsims. * #614 (comment) The following files were modified: * `kwave/kWaveSimulation.py` * `tests/test_kspaceFirstOrder3D_state.py`
1 parent e3e76d4 commit dd8a272

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

kwave/kWaveSimulation.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ class kWaveSimulation(object):
3636
def __init__(
3737
self, kgrid: kWaveGrid, source: kSource, sensor: NotATransducer, medium: kWaveMedium, simulation_options: SimulationOptions
3838
):
39+
"""
40+
Initialize kWaveSimulation and prepare internal state for simulation validation and preparation.
41+
42+
Creates and stores copies of the provided grid, source, sensor, medium, and options; initializes flags, defaults, and internal placeholders used throughout the input-checking and preparation pipeline. If sensor.time_reversal_boundary_data is provided, the constructor converts inputs into a Dirichlet-style source and a minimal sensor for deprecated time-reversal mode, warns about deprecation, and configures the Recorder accordingly.
43+
44+
Parameters:
45+
kgrid (kWaveGrid): Spatial grid definition for the simulation.
46+
source (kSource): User-provided source definition (a deep copy is stored internally; the original is preserved on original_source).
47+
sensor (NotATransducer): User-provided sensor definition (a deep copy is stored internally; the original is preserved on original_sensor).
48+
medium (kWaveMedium): Medium properties (sound speed, density, absorption, etc.).
49+
simulation_options (SimulationOptions): Simulation-wide options and flags.
50+
51+
Side effects:
52+
- Stores deep copies as self.source and self.sensor and preserves originals in self.original_source and self.original_sensor.
53+
- Sets many internal flags and default values (mask type, time-reversal flag, PML/simulation defaults, source/sensor indexing placeholders, absorption operator placeholders, recorder and logging setup).
54+
- May replace source and sensor with a Dirichlet-style source/sensor when time-reversal boundary data is present.
55+
56+
No return value.
57+
"""
3958
self.precision = None
4059
self.kgrid = kgrid
4160
self.medium = medium
@@ -1500,14 +1519,9 @@ def check_time_reversal(self) -> bool:
15001519

15011520
def _is_binary_sensor_mask(self, kgrid_dim: int) -> bool:
15021521
"""
1503-
Check if the sensor mask is a binary grid matching the kgrid dimensions.
1504-
Takes into account that the PML may have been added to the sensor mask.
1505-
1506-
Args:
1507-
kgrid_dim: Dimensionality of the kWaveGrid
1508-
1509-
Returns:
1510-
bool: True if the sensor mask is a binary grid matching kgrid dimensions
1522+
Return True if the sensor mask is a binary grid matching the simulation grid (kgrid), accounting for optional PML padding.
1523+
1524+
Checks whether sensor.mask has the same shape as kgrid.k or—when a PML size is configured in self.options.pml_size—matches the grid shape extended by 2*pml in each dimension. Supports 1D, 2D, and 3D grids and accepts a scalar or per-axis PML size representation.
15111525
"""
15121526
# Get the grid shape without PML
15131527
grid_shape = self.kgrid.k.shape

tests/test_kspaceFirstOrder3D_state.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919

2020
def make_simulation_parameters(directory: Path):
2121
# create the computational grid
22+
"""
23+
Create a minimal 3D k-Wave simulation configuration used for testing.
24+
25+
Parameters:
26+
directory (Path): Directory used to construct input/output/checkpoint filenames;
27+
no files are created by this function.
28+
29+
Returns:
30+
tuple: (kgrid, medium, source, sensor, simulation_options, execution_options)
31+
- kgrid (kWaveGrid): 3D computational grid with PML applied.
32+
- medium (kWaveMedium): Homogeneous medium with sound_speed=1500 m/s.
33+
- source (kSource): Contains a smoothed spherical initial pressure field (`p0`).
34+
- sensor (kSensor): Binary planar sensor mask (plane at the first x-index).
35+
- simulation_options (SimulationOptions): Options configured for disk I/O,
36+
PML, data casting, and filenames pointing into `directory`.
37+
- execution_options (SimulationExecutionOptions): CPU execution settings
38+
with checkpointing configured.
39+
40+
Notes:
41+
- The initial pressure (`source.p0`) is generated as a smoothed ball and
42+
smoothing at runtime is disabled (`smooth_p0=False`).
43+
- Filenames for input, output, and checkpoint are set to `{directory}/kwave_input.h5`,
44+
`{directory}/kwave_output.h5`, and `{directory}/kwave_checkpoint.h5` respectively.
45+
"""
2246
PML_size = 10 # size of the PML in grid points
2347
N = Vector([32, 64, 64]) - 2 * PML_size # number of grid points
2448
d = Vector([0.2e-3, 0.2e-3, 0.2e-3]) # grid point spacing [m]

0 commit comments

Comments
 (0)