Skip to content

Commit 05de0df

Browse files
author
Nino Rasic
committed
Update to version 2.0.0
1 parent 8ee91ed commit 05de0df

File tree

10 files changed

+356
-210
lines changed

10 files changed

+356
-210
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Meteomatics AG
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
[![logo](http://www.meteomatics.com/s/de_DE/5639/a252d7f5e75d7a8bf7047b4b2c92f71a56a8f048.29/2.6.1/_/download/resources/com.meteomatics.confluence.website-plugin:meteomatics-website-theme/images/meteomatics-logo.png)](http://www.meteomatics.com "Meteomatics - Your Experts in Weather Data Processing")
1+
[![PyPI](https://img.shields.io/pypi/v/meteomatics.svg)](https://pypi.python.org/pypi/meteomatics)
22

3-
Python connector to the [Meteomatics API](http://api.meteomatics.com/Overview.html "Documentation Overwiev")
4-
===================================================================================
3+
[![logo](https://www.meteomatics.com/wp-content/uploads/2019/01/meteomatics-logo_trans_sm-1.png)](http://www.meteomatics.com "Meteomatics - Your Experts in Weather Data Processing")
4+
5+
Python connector to the [Meteomatics Weather API](https://www.meteomatics.com/en/api/overview/ "Documentation Overview")
6+
===================================================================================
7+
8+
9+
Meteomatics provides a REST-style API to retrieve historic, current, and forecast data globally. This includes model data and observational data in time series and areal formats. Areal formats are also offered through a WMS/WFS-compatible interface. Geographic and time series data can be combined in certain file formats, such as NetCDF.
10+
11+
12+
Install by typing `pip install meteomatics` in your favourite shell.
13+
14+
For a start we recommend to run the example script.

__init__.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

example.py renamed to examples/example.py

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
# coding:=utf-8
44

55
import argparse
6-
import python_query_api as api
76
import datetime as dt
87
import 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
@@ -20,6 +21,7 @@
2021
username = 'python-community'
2122
password = 'Umivipawe179'
2223

24+
2325
def 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("\ntime 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("\ngrid:")
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("\nunpivoted 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("\ngrid 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("\ngrid 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("\nnetCDF 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("\nGrads 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("\nfind 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("\nstation 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("\nget 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("\nget 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("""
236259
Your account '{}' does not include model selection.
237260
With 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()

meteomatics/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from __version__ import __version__

meteomatics/__version__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
__version__ = "2.0.0"

0 commit comments

Comments
 (0)