爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 12645|回复: 3

[经验总结] NCL 对nc文件进行区域掩码

[复制链接]

新浪微博达人勋

发表于 2018-8-31 21:01:29 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
就是比如有全国的降水数据,想从中获取其中某个区域的降水数据(比如只获取黄河流域的),其他的全部制成无效值

需要用到shapefile_utils.ncl  这个文件中的函数,这个文件在官网上能下到,需要流域shape文件


  1. load "$NCARG_ROOT/shapefile_utils.ncl"

  2. begin

  3. f      = addfile("prcp.nc", "r")      ;//打开NC文件
  4. prcp_temp    = f->prcp(0,:,:)                      ;//读取数据

  5. shpfile   = "./liuyu.shp"
  6. print_shapefile_info(shpfile)
  7. plot_shapefile(shpfile)


  8. opt             = True
  9. opt@return_mask = True
  10. opt@shape_var   = "W1102WB0_1"
  11. opt@shape_names = "黄河流域片"

  12. land_mask  = shapefile_mask_data(prcp_temp,shpfile,opt)

  13. prcp_land_mask  =  where(land_mask.eq.1,prcp_temp,prcp_temp@_FillValue)

  14. copy_VarMeta(prcp_temp,prcp_land_mask)

  15. pcp = prcp_land_mask

  16. end
复制代码



密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-9-1 05:10:22 | 显示全部楼层
谢谢大神的经验分享!   
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-3-13 13:30:10 | 显示全部楼层
楼主好,我按您的代码运行出现如下错误,求指教
BDQS@DESKTOP-97QP3T6 ~
$ ncl QTPmask.ncl
Copyright (C) 1995-2019 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 6.6.2
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
warning:_NclOpenFile: Can not open file <./DBATP_Polygon.shp>; file format not supported or file is corrupted
warning:getfilevarnames: f is not a valid file variable
fatal:file (f) isn't defined
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 48 in file ./shapefile_utils.ncl
fatal:["Execute.c":8637]:Execute: Error occurred at or near line 11 in file QTPmask.ncl

以下是我的代码
;load "./gsn_code.ncl"
;load "./gsn_csm.ncl"
;load "./contributed.ncl"
load "./shapefile_utils.ncl"
begin

f      = addfile("1979.nc", "r")      ;//打开NC文件
prcp_temp    = f->temp(0,:,:)                      ;//读取数据

shpfile   = "./DBATP_Polygon.shp"
print_shapefile_info(shpfile)
plot_shapefile(shpfile)


opt             = True
opt@return_mask = True
opt@shape_var   = "W1102WB0_1"
opt@shape_names = "QTP"

land_mask  = shapefile_mask_data(prcp_temp,shpfile,opt)

prcp_land_mask  =  where(land_mask.eq.1,prcp_temp,prcp_temp@_FillValue)

copy_VarMeta(prcp_temp,prcp_land_mask)

pcp = prcp_land_mask

end  


密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-4-13 18:07:25 | 显示全部楼层
qingshan 发表于 2020-3-13 13:30
楼主好,我按您的代码运行出现如下错误,求指教
BDQS@DESKTOP-97QP3T6 ~
$ ncl QTPmask.ncl

我也是出现这种错误,同问,谢谢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表