How to customize file name when downloading

Hi guys,
I was downloading ERA5 daily maximum data using API request python code.
I would like to customize the filenames of the downloaded data instead of having them assigned automatically. Could you please guide me on how to modify the script to achieve this? Thanks.

import cdsapi

#YEARS = range(1961,1962)

#for year in YEARS:

pass

dataset = “derived-era5-single-levels-daily-statistics”
request = {
“product_type”: “reanalysis”,
“variable”: [“2m_temperature”],
“year”: “1961”,
“month”: [
“01”, “02”, “03”,
“04”, “05”, “06”,
“07”, “08”, “09”,
“10”, “11”, “12”
],
“day”: [
“01”, “02”, “03”,
“04”, “05”, “06”,
“07”, “08”, “09”,
“10”, “11”, “12”,
“13”, “14”, “15”,
“16”, “17”, “18”,
“19”, “20”, “21”,
“22”, “23”, “24”,
“25”, “26”, “27”,
“28”, “29”, “30”,
“31”
],
“daily_statistic”: “daily_mean”,
“time_zone”: “utc+00:00”,
“frequency”: “1_hourly”,
“area”: [30.75, 113, 23.75, 119]
}

client = cdsapi.Client()

filename = “era5-daily-mean-2mT-1961.nc”

client.retrieve(dataset, request).download(filename)

Hi,
if you want to name the downloaded files please use this:

filename="era5-daily-mean-2mT-1961.nc"
client.retrieve(dataset, request, filename)

Thanks

1 Like