33# coding:=utf-8
44
55import argparse
6- import python_query_api as api
76import datetime as dt
87import sys
98
9+ import meteomatics .api as api
10+
1011'''
1112 For further information on available parameters, models etc. please visit
1213 api.meteomatics.com
2021username = 'python-community'
2122password = 'Umivipawe179'
2223
24+
2325def example ():
2426 ###Input timeseries:
2527 now = dt .datetime .utcnow ().replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
@@ -30,6 +32,7 @@ def example():
3032 parameters_ts = ['t_2m:C' , 'rr_1h:mm' ]
3133 model = 'mix'
3234 ens_select = None # e.g. 'median'
35+ cluster_select = None # e.g. "cluster:1", see http://api.meteomatics.com/API-Request.html#cluster-selection
3336 interp_select = 'gradient_interpolation'
3437
3538 ###Input grid / grid unpivoted:
@@ -43,7 +46,7 @@ def example():
4346 parameter_grid = 'evapotranspiration_1h:mm' # 't_2m:C'
4447
4548 parameters_grid_unpiv = ['t_2m:C' , 'rr_1h:mm' ]
46- valid_dates_unpiv = [dt .datetime .utcnow (), dt .datetime .utcnow ()+ dt .timedelta (days = 1 )]
49+ valid_dates_unpiv = [dt .datetime .utcnow (), dt .datetime .utcnow () + dt .timedelta (days = 1 )]
4750
4851 ###input grid png
4952 filename_png = "grid_target.png"
@@ -65,47 +68,49 @@ def example():
6568 model_grads = 'ecmwf-ifs'
6669 area_grads = 'europe'
6770
68-
6971 ###input netcdf
7072 filename_nc = "path_netcdf/netcdf_target.nc"
7173 startdate_nc = now
72- enddate_nc = startdate_nc + dt .timedelta (days = 1 )
74+ enddate_nc = startdate_nc + dt .timedelta (days = 1 )
7375 interval_nc = dt .timedelta (days = 1 )
7476 parameter_nc = 't_2m:C'
7577
7678 ###input png timeseries
7779 # prefixpath_png_ts = 'path/to/directory' #TODO
7880 prefixpath_png_ts = '' # TODO
7981 startdate_png_ts = now
80- enddate_png_ts = startdate_png_ts + dt .timedelta (days = 2 )
82+ enddate_png_ts = startdate_png_ts + dt .timedelta (days = 2 )
8183 interval_png_ts = dt .timedelta (hours = 12 )
8284 parameter_png_ts = 't_2m:C'
8385
8486 ###input grads timeseries
8587 # prefixpath_grads_ts = 'path/to/directory' #TODO
86- prefixpath_grads_ts = '' # TODO
88+ prefixpath_grads_ts = '' # TODO
8789 startdate_grads_ts = now
88- enddate_grads_ts = startdate_grads_ts + dt .timedelta (days = 2 )
89- interval_grads_ts = dt .timedelta (hours = 24 )
90- parameters_grads_ts = ['t_500hPa:C' ,'gh_500hPa:m' ]
90+ enddate_grads_ts = startdate_grads_ts + dt .timedelta (days = 2 )
91+ interval_grads_ts = dt .timedelta (hours = 24 )
92+ parameters_grads_ts = ['t_500hPa:C' , 'gh_500hPa:m' ]
9193 model_grads_ts = 'ecmwf-ifs'
92- area_grads_ts = 'australia' # For Lat/Lon setting: None
94+ area_grads_ts = 'australia' # For Lat/Lon setting: None
9395
9496 ###input station data timeseries
9597 startdate_station_ts = startdate_grads_ts - dt .timedelta (days = 2 )
96- enddate_station_ts = startdate_grads_ts - dt .timedelta (hours = 3 )
97- interval_station_ts = dt .timedelta (hours = 1 )
98- parameters_station_ts = ['t_2m:C' ,'wind_speed_10m:ms' ,'precip_1h:mm' ]
98+ enddate_station_ts = startdate_grads_ts - dt .timedelta (hours = 3 )
99+ interval_station_ts = dt .timedelta (hours = 1 )
100+ parameters_station_ts = ['t_2m:C' , 'wind_speed_10m:ms' , 'precip_1h:mm' ]
99101 model_station_ts = 'mix-obs'
100- coordinates_station_ts = [(47.43 ,9.4 ), (50.03 ,8.52 )] #St. Gallen / Frankfurt/Main
101- wmo_stations = ['066810' ] #St. Gallen
102- metar_stations = ['EDDF' ] #Frankfurt/Main
102+ coordinates_station_ts = [(47.43 , 9.4 ), (50.03 , 8.52 )] # St. Gallen / Frankfurt/Main
103+ wmo_stations = ['066810' ] # St. Gallen
104+ metar_stations = ['EDDF' ] # Frankfurt/Main
105+ mch_stations = ['STG' ] # MeteoSchweiz Station St. Gallen
103106
104107 limits = api .query_user_features (username , password )
105108
106109 print ("\n time series:" )
107110 try :
108- df_ts = api .query_time_series (coordinates_ts , startdate_ts , enddate_ts , interval_ts , parameters_ts , username , password , model , ens_select , interp_select )
111+ df_ts = api .query_time_series (coordinates_ts , startdate_ts , enddate_ts , interval_ts , parameters_ts ,
112+ username , password , model , ens_select , interp_select ,
113+ cluster_select = cluster_select )
109114 print (df_ts .head ())
110115 except Exception as e :
111116 print ("Failed, the exception is {}" .format (e ))
@@ -120,28 +125,32 @@ def example():
120125 if limits ['area request option' ]:
121126 print ("\n grid:" )
122127 try :
123- df_grid = api .query_grid (startdate_grid , parameter_grid , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon , username , password )
128+ df_grid = api .query_grid (startdate_grid , parameter_grid , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon ,
129+ username , password )
124130 print (df_grid .head ())
125131 except Exception as e :
126132 print ("Failed, the exception is {}" .format (e ))
127133
128134 print ("\n unpivoted grid:" )
129135 try :
130- df_grid_unpivoted = api .query_grid_unpivoted (valid_dates_unpiv , parameters_grid_unpiv , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon , username , password )
136+ df_grid_unpivoted = api .query_grid_unpivoted (valid_dates_unpiv , parameters_grid_unpiv , lat_N , lon_W , lat_S ,
137+ lon_E , res_lat , res_lon , username , password )
131138 print (df_grid_unpivoted .head ())
132139 except Exception as e :
133140 print ("Failed, the exception is {}" .format (e ))
134141
135142 print ("\n grid timeseries:" )
136143 try :
137- df_grid_timeseries = api .query_grid_timeseries (startdate_ts , enddate_ts , interval_ts , parameters_ts , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon , username , password )
144+ df_grid_timeseries = api .query_grid_timeseries (startdate_ts , enddate_ts , interval_ts , parameters_ts , lat_N ,
145+ lon_W , lat_S , lon_E , res_lat , res_lon , username , password )
138146 print (df_grid_timeseries .head ())
139147 except Exception as e :
140148 print ("Failed, the exception is {}" .format (e ))
141149
142150 print ("\n grid as a png:" )
143151 try :
144- api .query_grid_png (filename_png , startdate_png , parameter_png , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon , username , password )
152+ api .query_grid_png (filename_png , startdate_png , parameter_png , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon ,
153+ username , password )
145154 print ("filename = {}" .format (filename_png ))
146155 except Exception as e :
147156 print ("Failed, the exception is {}" .format (e ))
@@ -172,15 +181,17 @@ def example():
172181 if limits ['model select option' ]:
173182 print ("\n netCDF file:" )
174183 try :
175- api .query_netcdf (filename_nc , startdate_nc , enddate_nc , interval_nc , parameter_nc , lat_N , lon_W , lat_S , lon_E ,
184+ api .query_netcdf (filename_nc , startdate_nc , enddate_nc , interval_nc , parameter_nc , lat_N , lon_W , lat_S ,
185+ lon_E ,
176186 res_lat , res_lon , username , password )
177187 print ("filename = {}" .format (filename_nc ))
178188 except Exception as e :
179189 print ("Failed, the exception is {}" .format (e ))
180190
181191 print ("\n Grads plot:" )
182192 try :
183- api .query_grads (filename_grads , startdate_grads , parameters_grads , lat_N , lon_W , lat_S , lon_E , res_lat , res_lon ,
193+ api .query_grads (filename_grads , startdate_grads , parameters_grads , lat_N , lon_W , lat_S , lon_E , res_lat ,
194+ res_lon ,
184195 username , password , model_grads , area = area_grads )
185196 print ("filename = {}" .format (filename_grads ))
186197 except Exception as e :
@@ -197,15 +208,17 @@ def example():
197208
198209 print ("\n find stations:" )
199210 try :
200- met = api .query_station_list (username , password , startdate = startdate_station_ts , enddate = enddate_station_ts , parameters = parameters_station_ts )
211+ met = api .query_station_list (username , password , startdate = startdate_station_ts , enddate = enddate_station_ts ,
212+ parameters = parameters_station_ts )
201213 print (met .head ())
202214 except Exception as e :
203215 print ("Failed, the exception is {}" .format (e ))
204216
205217 print ("\n station coordinates timeseries:" )
206218 try :
207219 df_sd_coord = api .query_station_timeseries (startdate_station_ts , enddate_station_ts , interval_station_ts ,
208- parameters_station_ts , username , password , model = model_station_ts ,
220+ parameters_station_ts , username , password ,
221+ model = model_station_ts ,
209222 latlon_tuple_list = coordinates_station_ts ,
210223 on_invalid = 'fill_with_invalid' , request_type = "POST" ,
211224 temporal_interpolation = 'none' )
@@ -218,29 +231,39 @@ def example():
218231 df_sd_ids = api .query_station_timeseries (startdate_station_ts , enddate_station_ts , interval_station_ts ,
219232 parameters_station_ts , username , password , model = model_station_ts ,
220233 wmo_ids = wmo_stations , metar_ids = metar_stations ,
221- on_invalid = 'fill_with_invalid' , request_type = "POST" ,
222- temporal_interpolation = 'none' )
234+ mch_ids = mch_stations , on_invalid = 'fill_with_invalid' ,
235+ request_type = "POST" , temporal_interpolation = 'none' )
223236 print (df_sd_ids .head ())
224237 except Exception as e :
225238 print ("Failed, the exception is {}" .format (e ))
226239
227240 print ("\n get init dates:" )
228241 try :
229- df_init_dates = api .query_init_date (now , now + dt .timedelta (days = 2 ), dt .timedelta (hours = 3 ), 't_2m:C' , username ,
242+ df_init_dates = api .query_init_date (now , now + dt .timedelta (days = 2 ), dt .timedelta (hours = 3 ), 't_2m:C' ,
243+ username ,
230244 password , 'ecmwf-ens' )
231245 print (df_init_dates .head ())
232246 except Exception as e :
233247 print ("Failed, the exception is {}" .format (e ))
248+
249+ print ("\n get available time ranges:" )
250+ try :
251+ df_time_ranges = api .query_available_time_ranges (['t_2m:C' , 'precip_6h:mm' ], username , password ,
252+ 'ukmo-euro4' )
253+ print (df_time_ranges .head ())
254+ except Exception as e :
255+ print ("Failed, the exception is {}" .format (e ))
256+
234257 else :
235258 print ("""
236259Your account '{}' does not include model selection.
237260With the corresponding upgrade you could query data from stations and request your data in netcdf or grads format.
238- Please check http://shop.meteomatics.com or contact us at shop@meteomatics.com for an individual offer.
261+ Please check http://shop.meteomatics.com or contact us at shop@meteomatics.com for an individual offer.
239262""" .format (username )
240263 )
241264
242265
243- if __name__ == "__main__" :
266+ if __name__ == "__main__" :
244267 parser = argparse .ArgumentParser ()
245268 parser .add_argument ('--username' , default = username )
246269 parser .add_argument ('--password' , default = password )
@@ -250,7 +273,8 @@ def example():
250273 password = arguments .password
251274
252275 if username is None or password is None :
253- print ("You need to provide a username and a password, either on the command line or by inserting them in the script" )
276+ print (
277+ "You need to provide a username and a password, either on the command line or by inserting them in the script" )
254278 sys .exit ()
255279
256280 example ()
0 commit comments