-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
54 lines (35 loc) · 1.57 KB
/
script.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
#!/usr/bin/env python
# coding: utf-8
# In[3]:
import pandas, glob, penmon.eto as pm
SOURCE_DIR="data/sourcedata/"
OUTPUT_DIR="data/"
pm.CHECK_RADIATION_RANGE=False
def calculate_eto(col):
try:
day = pm.Station(col["latitude"], col["altitude"], anemometer_height=10).get_day(col["date"].strftime("%Y-%m-%d"),
temp_min=round(col["temp_min"], 1),
temp_max=round(col["temp_max"], 1),
wind_speed=round(col["wind_speed"],1),
humidity_mean=round(col["humidity_mean"] * 100, 1),
radiation_s=round(col["solar_radiation"], 1))
return day.eto()
except:
raise Exception("Exception raised while processing line:\n" + str(col))
count = 0
dataframes=[]
all_csv_files = glob.glob(SOURCE_DIR+"*.csv")
for csv_file in all_csv_files:
df = pandas.read_csv(csv_file, header=0,
names=["date", "longitude", "latitude", "altitude", "temp_max",
"temp_min", "precip", "wind_speed","humidity_mean", "solar_radiation", None],
parse_dates=[0], index_col=None)
df["eto"] = df.apply(calculate_eto, axis=1)
dataframes.append(df)
count += 1
print("Processed ", count, "files")
df=pandas.concat(dataframes)
df.to_csv(OUTPUT_DIR+"eto.csv", index=False, columns=["date", "latitude", "longitude", "altitude", "temp_min", "temp_max",
"wind_speed", "humidity_mean", "solar_radiation", "precip", "eto"])
# In[4]:
df.head(5)