ERA5日均数据下载处理

该博客介绍了如何通过Python和CDSAPI工具从Copernicus Climate Data Store批量下载ERA5-Land的每日平均气象数据,包括2米温度和土壤温度层1等变量。文章提供了详细的代码示例,展示了如何设置参数,如年份、月份、统计类型和输出网格分辨率,并将数据转换为netCDF格式。处理后的文件可在ENVI中进一步处理为单波段TIFF文件。
摘要由CSDN通过智能技术生成

下载ERA5-Land数据及数据处理(每小时转日数据)_是一个橙子呀的博客-CSDN博客_cdsapi怎么安装

ERA5逐日资料下载方法-数据资料-气象家园_气象人自己的家园

Retrieve daily ERA5/ERA5-Land data using the CDS API - Copernicus User Support Forum - ECMWF Confluence Wiki

ERA5数据下载和批处理教程_江湖是你画中亦是你的博客-CSDN博客_era-5shujuchuli 

Log in |

利用python批量下载ERA5-Daily数据_可乐要加冰_ice的博客-CSDN博客_era5 数据下载

ERA5逐日资料下载方法-数据资料-气象家园_气象人自己的家园

How to install and use CDS API on Windows - Copernicus Knowledge Base - ECMWF Confluence Wiki

Retrieve daily ERA5/ERA5-Land data using the CDS API - Copernicus User Support Forum - ECMWF Confluence Wiki

# -*- coding: utf-8 -*-
"""
@author:hangsirm
"""
import time

import cdsapi
import requests
import multiprocessing

# CDS API script to use CDS service to retrieve daily ERA5* variables and iterate over
# all months in the specified years.

# Requires:
# 1) the CDS API to be installed and working on your system
# 2) You have agreed to the ERA5 Licence (via the CDS web page)
# 3) Selection of required variable, daily statistic, etc

# Output:
# 1) separate netCDF file for chosen daily statistic/variable for each month

# Uncomment years as required
# For valid keywords, see Table 2 of:
# https://datastore.copernicus-climate.eu/documents/app-c3s-daily-era5-statistics/C3S_Application-Documentation_ERA5-daily-statistics-v2.pdf
# select your variable; name must be a valid ERA5 CDS API name.
# Select the required statistic, valid names given in link above


c = cdsapi.Client()  # timeout=300
years = [str(id1) for id1 in range(2013, 2014)]
# months = ['%02d' % id2 for id2 in range(1, 13)]
months = ['01', '02', '12']

# var = "2m_temperature"
# 下载的数据类型
stat = "daily_mean"

# vars = ['2m_temperature', 'soil_temperature_level_1', 'snow_density']
vars = ['2m_temperature', 'soil_temperature_level_1']



def Download(iyear, imonth, var):
    t000 = time.time()
    result = c.service(
        "tool.toolbox.orchestrator.workflow",
        params={

            "realm": "c3s",
            "project": "app-c3s-daily-era5-statistics",
            "version": "master",
            "kwargs": {
                "dataset": "reanalysis-era5-land",
                "product_type": "reanalysis",
                "variable": var,
                "statistic": stat,
                "year": iyear,
                "month": imonth,
                "time_zone": "UTC+00:0",
                "frequency": "1-hourly",
                #
                # Users can change the output grid resolution and selected area
                #
               "grid": "0.1/0.1", # 10km分辨率
               "area": {
                   "lat": [24, 41],
                   "lon": [64, 106]
               }
            },
            "workflow_name": "application"
        }
    )

    # set name of output file for each month (statistic, variable, year, month

    file_name = r"G:\ERA5\\" + stat + "_" + var + iyear + imonth + ".nc"

    location = result[0]['location']
    res = requests.get(location, stream=True)
    print("Writing data to " + file_name)
    with open(file_name, 'wb') as fh:
        for r in res.iter_content(chunk_size=1024):
            fh.write(r)
    fh.close()
    print('***样本%s 保存结束, 耗时: %.3f s / %.3f mins****************' % (
    file_name, (time.time() - t000), (time.time() - t000) / 60))


if __name__ == "__main__":
    t0 = time.time()
    # ===================================================================================
    print('*****************程序开始*********************')
    for v in vars:

        for yr in years:
            for mn in months:
                Download(yr, mn, v)
    print('***********************程序结束, 耗时: %.3f s / %.3f mins****************' % (
        (time.time() - t0), (time.time() - t0) / 60))






代码注意事项:

1、变量命名,2m_temperature不能是2m temperature,下划线不能改成空格

2、在user下要有cdsapirc文件

处理好的文件是nc格式,在arcgis中打开只显示一个波段,并且看不到有哪些数据集,要在ENVI中打开,可以用IDL处理为单波段

for b = 0, dim[3] - 1 do begin
      data_wind2 = fltarr(dim[1],dim[2])    

      for m = 0,dim[1]-1 do begin
        for n = 0,dim[2]-1 do begin
          temp = data_wind[*,*,b]
          data_wind2[m,n] = temp[m,abs(n-dim[2]+1)];南北颠倒
     
        endfor
      endfor
      write_tiff,'G:\ERA5Test\'+tifname+string(b+1,format='(i2.2)')+'.tif',data_wind2,geotiff=geo,/FLOAT
      ;write_tiff,'E:\wdtif\'+tifname+'_tair.tif',data_wind,geotiff=geo,/FLOAT;图像是倒置的
      print,'G:\ERA5Test\'+tifname+string(b+1,format='(i2.2)')+'.tif'+" is ok!"
endfor

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值