-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprecalculate_time_series.py
52 lines (36 loc) · 1.85 KB
/
precalculate_time_series.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
import solve
from server import compute_weather_hash
import hashlib, json
import pandas as pd
countries = "country:" + pd.Index(solve.get_country_multipolygons().keys())
regions = "region:" + pd.Index(solve.get_region_multipolygons().keys())
locations = countries.append(regions)
country_names = solve.get_country_names()
years = range(2011,2013)
techs = ["solar","onwind"]
cf_exponents = [2.,1.,0.]
for cf_exponent in cf_exponents:
for year in years:
matrix_sums = pd.DataFrame(0.,index=locations,columns=techs)
for location in locations:
assumptions = {"year" : year,
"location" : location,
"cf_exponent" : cf_exponent,
"version" : 190929,
"job_type" : "weather"}
if location[:len("country:")] == "country:":
assumptions["location_name"] = country_names[location[len("country:"):]]
elif location[:len("region:")] == "region:":
assumptions["location_name"] = location[len("region:"):]
else:
assumptions["location_name"] = "None"
assumptions["weather_hex"] = compute_weather_hash(assumptions)
print(location, assumptions["location_name"], year, cf_exponent, assumptions["weather_hex"])
pu, matrix_sum, error_msg = solve.get_weather(location, year, cf_exponent)
weather_csv = 'data/time-series-{}.csv'.format(assumptions["weather_hex"])
pu.round(3).to_csv(weather_csv)
with open('data/weather-assumptions-{}.json'.format(assumptions['weather_hex']), 'w') as fp:
json.dump(assumptions,fp)
for tech in techs:
matrix_sums.loc[location,tech] = matrix_sum[tech]
matrix_sums.to_csv("data/matrix_sums-{}-{}.csv".format(year,cf_exponent))