Tech Blog

Function Interpolation with known

piecewise averages

jose_circle

Function interpolation with known piecewise averages

Overview

In a typical interpolation problem, values are estimated within a discrete set of known data points. Recently, we had to “interpolate” a function from which we only knew the averages at certain time intervals. A set of known data points was not available and regular interpolation techniques could not be applied. This post explains the solution that we implemented by way of an example.

Solution outline for function interpolation with known piecewise averages

The example used to illustrate the interpolation methodology is based on a small photovoltaic power plant. The hourly average generation for a given day is shown in Table 1.

Table 1: Average power generation.
Hour of the dayAverage generation (kW)
8:00-9:000.5
9:00-10:002.0
10:00-11:005.0
11:00-12:008.0
12:00-13:0010.0
13:00-14:0010.0
14:00-15:009.5
15:00-16:008.5
16:00-17:007.0
17:00-18:005.0
18:00-19:002.0

The target function is the power plant’s production curve on a minute-by-minute resolution. Note that the measured power curve is only available on an hourly basis.

The subsequent steps are followed to interpolate the power generation data:

  1. Calculate the cumulative function. This is equivalent to cumulative generation in our example (see Table 2). Note that 1 kWh is the energy generated by a power plant producing 1 kW during 1 hour. For example, the total generation until 10am was 2.5kWh (0.5kWh generated between 8:00 and 9:00 and 2.0kWh generated between 9:00 and 10:00am).
  2. Interpolate the cumulative function. Standard interpolation techniques can be applied to the cumulative function as a set of data points are known. For example, we know that the cumulative generation equals 0.5kWh at 9:00.
  3. Differentiate the interpolated cumulative function to obtain the target function. As the cumulative function is the integral (or sum) of the target function, the target function is the derivative of the cumulative function.
Table 2: Cumulative daily generation.
Time of the dayCumulative generation (kWh)
8:000
9:000.5
10:002.5
11:007.5
12:0015.5
13:0025.5
14:0035.5
15:0045.0
16:0053.5
17:0060.5
18:0065.5
19:0067.5

A third-order spline interpolation was applied to the solar PV cumulative values in Table 2. Given that a third order Spline interpolation is twice differentiable, its derivative, the target function of our example, is continuous and differentiable. The result for the target function compared to the original hour-by-hour data can be seen in the figure below.

Example code implementation in Python

An example code implementation in Python is as follows.

  # 0. Start by importing Numpy and interpolate from Scipy
  import numpy as np
  from scipy import interpolate


  # 1. Get cumulative function
  cumulative_generation = np.array([0, 0.5, 2.5, 7.5, 15.5, 25.5, 35.5, 45, 53.5, 60.5, 65.5, 67.5])
  hours = np.arange(8, 20)

  # 2. Interpolate the cumulative function (Spline interpolation)
  interpolator = interpolate.CubicSpline(hours, cumulative_generation)

  # 3. Differentiate and substitute.
  #    For example, differentiate and interpolate the power at 10am:
  print(interpolator(10, 1))
  # 3.37 is the output of the interpolation at 10am.

What next

Check out some of our other blogs. At Evergreen Innovations , we have extensive experience in data analytics and numerical analysis. If you have any questions or there any data analytics topic that you would like us to cover, just contact us.