Skip to content
Snippets Groups Projects
Commit 71f80d27 authored by dlandre2's avatar dlandre2
Browse files

title + xlabel + print in perdiodograms.py

parent 6f6039fd
No related branches found
No related tags found
No related merge requests found
characterizationUseCase.py
\ No newline at end of file
periodograms.py
\ No newline at end of file
......@@ -20,7 +20,7 @@ def filterTime(series, filterTimeInSec):
return seriesFiltered
def differentiateSeries(series): # Differentiating a non-stationary time series with no trend
print("Differentiation")
print("A differentiation of the time series is necessary. There is no trend\n")
seriesDiff = []
for i in range(len(series) - 1):
seriesDiff.append(series[i] - series[i + 1])
......@@ -28,10 +28,13 @@ def differentiateSeries(series): # Differentiating a non-stationary time series
def printPeriodogram(series): # Show periodogram and top 8 frequencies in time series.
print("Displaying the periodogram of the time series\n")
# Periodogram
freqencies, spectrum = periodogram(series)
plt.plot(freqencies, spectrum, color='blue')
plt.grid(True, linestyle='-', which='major', alpha=0.5, axis='both')
plt.title("Periodogram of the time series")
plt.xlabel('Frequency (Hz)', fontsize=45)
plt.ylabel('Power spectral density', fontsize=45)
plt.xticks(fontsize=40)
......@@ -50,6 +53,8 @@ def printPeriodogram(series): # Show periodogram and top 8 frequencies in time s
print(val)
def stationaryTestsResults(series, alpha): # Assessing the stationarity of a time series using ADF and KPSS tests
print("Testing the stationarity of the time series")
# ADF test
testAdf = adfuller(series)
# p-value
......@@ -61,35 +66,47 @@ def stationaryTestsResults(series, alpha): # Assessing the stationarity of a tim
print("The p-value KPSS:", testKpss[1])
if testAdf[1] <= alpha <= testKpss[1]:
print("The series is stationary")
print("The time series is stationary\n")
else:
print("The series is not stationary")
print("The time series is not stationary\n")
def removeTrend(series, granularity): # Removing the trend component from the time series if it is present
print("A trend component is present")
print("Displaying the time series with trend\n")
x_abs = [i for i in range(len(series))]
low = lowess(series, x_abs, frac=granularity)
low = [v[1] for v in low]
plt.plot(series)
plt.title("Time series with trend")
plt.plot(low)
plt.xlabel("time (hour)")
plt.show()
series_without_trend = [val - tr for val, tr in zip(series, low)]
print("Displaying the time series without its trend\n")
plt.plot(series_without_trend)
plt.title("Time series without trend")
plt.xlabel("time (hour)")
plt.show()
return series_without_trend
def plotSeries(series):
plt.plot(series)
plt.title("Time series")
plt.xlabel("time (hour)")
plt.show()
def execution(List):
for l in List:
print("######################################")
print(l[2])
X = filterTime(l[0], l[1])
print("Displaying the time series\n")
plotSeries(X)
stationaryTestsResults(X, alphaUsed)
if l[3] == "T":
......@@ -97,6 +114,7 @@ def execution(List):
stationaryTestsResults(X, alphaUsed)
elif l[3] == "D":
X = differentiateSeries(X)
print("Displaying the differentiate time series\n")
plotSeries(X)
stationaryTestsResults(X, alphaUsed)
printPeriodogram(X)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment