用NCL将GRIB/GRIB2文件转成nc文件(批量转),JRA-55再分析为例

  • Post author:
  • Post category:其他



背景




答主最近需要用到JRA-55再分析数据,但在面对GRIB数据格式时犯难了,便想把GRIB格式转成nc文件再做分析。因为nc文件很容易用python或Matlab处理

尝试了好些方法,发现先安装NCL再用ncl来批量转换,是一种比较便捷的方式。在此记录下来与大家分享


第一部分

:安装ncl,安装过程见这个帖子,很详细。https://blog.csdn.net/littlesqgg/article/details/112716228?spm=1001.2014.3001.5506

需要补充的是,在安装完时,只需要在Cygwin Terminal中输入ncl,当显示出如下内容时就表示已经安装完成。不需要像前面给出的链接中的答主那样“*

输入 source ~/.bashrc,Enter执行, 再输入 ncl

*”

$ ncl
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
ncl 0>


第二部分

:将GRIB格式的文件批量转成nc文件


1. 首先你需要把所有要转的GRIB文件放在一个文件夹中,如下图所示,我的文件夹中有4个文件

在这里插入图片描述


2. 打开Cygwin terminal,并在终端中输入如下代码:

先进入到你想要存储的文件夹

cd "I:/Reanalysis/JRA-55/test"

执行转化的命令

find "I:/Reanalysis/JRA-55/test" -type f | grep -i "anl_surf" | xargs -I{} ncl_convert2nc {} -e grib


  • I:/Reanalysis/JRA-55/test

    ” 内表示你的文件所在的路径


  • anl_surf

    ” 表示你要转化的文件的通配符,也就是ncl会选取含有这一串字符的文件来做转化


3. 在输完上述代码后,就会显示如下信息,则说明文件被转化成nc文件了:

$ find "I:/Reanalysis/JRA-55/test" -type f | grep -i "anl_surf" | xargs -I{} ncl  _convert2nc {} -e grib
Processing file: I:/Reanalysis/JRA-55/test/anl_surf.033_ugrd.reg_tl319.196001_19  6012...
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
Classic model NetCDF does not support string types, converting initial_time0 to   a character array
Dimension 'ncl_strlen_0' will be added


4. 打开文件夹查看,发现得到了生成的nc文件


在这里插入图片描述


第三部分

:将单个GRIB文件转成nc文件(比批量简单)


1. 先转到你想要存储的文件夹

cd "I:/Reanalysis/JRA-55/test"


2. 输入转化命令


下述引号内为要转的GRIB文件的路径

ncl_convert2nc "I:/Reanalysis/JRA-55/6-hourly/anl_surf.033_ugrd.reg_tl319.2019010100_2019013118" -e grib


3. 显示如下代码则表示成功

Processing file: anl_surf.033_ugrd.reg_tl319.2019010100_2019013118...
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
Classic model NetCDF does not support string types, converting initial_time0 to a character array
Dimension 'ncl_strlen_0' will be added



版权声明:本文为gourmet2原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。