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

简介: 最近,有学习到通过salem处理wrfout数据,非常的简单快捷,读取的变量也比较方面。也可以快速出图,下面简单对比一下xarray和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)


6a9a02e797a1466e879f6f939e6c70a6.png


功能还是非常强大的,但是,注意的是:对于诊断量的计算并不完善,期待后续的跟进。


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


切片


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


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


其中,corners=((100, 0.0), (210, 15))分布表示,提取矩形区域内的左下角的点以及右上角的点的经纬度坐标,如下图所示


c0070e54f993489b90223b589a6bbd86.png


经过我的测试,提取还是比较成功的,但是可能提取的结果并没有那么令人满意,总的来说问题不大。


插值到等压面


一般来说,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


相关文章
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
|
算法框架/工具
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
|
存储 数据可视化 数据挖掘
NumPy 1.26 中文官方指南(二)(2)
NumPy 1.26 中文官方指南(二)
237 0
|
Java 开发者
别再傻傻分不清!Java if-else与switch的性能对比全解析!
别再傻傻分不清!Java if-else与switch的性能对比全解析!
329 1
|
数据处理 API 索引
【Python】已解决:AttributeError: ‘Series‘ object has no attribute ‘sortlevel‘
【Python】已解决:AttributeError: ‘Series‘ object has no attribute ‘sortlevel‘
362 4
|
监控 Rust 安全
Rust代码在公司电脑监控软件中的内存安全监控
使用 Rust 语言开发的内存安全监控软件在企业中日益重要,尤其对于高安全稳定性的系统。文中展示了如何用 Rust 监控内存使用:通过获取向量长度和内存大小来防止泄漏和溢出。此外,代码示例还演示了利用 reqwest 库自动将监控数据提交至公司网站进行实时分析,以保证系统的稳定和安全。
568 2
|
机器学习/深度学习 搜索推荐 算法
降维·预测·救命:PCA、随机森林与乳腺癌
降维·预测·救命:PCA、随机森林与乳腺癌
216 1
|
开发者 索引 Python
Python中调整两列数据顺序的多种方式
Python中调整两列数据顺序的多种方式
816 0
|
Python Windows
python 如何在windows 64系统下安装salem 库
最近,需要用到geopandas + salem裁剪数据,对于salem库的安装,比较麻烦,在我的尝试下,终于算是成功安装了,简单记录一下安装记录,希望可以帮助到有需要的兄弟姐妹们 。
python 如何在windows 64系统下安装salem 库
|
算法
MATLAB | 插值算法 | 二维griddata插值法 | 附数据和出图代码 | 直接上手
MATLAB | 插值算法 | 二维griddata插值法 | 附数据和出图代码 | 直接上手
1184 0