Skip to content

Commit 750b545

Browse files
committed
final nonmonotonic handling
1 parent 922c11e commit 750b545

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/ramanchada2/protocols/calibration/xcalibration.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,20 @@ def process(
7878

7979
elif isinstance(self.model, CustomCubicSplineInterpolator):
8080
new_spe.x = self.model(new_spe.x)
81-
if not np.all(np.diff(new_spe.x) > 0):
82-
if self.nonmonotonic == "nan":
81+
82+
if np.any(np.diff(new_spe.x[np.isfinite(new_spe.x)]) <= 0):
83+
if self.nonmonotonic == "error":
84+
raise ValueError("Non-monotonic values detected (mode={})",self.nonmonotonic)
85+
elif self.nonmonotonic == "nan":
86+
# this is a patch, mostly intended at extrapolation
8387
new_spe.x = np.asarray(new_spe.x, dtype=float)
8488
is_nonmonotonic = np.diff(new_spe.x, prepend=new_spe.x[0]) <= 0
8589
new_spe.x[is_nonmonotonic] = np.nan
86-
elif self.nonmonotonic == "error":
87-
raise ValueError("Non-monotonic values detected")
90+
# we don't necessary ensure monotonicity by setting nans
91+
if np.any(np.diff(new_spe.x[np.isfinite(new_spe.x)]) <= 0):
92+
raise ValueError("Non-monotonic values detected (mode={})",self.nonmonotonic)
93+
94+
# else ignore
8895

8996
if convert_back:
9097
return self.convert_units(new_spe, self.model_units, spe_units)

0 commit comments

Comments
 (0)