[ncl-talk] how to use shapefile to creat a nc mask file

Guido Cioni guidocioni at gmail.com
Thu Apr 26 08:57:29 MDT 2018


Why not? I think the example on the website it's pretty clear :) 
You should be a little bit more specific...which aspect is not clear to you? 

I'm attaching an even simpler script that I used to produce a netcdf mask of a region in Italy (Toscana) using shapefile data. You need to load the shapefile_utils.ncl file first!!! (see here https://www.ncl.ucar.edu/Applications/shapefiles.shtml <https://www.ncl.ucar.edu/Applications/shapefiles.shtml>) 

;load shapefile
f_state       = addfile("shapefiles/ITA_adm_shp/ITA_adm0.shp","r")
lon_shp   = f_state->x
lat_shp   = f_state->y

;load data, in this case MODIS NDVI
infile    = addfile ("MOD13C2_2000-2017_it_seasanom.nc", "r")
ndvi=infile->CMG_0_05_Deg_Monthly_NDVI(0,::-1,:)

; Name of the output file 
mask_fname = "toscana_mask.nc"

     opt             = True
     opt at return_mask = True
     opt at debug       = True
     opt at shape_var   = "NAME_1"
     opt at shape_names = "Toscana"

     toscana_mask        = shapefile_mask_data(ndvi,f_state,opt)

;Write new mask to file

     system("rm -f " + mask_fname)
     fout           = addfile(mask_fname,"c")
     fout->TSC_mask = toscana_mask

And then use it with 

      fmask    = addfile("toscana_mask.nc","r")
     tsc_mask = fmask->TSC_mask

     ndvi=mask(ndvi, tsc_mask.eq.1, ndvi at _FillValue)


> On 26. Apr 2018, at 16:29, WUJIE <393069045 at qq.com> wrote:
> 
> 
> Hi Sir,
> 
> While I have used NCL for some months, I still cannot understand that how to use shapefile to creat a mask nc file.
> I am now having a basin's shp and I wanna to creat a ncfile as a basin mask. This enables me to calculate the basin mean temperature data using this mask nc (i.e. exclude the values out of the basin)
> I gave a read here (https://www.ncl.ucar.edu/Applications/Scripts/mask_12.ncl <https://www.ncl.ucar.edu/Applications/Scripts/mask_12.ncl>), but this is not clear to me.
> 
> Could you please give me an example?
> 
> I attached one shp as an example (see attached). I am really looking forward to your kind help, thanks!
> 
> Jie
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk


Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180426/f569f795/attachment.html>


More information about the ncl-talk mailing list