NetCDF: How to mask/filter out non-land values in global dataset, preferably using Python and/or NCO?

陌路散爱 提交于 2019-12-06 08:02:33

Once you have a variable on the same grid to mask with, you can use ncap2 where, e.g.,

ncap2 -s 'where(LANDMASK != 1) prcp=prcp@_FillValue' in.nc out.nc

If your mask is on a different grid than your data, you can use (on Linux/Mac) the masking features of ncremap, e.g., to remap your data to your mask (or visa versa) with something like

ncremap --msk_dst=LANDMASK -d mask.nc prcp_in.nc prcp_out.nc

A solution with CDO

# make landseamask on 0.25 grid with 1 for land and missing for sea
cdo -P 8 -f nc2 setctomiss,0 -gtc,0 -remapcon,r1440x720 -topo seamask.nc

# not sure if you need to do this but lets put your data on same grid
cdo remapcon,r1440x720 yourdata.nc yourdataremap.nc

# now mask the data
cdo mul yourdataremap.nc seamask.nc yourdatamasked.nc

hope that works...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!