Skip to content

Commit 8ce3916

Browse files
mikofskicwhanse
authored andcommitted
put SERVER in try and catch KeyError (#650)
* put SERVER in try and catch KeyError * if `.ecmwfapirc` not in `$HOME` * or `ECMWF_API_KEY` not set to path to `.ecmwfapirc` * [DOC] add important info about ECMWF key * key should be saved as `$HOME\.ecmwfapirc` * or set `ECMWF_API_KEY` as the path to the key * remove SERVER constant
1 parent 0486c3b commit 8ce3916

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pvlib/iotools/ecmwf_macc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ def ECMWFDataServer(*a, **kw):
2323
'To download data from ECMWF requires the API client.\nSee https:/'
2424
'/confluence.ecmwf.int/display/WEBAPI/Access+ECMWF+Public+Datasets'
2525
)
26-
SERVER = None
27-
else:
28-
SERVER = ECMWFDataServer()
2926

3027
#: map of ECMWF MACC parameter keynames and codes used in API
3128
PARAMS = {
@@ -58,7 +55,7 @@ def _ecmwf(server, startdate, stopdate, params, targetname):
5855

5956

6057
def get_ecmwf_macc(filename, params, startdate, stopdate, lookup_params=True,
61-
server=SERVER, target=_ecmwf):
58+
server=None, target=_ecmwf):
6259
"""
6360
Download data from ECMWF MACC Reanalysis API.
6461
@@ -75,7 +72,7 @@ def get_ecmwf_macc(filename, params, startdate, stopdate, lookup_params=True,
7572
lookup_params : bool, default True
7673
optional flag, if ``False``, then codes are already formatted
7774
server : ecmwfapi.api.ECMWFDataServer
78-
optionally provide a server object, default is given
75+
optionally provide a server object, default is ``None``
7976
target : callable
8077
optional function that calls ``server.retrieve`` to pass to thread
8178
@@ -86,9 +83,11 @@ def get_ecmwf_macc(filename, params, startdate, stopdate, lookup_params=True,
8683
8784
Notes
8885
-----
89-
To download data from ECMWF requires the API client. For more information,
90-
see the `documentation
86+
To download data from ECMWF requires the API client and a registration
87+
key. Please read the documentation in `Access ECMWF Public Datasets
9188
<https://confluence.ecmwf.int/display/WEBAPI/Access+ECMWF+Public+Datasets>`_.
89+
Follow the instructions in step 4 and save the ECMWF registration key
90+
as `$HOME\.ecmwfapirc` or set `ECMWF_API_KEY` as the path to the key.
9291
9392
This function returns a daemon thread that runs in the background. Exiting
9493
Python will kill this thread, however this thread will not block the main

0 commit comments

Comments
 (0)