Skip to content

Commit 088aa86

Browse files
fix tests
1 parent 33db79c commit 088aa86

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

kwave/data.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,35 @@ class SimulationResult:
163163
I_avg: Optional[np.ndarray] = None
164164
I: Optional[np.ndarray] = None
165165

166+
def __getitem__(self, key: str):
167+
"""
168+
Enable dictionary-style access for backward compatibility.
169+
170+
Args:
171+
key: Field name to access
172+
173+
Returns:
174+
Value of the field
175+
176+
Raises:
177+
KeyError: If the field does not exist
178+
"""
179+
if hasattr(self, key):
180+
return getattr(self, key)
181+
raise KeyError(f"'{key}' field not found in SimulationResult")
182+
183+
def __contains__(self, key: str) -> bool:
184+
"""
185+
Enable dictionary-style membership testing for backward compatibility.
186+
187+
Args:
188+
key: Field name to check
189+
190+
Returns:
191+
True if the field exists, False otherwise
192+
"""
193+
return hasattr(self, key)
194+
166195
@classmethod
167196
def from_dotdict(cls, data: dict) -> "SimulationResult":
168197
"""

kwave/kspaceFirstOrder2D.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union
1+
from typing import Optional, Union
22

33
import numpy as np
44
from beartype import beartype as typechecker
@@ -86,7 +86,7 @@ def kspaceFirstOrder2DC(
8686
medium: kWaveMedium,
8787
simulation_options: SimulationOptions,
8888
execution_options: SimulationExecutionOptions,
89-
) -> SimulationResult:
89+
) -> Optional[SimulationResult]:
9090
"""
9191
2D time-domain simulation of wave propagation using C++ code.
9292
@@ -146,7 +146,7 @@ def kspaceFirstOrder2D(
146146
medium: kWaveMedium,
147147
simulation_options: SimulationOptions,
148148
execution_options: SimulationExecutionOptions,
149-
) -> SimulationResult:
149+
) -> Optional[SimulationResult]:
150150
"""
151151
2D time-domain simulation of wave propagation using k-space pseudospectral method.
152152

kwave/kspaceFirstOrder3D.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union
1+
from typing import Optional, Union
22

33
import numpy as np
44

@@ -26,7 +26,7 @@ def kspaceFirstOrder3DG(
2626
medium: kWaveMedium,
2727
simulation_options: SimulationOptions,
2828
execution_options: SimulationExecutionOptions,
29-
) -> SimulationResult:
29+
) -> Optional[SimulationResult]:
3030
"""
3131
3D time-domain simulation of wave propagation on a GPU using C++ CUDA code.
3232
@@ -80,7 +80,7 @@ def kspaceFirstOrder3DC(
8080
medium: kWaveMedium,
8181
simulation_options: SimulationOptions,
8282
execution_options: SimulationExecutionOptions,
83-
) -> SimulationResult:
83+
) -> Optional[SimulationResult]:
8484
"""
8585
3D time-domain simulation of wave propagation using C++ code.
8686
@@ -137,7 +137,7 @@ def kspaceFirstOrder3D(
137137
simulation_options: SimulationOptions,
138138
execution_options: SimulationExecutionOptions,
139139
time_rev: bool = False, # deprecated parameter
140-
) -> SimulationResult:
140+
) -> Optional[SimulationResult]:
141141
"""
142142
3D time-domain simulation of wave propagation using k-space pseudospectral method.
143143

kwave/kspaceFirstOrderAS.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Union
2+
from typing import Optional, Union
33

44
import numpy as np
55
from numpy.fft import ifftshift
@@ -31,7 +31,7 @@ def kspaceFirstOrderASC(
3131
medium: kWaveMedium,
3232
simulation_options: SimulationOptions,
3333
execution_options: SimulationExecutionOptions,
34-
) -> SimulationResult:
34+
) -> Optional[SimulationResult]:
3535
"""
3636
Axisymmetric time-domain simulation of wave propagation using C++ code.
3737
@@ -90,7 +90,7 @@ def kspaceFirstOrderAS(
9090
medium: kWaveMedium,
9191
simulation_options: SimulationOptions,
9292
execution_options: SimulationExecutionOptions,
93-
) -> SimulationResult:
93+
) -> Optional[SimulationResult]:
9494
"""
9595
Axisymmetric time-domain simulation of wave propagation.
9696
@@ -159,7 +159,7 @@ def kspaceFirstOrderAS(
159159
if simulation_options.simulation_type is not SimulationType.AXISYMMETRIC:
160160
logging.log(
161161
logging.WARN,
162-
"simulation type is not set to axisymmetric while using kSapceFirstOrderAS. " "Setting simulation type to axisymmetric.",
162+
"simulation type is not set to axisymmetric while using kSapceFirstOrderAS. Setting simulation type to axisymmetric.",
163163
)
164164
simulation_options.simulation_type = SimulationType.AXISYMMETRIC
165165

@@ -297,7 +297,7 @@ def kspaceFirstOrderAS(
297297

298298
# option to run simulations without the spatial staggered grid is not
299299
# supported for the axisymmetric code
300-
assert options.use_sg, "Optional input " "UseSG" " is not supported for axisymmetric simulations."
300+
assert options.use_sg, "Optional input UseSG is not supported for axisymmetric simulations."
301301

302302
# =========================================================================
303303
# SAVE DATA TO DISK FOR RUNNING SIMULATION EXTERNAL TO MATLAB

0 commit comments

Comments
 (0)