python处理era5_如何保存为每日文件而不是每月(Python、ERA5、ECMWF)

这是我目前使用API检索数据的脚本,目标是“每月”文件。我需要缩小一个文件的大小,以腾出时间准备和传输数据。主要通过尝试在日常文件中定位/写入,例如…..20151001.grib。在

由于我是Python的初学者,我在这里发帖希望有人愿意帮助我改进这个脚本,主要考虑目标/编写文件。在

谢谢你!

/约瑟芬#!/usr/bin/env python

import calendar

from ecmwfapi import ECMWFDataServer

server = ECMWFDataServer()

def retrieve_era5():

"""

A function to demonstrate how to iterate efficiently over several years and months etc

for a particular era5 request.

Change the variables below to adapt the iteration to your needs.

You can use the variable 'target' to organise the requested data in files as you wish.

In the example below the data are organised in files per month. (eg "era5_daily_201510.grb")

"""

yearStart = 2010

yearEnd = 2017

monthStart = 1

monthEnd = 12

for year in list(range(yearStart, yearEnd + 1)):

for month in list(range(monthStart, monthEnd + 1)):

startDate = '%04d%02d%02d' % (year, month, 1)

numberOfDays = calendar.monthrange(year, month)[1]

lastDate = '%04d%02d%02d' % (year, month, numberOfDays)

target = "/Volumes/JOSEFINE/ERA5/era5_sfc_6hr_%04d%02d%.grb" % (year, month)

requestDates = (startDate + "/TO/" + lastDate)

era5_request(requestDates, target)

def era5_request(requestDates, target):

"""

An ERA5 request for analysis pressure level data.

Change the keywords below to adapt it to your needs.

(eg to add or to remove levels, parameters, times etc)

"""

server.retrieve({

"class": "ea", # do not change

"dataset": "era5", # do not change

"expver": "1", # do not change

"stream": "oper", # do not change

"type": "an", # analysis (versus forecast, fc)

"date": requestDates, # dates, set automatically from above

"levtype": "sfc", # pressure level data (versus surface, sfc, and model level, ml)

"param": "134.128/136.128/137.128/165.128/166.128/232.128/246.228/247.228", # see http://apps.ecmwf.int/codes/grib/param-db

"target": target, # output file name, set automatically from above

"time": "00:00/06:00/12:00/18:00", # times of analysis (with type:an), or initialization time of forecast (with type:fc)

"grid": "0.25/0.25", # Optional for GRIB, required for NetCDF. The horizontal resolution in decimal degrees. If not set, the archived grid as specified in the data documentation is used.

"area": "90/-40/-30/120", # Optional. Subset (clip) to an area. Specify as N/W/S/E in Geographic lat/long degrees. Southern latitudes and western longitudes must be

"RESOL" : "AV",

})

if __name__ == '__main__':

retrieve_era5()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值