-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathload.py
58 lines (46 loc) · 2.08 KB
/
load.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
import csv
import numpy as np
#Define function for loading solar data
def load_solar_data(path_data: str, path_labels:str) -> tuple:
"""
Load and preprocess solar data and labels for GAN training
"""
with open(f'{path_data}' if path_data.endswith('csv') else f'{path_data}.csv', 'r') as csvfile:
rows = np.array([row for row in csv.reader(csvfile)], dtype=float)
#Specify according to time points in your own dataset
rows = rows[:104832,:]
print('\nShape rows (data raw):', rows.shape)
with open(f'{path_labels}' if path_labels.endswith('csv') else f'{path_labels}.csv', 'r') as csvfile:
labels = np.array([row for row in csv.reader(csvfile)], dtype=int)
print('\nShape labels (labels raw):', labels.shape)
#Transform data to conform to GAN image input dimensions (24x24 = 576)
trX = np.reshape(rows.T,(-1,576))
print('\nShape trX (data preprocessed):',trX.shape)
trY = np.tile(labels,(32,1))
print('\nShape trY (labels preprocessed):', trY.shape)
m = np.ndarray.max(rows)
print("\nMax(Solar) =", m)
trX = trX/m
return trX, trY, m
#Define function for loading wind data
def load_wind_data(path_data: str, path_labels: str) -> tuple:
"""
Load and preprocess solar data and labels for GAN training
"""
#Example dataset created for evnet_based GANs wind scenarios generation
# Data from NREL wind integrated datasets
with open(f'{path_data}' if path_data.endswith('csv') else f'{path_data}.csv', 'r') as csvfile:
rows = np.array([row for row in csv.reader(csvfile)], dtype=float)
trX = []
m = np.ndarray.max(rows)
print('\nMax(Wind)', m)
for x in range(rows.shape[1]):
train = rows[:-288, x].reshape(-1, 576)
train = train / m
trX.extend(train)
trX = np.asarray(trX)
print('\nShape TrX', trX.shape)
with open(f'{path_labels}' if path_labels.endswith('csv') else f'{path_labels}.csv', 'r') as csvfile:
label = np.array([row for row in csv.reader(csvfile)], dtype=int)
print('\nShape Label', label.shape)
return trX, label, m