-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataProcessing.py
More file actions
60 lines (54 loc) · 2.58 KB
/
Copy pathDataProcessing.py
File metadata and controls
60 lines (54 loc) · 2.58 KB
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
60
"""A Python Function meant for processing NetCDF arrays into a CSV format
usable for training the correction models."""
import pandas as pd
from pandas import read_csv
import csv
def CSVWriter(Data = 'nothing'):
counter = 0
with open('CustomTable.csv', mode='w') as table:
writer = csv.writer(table, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
#Write Headers
writer.writerow(["Lon","Lat","Time","ReforecastTemp","ReanalysisTemp","ModelError",
"Precipitation", "CloudCover", "Landuse",
"Water","Ice","Land","Shallow Water", "Desert"])
MegaTable = pd.read_csv("MegaTable.csv")
for time in range(0,407,30):
counter = counter+1
for lon in range(359):
counter = counter+1
for lat in range(179):
counter = counter+1
#Create all the CSV Variables
CSVReforecastLongitude = lon
CSVReforecastLatitude = lat
if Data != 'nothing':
CSVReforecastTemp = Data[time,lat+1,lon+1]
CSVReanalysisTemp = Data[time,lat+1,lon+1]
CSVModelError = CSVReanalysisTemp - CSVReforecastTemp
else:
CSVReforecastTemp = 0
CSVReanalysisTemp = 0
CSVModelError = 0
if counter < 899650:
CSVPrecipitation = MegaTable['Precipitation'][counter]
CSVCloudCover = MegaTable['CloudCover'][counter]
CSVLanduseType = MegaTable['Landuse'][counter]
#OneHotEncoder part:
Water = 0
Ice = 0
Land = 0
ShallowWater = 0
Desert = 0
if CSVLanduseType == 1:
Water = 1
if CSVLanduseType == 7:
Ice = 1
if CSVLanduseType == 13:
Land = 1
if CSVLanduseType == 14:
ShallowWater = 1
if CSVLanduseType == 19:
Desert = 1
writer.writerow([CSVReforecastLongitude,CSVReforecastLatitude,time,CSVReforecastTemp,
CSVReanalysisTemp,CSVModelError, CSVPrecipitation, CSVCloudCover, CSVLanduseType,
Water, Ice, Land, ShallowWater, Desert])