Mask NETCDF file by shapefile?
Added by L. Santos almost 5 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
bacia_ama_bolivia.cpg (5 Bytes) bacia_ama_bolivia.cpg | |||
bacia_ama_bolivia.dbf (314 Bytes) bacia_ama_bolivia.dbf | |||
bacia_ama_bolivia.sbn (132 Bytes) bacia_ama_bolivia.sbn | |||
bacia_ama_bolivia.prj (151 Bytes) bacia_ama_bolivia.prj | |||
bacia_ama_bolivia.sbx (116 Bytes) bacia_ama_bolivia.sbx | |||
bacia_ama_bolivia.shp.xml (8 KB) bacia_ama_bolivia.shp.xml | |||
bacia_ama_bolivia.shx (108 Bytes) bacia_ama_bolivia.shx | |||
bacia_ama_bolivia.shp (362 KB) bacia_ama_bolivia.shp | shapefile (my study area) | ||
GPM_DJF.nc (198 KB) GPM_DJF.nc | netcdf that needs to be masked by the shapefile |
Replies (1)
RE: Mask NETCDF file by shapefile? - Added by Karin Meier-Fleischer almost 5 years ago
Please, don't do cross postings! See answer https://code.mpimet.mpg.de/boards/2/topics/9139