Is it possible to compute the monthly mean daily minimum and maximum temperature using a workflow for variable 2m temperature from the reanalysis era5 single levels?

I have seen a workflow (here: How to download minimum and maximum air temperature MONTHLY using cdapi?) computing minimum and maximum temperature, but I am interested in the monthly mean daily minimum and maximum temperature. 

2 Comments

  1. ERA5 daily data can be retrieved with their Daily Statistics Calculator, but it is difficult to download a lot of data with it (documentation here). Based on the information you gave me, I provided an example below that works in Python (Jupyter). Unfortunately, you aren't allowed to iterate over multiple statistics, so you'll have to merge the min and max data together at some point after download.

    The following code will download .nc files of daily minimum and maximum 2m temperature monthly for 2020 - 2021 (where daily values are calculated assuming UTC+00:00 over a 1 x 1 degree grid for the whole globe):

    # Import and launch CDS API
    import cdsapi
    c = cdsapi.Client()

    # Specify the directory where your files will be saved to 
    path = '/path/to/files/'

    # Set parameters
    dataset = 'reanalysis-era5-single-levels'
    variable = '2m_temperature'
    months = ['01','02','03','04','05','06','07','08','09','10','11','12']
    years = ['2020','2021']
    statistics = ['daily_minimum','daily_maximum']

    # Loop parameters by statistic, month, then year
    for year in years:
        for month in months:
            for statistic in statistics:
                print('Running: '+statistic+' '+variable+' '+month+'-'+year)
                params={
                    'realm':'c3s',
                    'project':'app-c3s-daily-era5-statistics',
                    'version':'master',
                    'kwargs':{
                        'dataset':dataset,
                        'product_type':'reanalysis',
                        'variable':variable,
                        'statistic':statistic,
                        'year':year,
                        'month':month,
                        'time_zone':'UTC+00:0',
                        'frequency':'1-hourly',
                        'grid':'1.0/1.0',
                        'area':{'lat':[-90,90],'lon':[-180,180]}},
                    'workflow_name':'application'}

                # Carry out daily statistics for the specific iteration
                result = c.service('tool.toolbox.orchestrator.workflow',params)

                # Set iteration filename 
                filename = 'ERA5_'+statistic+'_'+variable+'_'+year+month+'.nc'

                # Write filename into filenames.txt file
                w = open(path+'filenames.txt','a')
                w.write(path+filename+'\n')
              
                # Get data URL from result and allow chunking for reading in data
                url = result[0]['location']    
                readurl = requests.get(url,stream=True)
                
                # Write data from URL to filename in chunks
                print('Writing data to: '+path+filename)
                with open(path+filename,'wb') as fh:
                    for chunk in readurl.iter_content(chunk_size=1024*1024):
                        fh.write(chunk)
                fh.close()
    w.close()

    1. Dear Savannah,

      Thank you so much for your code. It's extremely helpful.

      However, I have a doubt (sorry for my ignorance). You say that your example works in Python (Jupyter), is that mean that I should put your code in Jupyter or can I do it as a workflow in the Toolbox editor of Copernicus?

      Thank you again.

      Best,

      Diego.