Skip to content

Commit

Permalink
interpolation now supports nans
Browse files Browse the repository at this point in the history
  • Loading branch information
AramisDuf committed Feb 21, 2024
1 parent 5cfaca9 commit 324c017
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion solardatatools/algorithms/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ def compute_integral_interpolation(ttnew, xxnew, new_indices):
Returns:
y (np.ndarray): Interpolated signal (length n-1).
'''
piecewise_integrals = np.diff(ttnew) * xxnew[:-1]
xxnew_filled = np.nan_to_num(xxnew, nan=0) # replace NaNs with zeros
piecewise_integrals = np.diff(ttnew) * xxnew_filled[:-1]
cumulative_integrals = np.zeros(ttnew.shape[0])
# Add the initial zero as a baseline for the cumulative sum
cumulative_integrals[1:] = np.cumsum(piecewise_integrals)
was_nan = np.isnan(xxnew)
was_nan[-1] = False # the last point is not used in the interpolation
cumulative_integrals[was_nan] = np.nan # set NaNs back to NaN
y = np.diff(cumulative_integrals[new_indices])
return y

Expand Down

0 comments on commit 324c017

Please sign in to comment.