1. 数据下载(ERA5)
新技能 get!
main idea 是从Climate Data Store https://cds.climate.copernicus.eu/cdsapp#!/home 获取url后通过IDM批量下载
import cdsapi
import calendar
from subprocess import call
def idmDownloader(task_url, folder_path, file_name):
"""
IDM下载器
:param task_url: 下载任务地址
:param folder_path: 存放文件夹
:param file_name: 文件名
:return:
"""
# IDM安装目录
idm_engine = "C:\\Program Files (x86)\\Internet Download Manager\\IDMan.exe"
# 将任务添加至队列
call([idm_engine, '/d', task_url, '/p', folder_path, '/f', file_name, '/a'])
# 开始任务队列
call([idm_engine, '/s'])
if __name__ == '__main__':
c = cdsapi.Client() # 创建用户
# 数据信息字典
dic = {
'product_type': 'reanalysis', # 产品类型
'format': 'grib', # 数据格式
'variable': [
'geopotential','relative_humidity','specific_humidity',
'temperature','u_component_of_wind','v_component_of_wind'
], # 变量名称
'pressure_level': [
'1','2','3',
'5','7','10',
'20','30','50',
'70', '100','125',
'150', '175',
'200', '225', '250',
'300', '350', '400',
'450', '500', '550',
'600', '650', '700',
'750', '775', '800',
'825', '850', '875',
'900', '925', '950',
'975', '1000',
],
'year': '2018', # 年,设为空
'month': '05', # 月,设为空
'day': [ '01', '02','03','04','05','06','07',], # 日,设为空
'time': [ # 小时
'00:00', '06:00', '12:00',
'18:00'
],
'area': [90, -180, 45, 180],
}
# 通过循环批量下载1979年到2020年所有月份数据
'''
for y in range(1979, 2021): # 遍历年
for m in range(1, 13): # 遍历月
day_num = calendar.monthrange(y, m)[1] # 根据年月,获取当月日数
# 将年、月、日更新至字典中
dic['year'] = str(y)
dic['month'] = str(m).zfill(2)
dic['day'] = [str(d).zfill(2) for d in range(1, day_num + 1)]
'''
r = c.retrieve('reanalysis-era5-pressure-levels', dic, ) # 文件
url = r.location # 获取文件下载地址
path = 'E:\\ERA5\\' # 存放文件夹
filename = 'pressure'+str(2018) + str(5).zfill(2) + '.grib' # 文件名
idmDownloader(url, path, filename) # 添加进IDM中下载
以上是三维数据的下载,单层数据的下载同理:
import cdsapi
import calendar
from subprocess import call
if __name__ == '__main__':
c = cdsapi.Client() # 创建用户
# 数据信息字典
dic = {
'product_type': 'reanalysis', # 产品类型
'format': 'grib', # 数据格式
'variable': [
'10m_u_component_of_wind', '10m_v_component_of_wind', '2m_temperature',
'mean_sea_level_pressure', 'sea_surface_temperature', 'skin_temperature',
'snow_albedo', 'snow_depth', 'snowfall',
'soil_temperature_level_1', 'soil_type', 'surface_pressure',
'total_precipitation','soil_temperature_level_2',
'soil_temperature_level_3','soil_temperature_level_4',
'volumetric_soil_water_layer_1','volumetric_soil_water_layer_2',
'volumetric_soil_water_layer_3', 'volumetric_soil_water_layer_4',
],
'year': '2018', # 年,设为空
'month': '05', # 月,设为空
'day': [ '01', '02','03','04','05','06','07',], # 日,设为空
'time': [ # 小时
'00:00', '06:00', '12:00',
'18:00'
],
'area': [90, -180, 45, 180],
}
# 通过循环批量下载1979年到2020年所有月份数据
'''
for y in range(1979, 2021): # 遍历年
for m in range(1, 13): # 遍历月
day_num = calendar.monthrange(y, m)[1] # 根据年月,获取当月日数
# 将年、月、日更新至字典中
dic['year'] = str(y)
dic['month'] = str(m).zfill(2)
dic['day'] = [str(d).zfill(2) for d in range(1, day_num + 1)]
'''
r = c.retrieve('reanalysis-era5-single-levels', dic, ) # 文件
url = r.location # 获取文件下载地址
path = 'E:\\ERA5\\' # 存放文件夹
filename = 'single'+str(2018) + str(5).zfill(2) + '.grib' # 文件名
idmDownloader(url, path, filename) # 添加进IDM中下载
2. WPS 前处理
2.1 修改namelist.wps
&share
wrf_core = 'ARW',
max_dom =1,
start_date = '2018-05-01_12:00:00','2019-09-04_12:00:00', # 模拟开始&结束日期
end_date = '2018-05-07_00:00:00','2019-09-04_12:00:00',
interval_seconds = 21600 # 模拟间隔
/
&geogrid
parent_id = 1,
parent_grid_ratio = 1,
i_parent_start = 1,
j_parent_start = 1,
e_we = 150,
e_sn = 150,
geog_data_res = '10m',
dx = 45000,
dy = 45000,
map_proj = 'polar',
ref_lat = 90.00,
ref_lon = 0.0,
truelat1 = 60.0,
truelat2 = 60.0,
stand_lon = 0.0,
geog_data_path = '/public/home/zyh/WRF/Build_WRF/WPS_GEOG/'
/
&ungrib
out_format = 'WPS',
prefix = 'FILE',
/
&metgrid
fg_name = 'FILE'
/
~
geogrid
修改完后在WPS文件夹下执行geogrid.exe
./geogrid.exe
执行成功后会产生geo_em.d01.nc
文件
ls -lah geo_em.d01.nc
ungrib
首先创建链接
ln -sf ungrib/Variable_Tables/Vtable.ECMWF Vtable
随后连接数据
./link_grib.csh ../ERA5/*.grib
成功后出现GRIBFILE.AAA, GRIBFILE.AAB
等文件
之后运行ungrib
./ungrib.exe
成功后出现FILE:2018-05-06_00
等文件
metgrid
直接运行metgrid.exe
./metgrid.exe
成功后出现met_em.d01.xxxx-xx-xx_xx:xx:xx.nc
格式的文件