From 324c01764b0bf329f179181ee01fad2debef3cf6 Mon Sep 17 00:00:00 2001 From: Aramis Date: Wed, 21 Feb 2024 13:49:19 -0800 Subject: [PATCH] interpolation now supports nans --- solardatatools/algorithms/interpolation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/solardatatools/algorithms/interpolation.py b/solardatatools/algorithms/interpolation.py index 63aa992d..b54e1d68 100644 --- a/solardatatools/algorithms/interpolation.py +++ b/solardatatools/algorithms/interpolation.py @@ -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