# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 16:13:44 2020

@author: Carmen Lewis (carmen@solarXY.org)

Function for calculating the fast Fourier Transform 
and sample standard deviation.
"""

import numpy as np
import scipy.fftpack
from statistics import stdev 

Ts = 60.0               #sampling time or interval
Fs = 1.0/Ts             #sampling rate or frequency
t = np.arange(0,1,Ts)   #time vector
n = 15
k = np.arange(n)
T = n/Fs                #period
frq = k/T               #two-sided frequency range
frq = frq[:int(n/2)]    #one-side frequency range

def fft_sd(D):
    if len(D) == 15:
        #fast fourier transform of 15-minute period
        Y_ghi = scipy.fftpack.fft(D)
        Y_ghi = Y_ghi[:int(n/2)]
        powr = ((abs(Y_ghi))**2)[1:]
        frq2 = frq[1:]
        
        #calculate the first derivative
        dy=np.diff(powr,1)
        dx=np.diff(frq2,1)
        yfirst=dy/dx
        xfirst=0.5*(frq2[:-1]+frq2[1:])
                    
        #calculate the second derivative
        dyfirst=np.diff(yfirst,1)
        dxfirst=np.diff(xfirst,1)
        ysecond=dyfirst/dxfirst
                    
        #Calculate the sample standard deviation 
        #(measure of statistical dispersion)
        SD = stdev(ysecond)/1000**2

    else:
        SD = np.nan

    return SD
20789d316205f577728d5f6c7a71324f3391873e
<mask token>

<mask token>


def fft_sd(D):
    if len(D) == 15:
        Y_ghi = scipy.fftpack.fft(D)
        Y_ghi = Y_ghi[:int(n / 2)]
        powr = (abs(Y_ghi) ** 2)[1:]
        frq2 = frq[1:]
        dy = np.diff(powr, 1)
        dx = np.diff(frq2, 1)
        yfirst = dy / dx
        xfirst = 0.5 * (frq2[:-1] + frq2[1:])
        dyfirst = np.diff(yfirst, 1)
        dxfirst = np.diff(xfirst, 1)
        ysecond = dyfirst / dxfirst
        SD = stdev(ysecond) / 1000 ** 2
    else:
        SD = np.nan
    return SD

<mask token>
Ts = 60.0
Fs = 1.0 / Ts
t = np.arange(0, 1, Ts)
n = 15
k = np.arange(n)
T = n / Fs
frq = k / T
frq = frq[:int(n / 2)]


def fft_sd(D):
    if len(D) == 15:
        Y_ghi = scipy.fftpack.fft(D)
        Y_ghi = Y_ghi[:int(n / 2)]
        powr = (abs(Y_ghi) ** 2)[1:]
        frq2 = frq[1:]
        dy = np.diff(powr, 1)
        dx = np.diff(frq2, 1)
        yfirst = dy / dx
        xfirst = 0.5 * (frq2[:-1] + frq2[1:])
        dyfirst = np.diff(yfirst, 1)
        dxfirst = np.diff(xfirst, 1)
        ysecond = dyfirst / dxfirst
        SD = stdev(ysecond) / 1000 ** 2
    else:
        SD = np.nan
    return SD

<mask token>
import numpy as np
import scipy.fftpack
from statistics import stdev
Ts = 60.0
Fs = 1.0 / Ts
t = np.arange(0, 1, Ts)
n = 15
k = np.arange(n)
T = n / Fs
frq = k / T
frq = frq[:int(n / 2)]


def fft_sd(D):
    if len(D) == 15:
        Y_ghi = scipy.fftpack.fft(D)
        Y_ghi = Y_ghi[:int(n / 2)]
        powr = (abs(Y_ghi) ** 2)[1:]
        frq2 = frq[1:]
        dy = np.diff(powr, 1)
        dx = np.diff(frq2, 1)
        yfirst = dy / dx
        xfirst = 0.5 * (frq2[:-1] + frq2[1:])
        dyfirst = np.diff(yfirst, 1)
        dxfirst = np.diff(xfirst, 1)
        ysecond = dyfirst / dxfirst
        SD = stdev(ysecond) / 1000 ** 2
    else:
        SD = np.nan
    return SD

# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 16:13:44 2020

@author: Carmen Lewis (carmen@solarXY.org)

Function for calculating the fast Fourier Transform 
and sample standard deviation.
"""

import numpy as np
import scipy.fftpack
from statistics import stdev 

Ts = 60.0               #sampling time or interval
Fs = 1.0/Ts             #sampling rate or frequency
t = np.arange(0,1,Ts)   #time vector
n = 15
k = np.arange(n)
T = n/Fs                #period
frq = k/T               #two-sided frequency range
frq = frq[:int(n/2)]    #one-side frequency range

def fft_sd(D):
    if len(D) == 15:
        #fast fourier transform of 15-minute period
        Y_ghi = scipy.fftpack.fft(D)
        Y_ghi = Y_ghi[:int(n/2)]
        powr = ((abs(Y_ghi))**2)[1:]
        frq2 = frq[1:]
        
        #calculate the first derivative
        dy=np.diff(powr,1)
        dx=np.diff(frq2,1)
        yfirst=dy/dx
        xfirst=0.5*(frq2[:-1]+frq2[1:])
                    
        #calculate the second derivative
        dyfirst=np.diff(yfirst,1)
        dxfirst=np.diff(xfirst,1)
        ysecond=dyfirst/dxfirst
                    
        #Calculate the sample standard deviation 
        #(measure of statistical dispersion)
        SD = stdev(ysecond)/1000**2

    else:
        SD = np.nan

    return SD