diff --git a/.idea/.name b/.idea/.name index e347a86c433b2ae0cc8e620d280a897a7d5ff770..c27efae63966199781b1f41c90e4c3b8eb81523c 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -characterizationUseCase.py \ No newline at end of file +periodograms.py \ No newline at end of file diff --git a/hpc_case/periodograms.py b/hpc_case/periodograms.py index 06e94cc27d6e1a465dd873873008a83a960c24dd..18ebb9497bd0c2c8c1baaeade8556ca4d376627b 100644 --- a/hpc_case/periodograms.py +++ b/hpc_case/periodograms.py @@ -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)