Skip to content

Commit 5ffa109

Browse files
author
tully (work)
committed
fix: correct type annotations in kWaveMedium class
- Replace incorrect np.array type hints with proper Union types - Add support for scalar (float/int) and array (np.ndarray) inputs - Use Optional[] for parameters with None defaults - Improve IDE type checking and autocompletion support Addresses issue where IDE shows 'Expected type None, got float' warnings for alpha_coeff and alpha_power parameters.
1 parent 51b2041 commit 5ffa109

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

kwave/kmedium.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from dataclasses import dataclass
33
from typing import List
4+
from typing import Union, Optional
45

56
import numpy as np
67

@@ -10,24 +11,24 @@
1011
@dataclass
1112
class kWaveMedium(object):
1213
# sound speed distribution within the acoustic medium [m/s] | required to be defined
13-
sound_speed: np.array
14+
sound_speed: Union[float, int, np.ndarray]
1415
# reference sound speed used within the k-space operator (phase correction term) [m/s]
15-
sound_speed_ref: np.array = None
16+
sound_speed_ref: Optional[Union[float, int, np.ndarray]] = None
1617
# density distribution within the acoustic medium [kg/m^3]
17-
density: np.array = None
18+
density: Optional[Union[float, int, np.ndarray]] = None
1819
# power law absorption coefficient [dB/(MHz^y cm)]
19-
alpha_coeff: np.array = None
20+
alpha_coeff: Optional[Union[float, int, np.ndarray]] = None
2021
# power law absorption exponent
21-
alpha_power: np.array = None
22+
alpha_power: Optional[Union[float, int, np.ndarray]] = None
2223
# optional input to force either the absorption or dispersion terms in the equation of state to be excluded;
2324
# valid inputs are 'no_absorption' or 'no_dispersion'
24-
alpha_mode: np.array = None
25+
alpha_mode: Optional[str] = None
2526
# frequency domain filter applied to the absorption and dispersion terms in the equation of state
26-
alpha_filter: np.array = None
27+
alpha_filter: Optional[np.ndarray] = None
2728
# two element array used to control the sign of absorption and dispersion terms in the equation of state
28-
alpha_sign: np.array = None
29+
alpha_sign: Optional[np.ndarray] = None
2930
# parameter of nonlinearity
30-
BonA: np.array = None
31+
BonA: Optional[Union[float, int, np.ndarray]] = None
3132
# is the medium absorbing?
3233
absorbing: bool = False
3334
# is the medium absorbing stokes?

0 commit comments

Comments
 (0)