前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Python如何将GrADs常用文件转换为NetCDF格式?

Python如何将GrADs常用文件转换为NetCDF格式?

作者头像
郭好奇同学
发布2021-08-26 17:17:52
发布2021-08-26 17:17:52
2.7K0
举报
文章被收录于专栏:好奇心Log好奇心Log

之前有写过文章使用Ruby和NCL读取转换grd文件,现在有国人开发的GrADs的Python接口xgrads可用于文件格式转换。(点击可跳转!)

首先需要确保xgrads库的安装: pip install xgrads Install from github 或者 git clone https://github.com/miniufo/xgrads.git cd xgrads python setup.py install 链接https://github.com/miniufo/xgrads , 有提供示例ctl和dat文件,下面我们是使用的ctl和grd文件转换的,方法类似: #import sys #sys.path.append('/home/gavin/miniconda3/envs/atmpy/lib/python3.8/site-packages') #sys.path from xgrads import CtlDescriptor, open_CtlDataset ds = open_CtlDataset('lst.ctl') ctl = CtlDescriptor(file='lst.ctl') ds.attrs['pdef' ] = 'None' ds.to_netcdf('lst.nc') data = ds.ro1 data.where(data!=ctl.undef).plot(figsize=(9,5), cmap='jet') 以上需要注意两点: 1.如果在jupyter-lab中无法加载xgrads需要手动添加其路径,使用到的是:import sys 2. xgrads存在bug,如果不添加语句ds.attrs['pdef' ] = 'None'会一直报错,无法生成nc文件!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-08-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 好奇心Log 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 之前有写过文章使用Ruby和NCL读取转换grd文件,现在有国人开发的GrADs的Python接口xgrads可用于文件格式转换。(点击可跳转!)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档