Skip to content

Commit 67ce776

Browse files
📝 Add docstrings to lossless
Docstrings generation was requested by @djps. * #658 (comment) The following files were modified: * `kwave/kWaveSimulation.py` * `kwave/kWaveSimulation_helper/create_absorption_variables.py`
1 parent 6ec3d6d commit 67ce776

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

kwave/kWaveSimulation.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,29 @@ def __init__(
145145
@property
146146
def equation_of_state(self):
147147
"""
148+
Select the active equation-of-state label based on the medium's absorption and Stokes settings.
149+
148150
Returns:
149-
Set equation of state variable
151+
equation (str): One of:
152+
- 'stokes' when the medium is absorbing and uses the Stokes model.
153+
- 'absorbing' when the medium is absorbing and not using the Stokes model.
154+
- 'lossless' when the medium is not absorbing.
150155
"""
151156
if self.medium.absorbing:
152157
if self.medium.stokes:
153158
return "stokes"
154159
else:
155160
return "absorbing"
156161
else:
157-
return "loseless"
162+
return "lossless"
158163

159164
@property
160165
def use_sensor(self):
161166
"""
167+
Indicates whether a sensor is defined for the simulation.
168+
162169
Returns:
163-
False if no output of any kind is required
164-
170+
True if a sensor object is present, False otherwise.
165171
"""
166172
return self.sensor is not None
167173

@@ -1549,4 +1555,4 @@ def _is_cuboid_corners_mask(self, kgrid_dim: int) -> bool:
15491555
return self.sensor.mask.shape[0] == 4 # [x1, y1, x2, y2]
15501556
elif kgrid_dim == 3:
15511557
return self.sensor.mask.shape[0] == 6 # [x1, y1, z1, x2, y2, z2]
1552-
return False # Not valid for 1D or other dimensions
1558+
return False # Not valid for 1D or other dimensions

kwave/kWaveSimulation_helper/create_absorption_variables.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,32 @@
1010

1111
def create_absorption_variables(kgrid: kWaveGrid, medium: kWaveMedium, equation_of_state):
1212
# define the lossy derivative operators and proportionality coefficients
13+
"""
14+
Selects and returns absorption and dispersion operators and coefficients for the given medium based on the equation of state.
15+
16+
Parameters:
17+
kgrid (kWaveGrid): Grid object providing wavenumber array via `kgrid.k`.
18+
medium (kWaveMedium): Medium properties used to compute absorption/dispersion coefficients.
19+
equation_of_state (str): One of `"absorbing"`, `"stokes"`, or `"lossless"` determining which variables to produce.
20+
21+
Returns:
22+
tuple: (nabla1, nabla2, tau, eta)
23+
- nabla1: First-order absorption operator or `None` when not applicable.
24+
- nabla2: Dispersion operator or `None` when not applicable.
25+
- tau: Absorbing coefficient or `None` when not applicable.
26+
- eta: Dispersive coefficient or `None` when not applicable.
27+
28+
Behavior:
29+
- "absorbing": returns (nabla1, nabla2, tau, eta) computed for an absorbing medium.
30+
- "stokes": returns (None, None, tau, None) where `tau` is the Stokes absorbing coefficient.
31+
- "lossless": returns (None, None, None, None).
32+
"""
1333
if equation_of_state == "absorbing":
1434
return create_absorbing_medium_variables(kgrid.k, medium)
1535
elif equation_of_state == "stokes":
1636
return create_stokes_medium_variables(medium)
37+
elif equation_of_state == "lossless":
38+
return None, None, None, None
1739
else:
1840
raise NotImplementedError
1941

@@ -105,4 +127,4 @@ def apply_alpha_filter(medium, nabla1, nabla2):
105127
# shift the parameters back
106128
nabla1 = np.fft.ifftshift(nabla1)
107129
nabla2 = np.fft.ifftshift(nabla2)
108-
return nabla1, nabla2
130+
return nabla1, nabla2

0 commit comments

Comments
 (0)