Skip to content

Commit

Permalink
safer bounds determination for Elam spline evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed May 15, 2024
1 parent 65e3baf commit 2684658
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions python/xraydb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def as_ndarray(obj):
return np.array([obj])
return np.asarray(obj)


def elam_spline(xin, yin, yspl_in, xout):
"""
interpolate values from Elam photoabsorption and
Expand All @@ -57,12 +58,12 @@ def elam_spline(xin, yin, yspl_in, xout):
ndarray: interpolated values
"""
x = as_ndarray(xout)
x[np.where(x < min(xin))] = min(xin)
x[np.where(x > max(xin))] = max(xin)

lo, hi = np.array([(np.flatnonzero(xin < e)[-1],
np.flatnonzero(xin > e)[0])
for e in x]).transpose()
lo, hi = [], []
for e in x:
_elo = np.where(xin < e)[0]
_ehi = np.where(xin > e)[0]
lo.append(_elo[-1] if len(_elo) > 0 else 0)
hi.append(_ehi[0] if len(_ehi) > 0 else len(xin)-1)

diff = xin[hi] - xin[lo]
if any(diff <= 0):
Expand Down

0 comments on commit 2684658

Please sign in to comment.