0

I have some data I'd like to download from the era5 via the cdsapi package.

I do know most data can be downloaded via using cdsapi.Client.retrieve function. Such as many examples I can find at stack overflow (cdsapi era5 download to computer).

However, the data I want is the statistic data (https://cds.climate.copernicus.eu/cdsapp#!/software/app-c3s-daily-era5-statistics?tab=app), and they are provided by ERA5 daily statistics calculator, and can be dowmloaded by via CDS API according to ERA5 daily statistics user guide (https://datastore.copernicus-climate.eu/documents/app-c3s-daily-era5-statistics/C3S_Application-Documentation_ERA5-daily-statistics-v2.pdf). So after read the guide, I used following python script to download, and it worked. However, the only problem here is the data I got had the random file name, and it would be very hard to find certain file.

1 .So I'm wondering if there is any way I can set the download filename myself when downloading the data

  1. My second question is the script only allows me to down one variable (2m_temperature) in one nc file, however, I want to other variables can be downloaded at the same time, I've tried to added more (I have commented out the other required variables), but I got the error like "TypeError: Object of type 'set' is not JSON serializable", so I'm wondering if it is possible to download multiple variables

`

import cdsapi
c = cdsapi.Client(timeout=600)


YEARS = range(1950,1951) 
MONTHS = ["01","02","03","04","05","06","07","08","09","10","11","12"]

for year in YEARS:
for month in MONTHS:

    result = c.service(
    "tool.toolbox.orchestrator.workflow",
    params={
    "realm": "user-apps",
    "project": "app-c3s-daily-era5-statistics",
    "version": "master",
    "kwargs": {"dataset": "reanalysis-era5-single-levels",
    "product_type": "reanalysis",
    "variable": "2m_temperature", 
    # "variable": {"2m_temperature", "2m_dewpoint_temperature", "10m_u_component_of_wind", "10m_v_component_of_wind"},
    "statistic": "daily_mean",
    "year": year,
    "month": month,
    "time_zone": "UTC+00:00",
    "frequency": "1-hourly",
    "grid": "0.25/0.25",
    "area": {"lat": [25.15265, 52.84375], "lon": [-124.59375, -67.03125]}
    },
    "workflow_name": "application"
    })
    c.download(result)

1 Answer 1

0

You need

c.download(result,["filename"])

Make sure filename is in a list (I think that is a glitch on their part)

For question 2 you need to put the variables in a list , that is, square brackets, not curly brackets, which is for a dictionary.

4
  • I exremely appreciated your response. I tried your suggestion for filename, and it worked now. But for question 2 about multiple variables, I repalced square curly by square brackets, bur got some errors (I attached as follows, I cannot paste them all once, so I made several comments here).
    – Gioia
    Commented Jun 13 at 20:13
  • 2024-06-13 16:05:03,849 ERROR Message: 2024-06-13 16:05:03,849 ERROR Reason: Traceback (most recent call last): File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 59, in handle_request result = cached(context.method, proc, context, context.args, context.kwargs) File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached result = proc(context, *context.args, **context.kwargs) File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 124, in call return p(*args, **kwargs)
    – Gioia
    Commented Jun 13 at 20:18
  • File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 60, in call return self.proc(context, *args, **kwargs) File "/home/cds/cdsservices/services/python_service.py", line 38, in execute raise exceptions.InternalError(logging + traceback, '') cdsclient.exceptions.InternalError: Traceback (most recent call last): File "/opt/cdstoolbox/jsonrequest/jsonrequest/requests.py", line 71, in jsonrequestcall resp = coding.encode(req.callable(*req.args, **req.kwargs), register=encoders, **context)
    – Gioia
    Commented Jun 13 at 20:18
  • File "/opt/cdstoolbox/cdstools/cdstools/util.py", line 367, in resample resample = data.resample(label=label, closed=closed, keep_attrs=keep_attrs, AttributeError: 'list' object has no attribute 'resample' 2024-06-13 16:05:03,849 ERROR Traceback (most recent call last): 2024-06-13 16:05:03,849 ERROR File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 59, in handle_request 2024-06-13 16:05:03,850 ERROR result = cached(context.method, proc, context, context.args, context.kwargs)
    – Gioia
    Commented Jun 13 at 20:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.