File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
src/ramanchada2/protocols/calibration Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments