-
Notifications
You must be signed in to change notification settings - Fork 0
/
EE_interp.py
59 lines (52 loc) · 2.31 KB
/
EE_interp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 08 09:58:05 2016
@author: utente
Iterpolation of electric energy demand
"""
import pandas as pd
import numpy as np
from scipy.interpolate import interp1d
from os import listdir
from os.path import isfile, join
from collections import OrderedDict
import matplotlib.pyplot as plt
path = 'C:\Users\utente\Documents\PUN\curve_domanda'
#curves = pd.read_csv('C:\\Users\\utente\\Documents\\PUN\\curve domanda\\Default Dataset_2016-09-07.csv',sep=',', header=None)
###################################################################################################
def Extract_Dataset(path):
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
ndict = OrderedDict()
for of in onlyfiles:
df = pd.read_csv('C:\\Users\\utente\\Documents\\PUN\\curve_domanda\\'+of, sep=',', header=None)
for j in range(df.shape[0]):
if 'h-'+str(j) in ndict:
ndict['h-'+str(j)].append(df[df.columns[1]].ix[j])
else:
ndict['h-'+str(j)] = [df[df.columns[1]].ix[j]]
DF = pd.DataFrame.from_dict(ndict)
rng = pd.date_range(start="2016-09-07", periods = DF.shape[0],freq = 'D')
DF = DF.set_index(rng)
DF.to_csv('C:\\Users\\utente\\Documents\\PUN\\demand_curves.csv', sep=',', header = True)
print 'dimensions of the updated dataset: {}'.format(DF.shape)
return DF
###################################################################################################
def get_InterpolatedCurves(path):
DF = Extract_Dataset(path)
x = range(DF.shape[1])
new_x = np.linspace(0, 24, 100)
for i in range(DF.shape[0]):
fhat = interp1d(x, DF.ix[i], kind = 'cubic')
fig = plt.figure()
plt.plot(new_x, fhat(new_x))
fig.suptitle('electric energy demand for {} '.format(str(DF.index[i])))
#plt.savefig('C:\Users\utente\Documents\PUN\curve domanda\plots\curve_demand for {} '.format(str(DF.index[i])))
###################################################################################################
#DF = Extract_Dataset(path)
#
#x = range(DF.shape[1])
#new_length = 100
#new_x = np.linspace(0, 23, new_length)
#fhat = interp1d(x, DF.ix[1], kind='cubic')
#plt.figure()
#plt.plot(new_x, fhat(new_x))