Dilation#

Dilation Module

This module contains functions to dilate a signal from a regular time grid to a dilated time grid and to undilate it back.

class solardatatools.algorithms.dilation.Dilation(data_handler, nvals_dil=101, matrix='raw')#

Bases: object

plot_heatmap(space='original', figsize=(12, 6), scale_to_kw=True, year_lines=True, units=None)#
run()#
solardatatools.algorithms.dilation.build_dilated_idx(sunrises, sunsets, signal_idx_ori, nvals_dil=101)#

This function builds a float index from 00:00 first day to the last sunset of the last day (eg. 18:37) for the dilated signal. The last point of the index is the end of the last time bin (00:00 next day).

Parameters:
  • sunrises – ndarray, 1D array with the sunrise times (length ndays).

  • sunsets – ndarray, 1D array with the sunset times (length ndays).

  • signal_idx_ori – ndarray, 1D array with the original index (length nvals_ori*ndays + 1).

  • nvals_dil – int, number of values per day for the dilated signal. Default is 101.

Returns:

ndarray, 1D array with the dilated index (length nvals_dil*ndays + 2).

solardatatools.algorithms.dilation.check_sanity(tnew, t, x, alignment)#

This functions performs basic checks on the input parameters of the interpolate function.

Parameters:
  • tnew – ndarray, new time points for interpolation (length n). Last point is the end of the last time bin.

  • t – ndarray, original time points (length m).

  • x – ndarray, original signal values (length m).

  • alignment – str, time bin label alignement, either ‘left’ or ‘right’.

Raises:
  • ValueError – raised if t and tnew do not have at least two values.

  • ValueError – raised if t values are not sorted.

  • ValueError – raised if tnew values are not sorted.

  • ValueError – raised if tnew values are not within the range of t values.

  • ValueError – raised if t does not have the same shape as x.

  • ValueError – raised if alignment is not ‘left’ or ‘right’.

solardatatools.algorithms.dilation.compute_integral_interpolation(ttnew, xxnew, new_indices)#

This function computes the interpolation of the signal for the new time points by computing the integral.

Parameters:
  • ttnew – ndarray, 1D array with the original and new time points (length m+n).

  • xxnew – ndarray, 1D array with the original and temporary new signal values (length m+n).

  • new_indices – ndarray, 1D array with the indices of the points in tnew (length n).

Returns:

ndarray, 1D array with the interpolated signal for the new time points (length n-1).

solardatatools.algorithms.dilation.dilate_signal(signal_idx_dil, signal_idx_ori, signal_ori)#

This function dilates a signal from a regular time grid to a dilated time grid.

Parameters:
  • signal_idx_dil – ndarray, 1D array with the dilated index (length n).

  • signal_idx_ori – ndarray, 1D array with the original index (length m).

  • signal_ori – ndarray, 1D array with the original signal values (length m-1).

Returns:

ndarray, 1D array with the dilated signal values (length n-1).

solardatatools.algorithms.dilation.extrapolate_signal_after_sunset(signal, nvals, ndays, method)#

This generic function extrapolates a signal after sunset to add a zero value at the beginning of every night.

Parameters:
  • signal – ndarray, 1D array with the signal values (length nvals*ndays + 2).

  • nvals – int, number of values per day for the signal.

  • ndays – int, number of days in the signal.

  • method – str, method to use for the extrapolation, either ‘linear’ or ‘zero_padding’.

Raises:

ValueError – raised if method is not ‘linear’ or ‘zero_padding’.

Returns:

ndarray, 1D array with the signal values after the extrapolation (length (nvals+1)*ndays + 2).

solardatatools.algorithms.dilation.initialize_arrays(tnew, t, x, alignment)#
solardatatools.algorithms.dilation.interpolate(tnew, t, x, alignment='left')#

This function interpolates a signal for a new set of points while maintaining constant signal energy.

Parameters:
  • tnew – ndarray, 1D array with the new time points for interpolation (length n). Last point is the end of the last time bin.

  • t – ndarray, 1D array with the original time points (length m).

  • x – ndarray, 1D array with the original signal values (length m).

  • alignment – str, time bin label alignement, either ‘left’ or ‘right’.

Returns:

ndarray, 1D array with the interpolated signal for the new time points (length n-1).

solardatatools.algorithms.dilation.undilate_quantiles(signal_idx_ori, signal_idx_dil, quantiles_dil, nvals_dil=101)#

This function undilates a 2D matrix of quantiles from the dilated time grid to the regular time grid.

Parameters:
  • signal_idx_ori – ndarray, 1D array with the original index (length m).

  • signal_idx_dil – ndarray, 1D array with the dilated index (length n).

  • quantiles_dil – ndarray, 2D array with the quantile values in the dilated time grid (shape (n-1, p)).

  • nvals_dil – int, number of values per day for the dilated signal. Default is 101.

Returns:

ndarray, 2D array with the quantile values in the original time grid (shape (m-1, p)).

solardatatools.algorithms.dilation.undilate_signal(signal_idx_ori, signal_idx_dil, signal_dil)#

This function undilates a signal from the dilated time grid to the regular time grid.

Parameters:
  • signal_idx_ori – ndarray, 1D array with the original index (length m).

  • signal_idx_dil – ndarray, 1D array with the dilated index (length n).

  • signal_dil – ndarray, 1D array with the dilated signal values (length n-1).

Returns:

ndarray, 1D array with the original signal values (length m-1).