Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplified cdsapi initialization and updated minimal cdsapi version #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions dfm_tools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def download_ERA5(varkey,
cds_credentials()

# import cdsapi and create a Client instance # https://cds.climate.copernicus.eu/api-how-to
c = cds_client_withargs()
c = cdsapi.Client()

#dictionary with ERA5 variables #this is not actively used
variables_dict = {'ssr':'surface_net_solar_radiation',
Expand Down Expand Up @@ -116,7 +116,7 @@ def cds_credentials():

try:
# checks whether CDS apikey is in environment variable or ~/.cdsapirc file and if it is in correct format
c = cds_client_withargs()
c = cdsapi.Client()
# checks whether credentials (uid and apikey) are correct
c.retrieve(name="dummy", request={})
except Exception as e:
Expand Down Expand Up @@ -164,17 +164,6 @@ def cds_remove_credentials():
os.remove(file_cds_credentials)


def cds_client_withargs():
"""
Initialize a csdapi client with url and key from os environment variables
These are the default values for the url/key arguments, but somehow this
is necessary to use the key/url from environment variables.
"""
c = cdsapi.Client(url=os.environ.get("CDSAPI_URL"),
key=os.environ.get("CDSAPI_KEY"))
return c


def download_CMEMS(varkey,
longitude_min, longitude_max, latitude_min, latitude_max,
date_min, date_max, freq='D',
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ dependencies = [
"bottleneck>=1.3.3",
#xugrid<0.9.0 does not support partitioned 1d2d grids
"xugrid>=0.9.0",
#cdsapi<0.6.1 is from Feb 2021 and does not support newer python versions
"cdsapi>=0.6.1",
#cdsapi<0.7.0 supports credentials from environment variables
"cdsapi>=0.7.0",
#pydap<3.4.0 is from May 2017 and does not support newer python versions
"pydap>=3.4.0",
#erddapy<2.0.0 does not support pandas>=2.0.0
Expand Down
Loading