Skip to content

Commit

Permalink
final nonmonotonic handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Nov 19, 2024
1 parent 922c11e commit 750b545
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ramanchada2/protocols/calibration/xcalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ def process(

elif isinstance(self.model, CustomCubicSplineInterpolator):
new_spe.x = self.model(new_spe.x)
if not np.all(np.diff(new_spe.x) > 0):
if self.nonmonotonic == "nan":

if np.any(np.diff(new_spe.x[np.isfinite(new_spe.x)]) <= 0):
if self.nonmonotonic == "error":
raise ValueError("Non-monotonic values detected (mode={})",self.nonmonotonic)
elif self.nonmonotonic == "nan":
# this is a patch, mostly intended at extrapolation
new_spe.x = np.asarray(new_spe.x, dtype=float)
is_nonmonotonic = np.diff(new_spe.x, prepend=new_spe.x[0]) <= 0
new_spe.x[is_nonmonotonic] = np.nan
elif self.nonmonotonic == "error":
raise ValueError("Non-monotonic values detected")
# we don't necessary ensure monotonicity by setting nans
if np.any(np.diff(new_spe.x[np.isfinite(new_spe.x)]) <= 0):
raise ValueError("Non-monotonic values detected (mode={})",self.nonmonotonic)

# else ignore

if convert_back:
return self.convert_units(new_spe, self.model_units, spe_units)
Expand Down

0 comments on commit 750b545

Please sign in to comment.