WRF | 基础要素绘制

一、概括

前面部分中,我们已经对 WRF 的安装和基础运行进行了介绍,本次内容分享主要一下 WRF 模拟中所使用的网格嵌套和土地类型如何使用 python 进行绘制。

二、土地类型

2.1 结果

2.2 主程序

# 土地类型
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
from mpl_toolkits.basemap import Basemap
from landuse_colormap import *

from wrf import to_np, getvar, smooth2d, get_basemap, latlon_coords

path=r'D:\Project\wrfout_d01_2023-07-01_06_00_00'
ncfile = Dataset(path)

LU_INDEX = getvar(ncfile, "LU_INDEX")

lats, lons = latlon_coords(LU_INDEX)

# Get the basemap object
bm = get_basemap(LU_INDEX)

# Create a figure
fig = plt.figure(figsize=(12,9))

# Add geographic outlines
bm.drawcoastlines(linewidth=0.25)
bm.drawstates(linewidth=0.25)
bm.drawcountries(linewidth=0.25)

# Convert the lats and lons to x and y.  Make sure you convert the lats and
# lons to numpy arrays via to_np, or basemap crashes with an undefined
# RuntimeError.
x, y = bm(to_np(lons), to_np(lats))

cm,labels = LU_MODIS21()
im = plt.pcolormesh(x,y,to_np(LU_INDEX),cmap=cm,vmax=len(labels)+1,vmin=1)
cbar = plt.colorbar(orientation='vertical',shrink=.98,pad=.02)
cbar.set_ticks(np.arange(1.5,len(labels)+1))
cbar.ax.set_yticklabels(labels)
plt.title('MODIS Land Use Categories')
plt.savefig('1.png',bbox_inches='tight',dpi=300)

三、网格嵌套

3.1 结果

3.2 主程序

from salem import geogrid_simulator
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt

namelist_path = r'D:\Project\namelist.wps' # ensure no comments in namelist
g, maps = geogrid_simulator(namelist_path)
print(maps)
fig = plt.figure(1, figsize=(5, 5))
gs = gridspec.GridSpec(1, 1)
ax = fig.add_subplot(gs[0])

# 添加自定义shape文件
# maps[0].set_shapefile(r"/home/province_9south.shp")

# 绘制所有domain
maps[0].set_rgb(natural_earth='lr')
maps[0].visualize(title='Domains')
'''
# 单独绘制d02
maps[1].set_rgb(natural_earth='lr') 
maps[1].visualize(title='Domains')
'''
gs.tight_layout(fig)
plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值