Skip to content

Commit

Permalink
Logging - avoid the zero division warning (#2695)
Browse files Browse the repository at this point in the history
* avoid the warning of division zero

* run black formatter
  • Loading branch information
DeerWhale authored Jul 11, 2024
1 parent 26cd336 commit 9279330
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tardis/plasma/properties/radiative_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ def calculate(
metastability, lines_upper_level_index
)

stimulated_emission_factor = 1 - (
(g_lower * n_upper) / (g_upper * n_lower)
# In theory the factor should be 1 for n_lower = 0, but in practice the opacity is reduced to 0 anyway
stimulated_emission_factor = np.zeros(n_lower.shape, dtype=np.float64)

n_lower_zero_mask = n_lower == 0.0
stimulated_emission_factor[~n_lower_zero_mask] = 1 - (
(g_lower * n_upper)[~n_lower_zero_mask]
/ (g_upper * n_lower)[~n_lower_zero_mask]
)
stimulated_emission_factor[n_lower == 0.0] = 0.0

# the following line probably can be removed as well
stimulated_emission_factor[
np.isneginf(stimulated_emission_factor)
] = 0.0
Expand Down

0 comments on commit 9279330

Please sign in to comment.