Skip to content

Commit

Permalink
Raise warning for division by null values during pdf computation Ped…
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoChat committed Apr 3, 2024
1 parent 40a63dd commit ace9e02
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pedpy/methods/other_characterisation_methods.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Module containing functions to compute pair distribution function."""

from typing import Tuple
import warnings

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -58,13 +59,19 @@ def compute_pair_distibution_function(
pd_ni_bins.value_counts().sort_index().to_numpy()
) / Nb_dist

# pair_distribution = pd_bins_normalised / pd_ni_bins_normalised
pair_distribution = np.divide(
pd_bins_normalised,
pd_ni_bins_normalised,
out=np.zeros_like(pd_bins_normalised),
where=pd_ni_bins_normalised != 0,
)
# Suppress warnings
warnings.filterwarnings("ignore")

try:
with np.errstate(divide='raise'):
pair_distribution = pd_bins_normalised / pd_ni_bins_normalised
warnings.filterwarnings("default") # reset wrnings values
except FloatingPointError :
warnings.filterwarnings("default") # reset wrnings values
pair_distribution = pd_bins_normalised / pd_ni_bins_normalised
warning_message = 'Random probability distribution contains null values, try using larger dx or more randomization cycles.'
warnings.warn(warning_message)

return radius_bins[1:], pair_distribution


Expand Down

0 comments on commit ace9e02

Please sign in to comment.