使用salem处理wrfout数据,进行切片、并插值到等压面

使用salem处理wrfout数据,进行切片、并插值到等压面

最近,有学习到通过salem处理wrfout数据,非常的简单快捷,读取的变量也比较方面。也可以快速出图,下面简单对比一下xarray和salem读取wrfout文件的区别:

import xarray as xr

from salem.utils import get_demo_file

ds = xr.open_dataset(get_demo_file('wrfout_d01.nc'))

可以发现,通过xarray 读取wrfout文件的内容非常的混乱,让人摸不着头脑,无从下手


Out[4]: ds
<xarray.Dataset>
Dimensions:  (Time: 3, south_north: 150, west_east: 150, bottom_top: 27, west_east_stag: 151, south_north_stag: 151, bottom_top_stag: 28)
Coordinates:
    XLONG    (Time, south_north, west_east) float32 ...
    XLONG_U  (Time, south_north, west_east_stag) float32 ...
    XLAT_U   (Time, south_north, west_east_stag) float32 ...
    XLAT_V   (Time, south_north_stag, west_east) float32 ...
    XLONG_V  (Time, south_north_stag, west_east) float32 ...
    XLAT     (Time, south_north, west_east) float32 ...
Dimensions without coordinates: Time, south_north, west_east, bottom_top, west_east_stag, south_north_stag, bottom_top_stag
Data variables:
    Times    (Time) |S19 ...
    T2       (Time, south_north, west_east) float32 ...
    RAINC    (Time, south_north, west_east) float32 ...
    RAINNC   (Time, south_north, west_east) float32 ...
    U        (Time, bottom_top, south_north, west_east_stag) float32 ...
    V        (Time, bottom_top, south_north_stag, west_east) float32 ...
    PH       (Time, bottom_top_stag, south_north, west_east) float32 ...
    PHB      (Time, bottom_top_stag, south_north, west_east) float32 ...
Attributes:
    note:     Global attrs removed.

而如果使用salem的话,则大大简化:

import salem

ds = salem.open_wrf_dataset(get_demo_file('wrfout_d01.nc'))

Out[7]: ds
<xarray.Dataset>
Dimensions:       (time: 3, south_north: 150, west_east: 150, bottom_top: 27)
Coordinates:
    lon           (south_north, west_east) float32 70.72 70.97 ... 117.5 117.8
    lat           (south_north, west_east) float32 7.789 7.829 ... 46.52 46.46
  * time          (time) datetime64[ns] 2008-10-26T12:00:00 ... 2008-10-26T18...
  * west_east     (west_east) float64 -2.235e+06 -2.205e+06 ... 2.235e+06
  * south_north   (south_north) float64 -2.235e+06 -2.205e+06 ... 2.235e+06
Dimensions without coordinates: bottom_top
Data variables: (12/14)
    T2            (time, south_north, west_east) float32 ...
    RAINC         (time, south_north, west_east) float32 ...
    RAINNC        (time, south_north, west_east) float32 ...
    U             (time, bottom_top, south_north, west_east) float32 ...
    V             (time, bottom_top, south_north, west_east) float32 ...
    PH            (time, bottom_top, south_north, west_east) float32 ...
    ...            ...
    PRCP          (time, south_north, west_east) float32 ...
    WS            (time, bottom_top, south_north, west_east) float32 ...
    GEOPOTENTIAL  (time, bottom_top, south_north, west_east) float32 ...
    Z             (time, bottom_top, south_north, west_east) float32 ...
    PRCP_NC       (time, south_north, west_east) float32 ...
    PRCP_C        (time, south_north, west_east) float32 ...
Attributes:
    note:        Global attrs removed.
    pyproj_srs:  +proj=lcc +lat_0=29.0399971008301 +lon_0=89.8000030517578 +l...

可以发现,已经重命名了一些维度/坐标,定义了新的变量。

同时,salem也可以实现快速出图的功能:

ds.PRCP.isel(time=-1).salem.quick_map(cmap='Purples', vmax=5)

在这里插入图片描述
功能还是非常强大的,但是,注意的是:对于诊断量的计算并不完善,期待后续的跟进。

下面根据我的需求,使用的函数进行简单记录:

切片

首先是实现对于纬度切片的功能, 假设我只需要纬度:0-15°N范围的数据,可以这样实现:

ds = ds.salem.subset(corners=((100, 0.0), (210, 15)))

其中,corners=((100, 0.0), (210, 15))分布表示,提取矩形区域内的左下角的点以及右上角的点的经纬度坐标,如下图所示
在这里插入图片描述
经过我的测试,提取还是比较成功的,但是可能提取的结果并没有那么令人满意,总的来说问题不大。

插值到等压面

一般来说,wrf模式跑出的数据是: eta-levels,对于分析和作图来说是非常不方便的,因此salem也提供了 wrf_zlevel()wrf_plevel() 两个函数,分布实现对于等高面和等压面的插值,这里仅示范插值到等压面的用法,使用如下所示:

DatasetAccessor.wrf_plevel(varname, levels=None, fill_value=nan, use_multiprocessing=True)
ds.isel(time=0).salem.wrf_plevel('V', levels=[850.])

“U”:你要插值的变量
levels:你要插值的气压层

通过上述两个方法,就能实现切片和插值的需求啦~

官网链接:salem

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

简朴-ocean

继续进步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值