0

I want to download multiple files for a specific area, one file daily for an specific variable like total rainfall in one month. I'm having problems with the for loop and changing the output file name stored in a desired folder.

Expecting for example january-2022, having 31 files for total precipitation TPdata, like: TP_01_01.nc TP_01_02.nc .... TP_01_31.nc

Mllearner
  • 11
  • 1
  • This needs clarification - if you don't post the code you tried and the error message, how can we help? In the meantime, I have a video on this topic that might help? https://www.youtube.com/watch?v=H47VBPeUGQo – ClimateUnboxed Dec 19 '22 at 21:43

1 Answers1

1

If you have the api request for a day in january 2022 (that you can get in the cds website using a form) you only have to change two things:

  1. add a for cicle before c.retrieve( -and watch the identation-
  2. replace the day in the format for a %s

An example:

#!/usr/bin/env python3
import cdsapi

c = cdsapi.Client()

for x in range(1,32):
  c.retrieve(
    'reanalysis-era5',
    {
        'variable': '2m_dewpoint_temperature',
        'year': '2022',
        'month': '01',
        'day': '%s'%x,
        'time': [
            '00:00', '01:00', '02:00',
            '03:00', '04:00', '05:00',
            '06:00', '07:00', '08:00',
            '09:00', '10:00', '11:00',
            '12:00', '13:00', '14:00',
            '15:00', '16:00', '17:00',
            '18:00', '19:00', '20:00',
            '21:00', '22:00', '23:00',
        ],
        'area': [
            21, -104, 20,
            -103,
        ],
        'format': 'grib',
    },
    'TP_01_%s.grib'%x)