Project

General

Profile

Mask NETCDF file by shapefile?

Added by L. Santos about 4 years ago

hello everyone, could someone help me?
I'm trying to make a mask for a netcdf file just from my study area, which is the shapefile area that I have.
I used an NCL script to transform my shapefile file into netcdf. So you can use it in the CDO to make the mask. However, the CDO cannot read the file I created with the NCL
the script I used was this one, proposed by a user of this forum

load "/usr/local/lib/ncarg/nclscripts/shapefile_utils.ncl" ; 
begin
shpname = "/home/Luiz/bacia_ama_bolivia.shp"
maskname = "/home/Luiz/mask_bolivia.nc"
print_shapefile_info(shpname)
;-- open data file to get the grid to be used
f = addfile("GPM_DJF.nc","r")
;print(f)
vNames = getfilevarnames (f) ; Pegar o nome das variaveis no arquivo
;print(vNames) ; mostrar o nome das variaveis
; Devem estar os nomes de cada variavel do arquivo selecionado
;-- read variable
var = f->GPM_3IMERGM_06_precipitation(:,:)
var@lat2d = f->lat_bnds
var@lon2d = f->lon_bnds
;-- shapefile mask resources
opt = True
opt@return_mask = True ;-- this forces the return of a 0s and 1s mask array
;-- create the mask based on the given shapefile
mask_array = shapefile_mask_data(var, shpname, opt)
mask_array!0 = "y"
mask_array!1 = "x"
mask_array@coordinates = "lat_bnds lon_bnds"
;-- create new netCDF file and write mask array
system("rm f " + maskname)
fout = addfile(maskname,"c")
fout
>mask_array = mask_array
fout->lat_bnds = f->lat_bnds
fout->lon_bnds = f->lon_bnds
df = addfile("mask_bolivia.nc","r")
print(df)
end

what am i doing wrong? can anybody help me


    (1-1/1)