-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_json_spain.py
More file actions
96 lines (65 loc) · 3.32 KB
/
Copy pathmake_json_spain.py
File metadata and controls
96 lines (65 loc) · 3.32 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from datetime import date
from weather.weather import WeatherExtractor, WeatherApi
import pandas as pd
from weather_combined import Weather_combined
from weather_separate import Weather_separate
def print_data(weather_data):
for row in weather_data.iterrows():
# row is tuple (index, columns)
measure = row[1]
print "Measurement of %s at from %s for %s" % (measure['shortName'], measure['validDateTime'], measure['validityDateTime'])
for lat, lon, val in zip(measure['lats'], measure['lons'], measure['values']):
print "%f N %f S = %f" % (lat, lon, val)
def panda_to_jsonfile(pd, file_name):
pd.to_json(path_or_buf=file_name, orient='records', date_format='iso', date_unit='s')
# query the downloaded data
we = WeatherExtractor()
# load actual and forecasted weather data
print 'load grib file'
we.load(['spain_jan2017_dec2017.grib'])
print 'get_forecast per city'
csv = pd.read_csv('spanish_coordinates.csv')
wc = Weather_combined()
ws = Weather_separate()
for i in range(len(csv)):
print "i %d city %s" % (i, csv.loc[i,"City"])
points = [{'lat': csv.loc[i,"Latitude"], 'lon': csv.loc[i,"Longitude"]}]
weather_data = we.get_forecast(base_date=date(2017, 1, 1), from_date=date(
2017, 1, 1), to_date=date(2017, 12, 31), aggtime='hour', aggloc='points',
interp_points=points)
wc.add_city_weather_data(csv.loc[i,"City"], weather_data)
ws.add_city_weather_data(csv.loc[i,"City"], weather_data)
print 'Generate the result forecast'
# print_data(weather_data)
panda_to_jsonfile(pd.Series(wc.get_dict_values()), 'spain_cities_forecast_combined.json')
panda_to_jsonfile(pd.Series(ws.get_dict_values()), 'spain_cities_forecast_separate.json')
wc = Weather_combined()
ws = Weather_separate()
for i in range(len(csv)):
print "i %d city %s" % (i, csv.loc[i,"City"])
points = [{'lat': csv.loc[i,"Latitude"], 'lon': csv.loc[i,"Longitude"]}]
weather_data = we.get_actual(from_date=date(
2017, 1, 1), to_date=date(2017, 12, 31), aggtime='hour', aggloc='points',
interp_points=points)
wc.add_city_weather_data(csv.loc[i,"City"], weather_data)
ws.add_city_weather_data(csv.loc[i,"City"], weather_data)
print 'Generate the result actual'
# print_data(weather_data)
panda_to_jsonfile(pd.Series(wc.get_dict_values()), 'spain_cities_actual_combined.json')
panda_to_jsonfile(pd.Series(ws.get_dict_values()), 'spain_cities_actual_separate.json')
#print 'get_actual'
#weather_data = we.get_actual(from_date=date(
# 2017, 11, 1), to_date=date(2017, 11, 30), aggtime='hour', aggloc='grid')
#panda = make_panda_combined(weather_data)
#panda_to_jsonfile(panda, 'actual_full1.json')
#panda = make_panda_separate(weather_data)
#panda_to_jsonfile(panda, 'actual_full2.json')
""" Get forecasted data from 1-11-2017 for 2-11-2017, 3-11-2017 and 4-11-2017 for
two specific points with latitudes and longitudes: (45.01, 13.00) and (46.00, 12.05) """
#points = [{'lat': 45.01, 'lon': 13.0}, {'lat': 46.0, 'lon': 12.05}]
#weather_data = we.get_forecast(base_date=date(2017, 11, 1), from_date=date(
# 2017, 11, 2), to_date=date(2017, 11, 4), aggtime='hour', aggloc='points', interp_points=points)
# print the result
#print_data(weather_data)
#panda = make_panda(weather_data)
#panda_to_jsonfile(panda, 'test2.json')