Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
scottprahl committed May 7, 2024
1 parent 3320c21 commit ae2fa0c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 60 deletions.
88 changes: 46 additions & 42 deletions miepython/miepython.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# pylint: disable=unused-argument
# pylint: disable=no-member
# pylint: disable=bare-except
# pylint: disable=too-many-return-statements

"""
Mie scattering calculations for perfect spheres JITTED!.
Expand Down Expand Up @@ -198,15 +193,15 @@ def _mie_An_Bn(m, x):


@njit((complex128, float64), cache=True)
def _small_conducting_mie(m, x):
def _small_conducting_mie(_m, x):
"""
Calculate the efficiencies for a small conducting spheres.
Typically used for small conducting spheres where x < 0.1 and
m.real == 0
Args:
m: the complex index of refraction of the sphere
_m: the complex index of refraction of the sphere (unused)
x: the size parameter of the sphere
Returns:
Expand Down Expand Up @@ -398,38 +393,44 @@ def normalization_factor(m, x, norm_int):
Returns:
scaling factor needed for scattering function
"""
norm = None

# Qsca normalization
if norm_int == 3:
return x * np.sqrt(np.pi)
norm = x * np.sqrt(np.pi)

# Bohren Normalization
if norm_int == 5:
return 0.5
elif norm_int == 5:
norm = 0.5

# Wiscombe Normalization
if norm_int == 6:
return 1
elif norm_int == 6:
norm = 1

else:
# calculate qsca and qext
qext, qsca, _, _ = _mie_scalar(m, x)

# calculate qsca and qext
qext, qsca, _, _ = _mie_scalar(m, x)
# albedo Normalization
if norm_int == 0:
norm = x * np.sqrt(np.pi * qext)

# albedo Normalization
if norm_int == 0:
return x * np.sqrt(np.pi * qext)
# Unity normalization
elif norm_int == 1:
norm = x * np.sqrt(qsca * np.pi)

# Unity normalization
if norm_int == 1:
return x * np.sqrt(qsca * np.pi)
# 4pi Normalization
elif norm_int == 2:
norm = x * np.sqrt(qsca / 4)

# 4pi Normalization
if norm_int == 2:
return x * np.sqrt(qsca / 4)
# Qext Normalization
elif norm_int == 4: # 4pi
norm = x * np.sqrt(qsca * np.pi / qext)

# Qext Normalization
if norm_int == 4: # 4pi
return x * np.sqrt(qsca * np.pi / qext)
if norm is None:
raise ValueError("norm-int must be in the range 0..6")

raise ValueError("norm-int must be in the range 0..6")
return norm


def norm_string_to_integer(s):
Expand All @@ -446,31 +447,34 @@ def norm_string_to_integer(s):
Returns:
integer used in _mie_S1_S2() determine normalization
"""
ii = None
norm = s.lower()

if norm in ['a', 'albedo']:
return 0
ii = 0

if norm in ['1', 'one', 'unity']:
return 1
elif norm in ['1', 'one', 'unity']:
ii = 1

if norm in ['four_pi', '4pi']:
return 2
elif norm in ['four_pi', '4pi']:
ii = 2

if norm in ['qsca', 'scattering_efficiency']:
return 3
elif norm in ['qsca', 'scattering_efficiency']:
ii = 3

if norm in ['qext', 'extinction_efficiency']:
return 4
elif norm in ['qext', 'extinction_efficiency']:
ii = 4

if norm in ['bohren']:
return 5
elif norm in ['bohren']:
ii = 5

if norm in ['wiscombe']:
return 6
elif norm in ['wiscombe']:
ii = 6

raise ValueError("normalization must be one of 'albedo' (default), 'one'"
"'4pi', 'qext', 'qsca', 'bohren', or 'wiscombe'")
if ii is None:
raise ValueError("normalization must be one of 'albedo' (default), 'one'"
"'4pi', 'qext', 'qsca', 'bohren', or 'wiscombe'")
return ii


@njit((complex128, float64, float64[:], int32), cache=True)
Expand Down
40 changes: 22 additions & 18 deletions miepython/miepython_nojit.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ def _mie_An_Bn(m, x):
return a, b


def _small_conducting_mie(m, x):
def _small_conducting_mie(_m, x):
"""
Calculate the efficiencies for a small conducting spheres.
Typically used for small conducting spheres where x < 0.1 and
m.real == 0
Args:
m: the complex index of refraction of the sphere
_m: the complex index of refraction of the sphere (unused)
x: the size parameter of the sphere
Returns:
Expand Down Expand Up @@ -383,33 +383,37 @@ def normalization_factor(m, x, norm_str):
Returns:
scaling factor needed for scattering function
"""
factor = None
norm = norm_str.lower()

if norm in ['bohren']:
return 1 / 2
factor = 1 / 2

if norm in ['wiscombe']:
return 1
elif norm in ['wiscombe']:
factor = 1

if norm in ['qsca', 'scattering_efficiency']:
return x * np.sqrt(np.pi)
elif norm in ['qsca', 'scattering_efficiency']:
factor = x * np.sqrt(np.pi)

qext, qsca, _, _ = _mie_scalar(m, x)
else:
qext, qsca, _, _ = _mie_scalar(m, x)

if norm in ['a', 'albedo']:
return x * np.sqrt(np.pi * qext)
if norm in ['a', 'albedo']:
factor = x * np.sqrt(np.pi * qext)

if norm in ['1', 'one', 'unity']:
return x * np.sqrt(qsca * np.pi)
if norm in ['1', 'one', 'unity']:
factor = x * np.sqrt(qsca * np.pi)

if norm in ['four_pi', '4pi']:
return x * np.sqrt(qsca / 4)
if norm in ['four_pi', '4pi']:
factor = x * np.sqrt(qsca / 4)

if norm in ['qext', 'extinction_efficiency']:
return x * np.sqrt(qsca * np.pi / qext)
if norm in ['qext', 'extinction_efficiency']:
factor = x * np.sqrt(qsca * np.pi / qext)

raise ValueError("normalization must be one of 'albedo' (default), 'one'"
"'4pi', 'qext', 'qsca', 'bohren', or 'wiscombe'")
if factor is None:
raise ValueError("normalization must be one of 'albedo' (default), 'one'"
"'4pi', 'qext', 'qsca', 'bohren', or 'wiscombe'")
return factor


def mie_S1_S2(m, x, mu, norm='albedo'):
Expand Down

0 comments on commit ae2fa0c

Please sign in to comment.