Re: Error in masking wrf data using shapefile

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 03 2014 - 12:14:58 MST

Tabish,

Over the weekend I updated the shapefile examples, and the "shapefile_mask_data.ncl" script. The updated function will now allow you to mask based on a specific area in a shapefile, or the whole shapefile

I assume in your case you are talking about the whole shapefile, so try downloading the new shapefile_mask_data.ncl from:

http://www.ncl.ucar.edu/Applications/Scripts/shapefile_mask_data.ncl

and instead of code that looks like this:

;---Set all hgt values to missing except for those over Ohio.
  opt = True
  opt@shape_var = "NAME_1"
  opt@shape_names = "Ohio"
  hgt_mask = shapefile_mask_data(hgt,shp_filename,opt)

You want to do:

;---Mask "hgt" using the whole shapefile
  opt = True
  hgt_mask = shapefile_mask_data(hgt,shp_filename,opt)

Please note that if you have a shapefile with a lot of segments and/or a lot of points, then the masking can be slow. There are ways to speed up the masking, for example, by passing in minlat, maxlat, minlon, and maxlon attributes that represents a rough lat/lon box of the area you want to mask. For example, you might do:

  opt = True
  opt@minlat = 5
  opt@maxlat = 37
  opt@minlon = 65
  opt@maxlon = 99
  hgt_mask = shapefile_mask_data(hgt,shp_filename,opt)

This is mostly necessary if you are using a shapefile that has outlines from the whole world, and you just want to mask over India. If your shapefile only contains outlines of India, then these four attributes probably won't help much.

--Mary

On Mar 2, 2014, at 7:37 AM, Tabish Ansari <tabishumaransari@gmail.com> wrote:

> Thank you very much for the mail. I just have a small doubt. I need to retain all my wrf data within entire Indian political boundary and not within a state of India (like OHIO in your case). So, what should I give in as the "NAME_1" to the shapefile_mask_data function?
>
>
> On 22 February 2014 04:39, Mary Haley <haley@ucar.edu> wrote:
> Tabish,
>
> I haven't had luck with making the masking code faster, so I've attached what I have so far.
>
> The function to use is shapefile_mask_data, which is in the attached "shapefile_mask_data.ncl" script.
>
> The script that calls this function is wrf_hgt_shapefile_mask.ncl.
>
> To mask your data, you need to attach the special "lat2d" and "lon2d" attributes as shown in the script,
> and then call the masking function with:
>
> hgt_mask = shapefile_mask_data(hgt,"USA_adm/USA_adm2.shp","NAME_1","Ohio",False)
>
> where:
>
> "hgt" is the 2D variable you want to mask (that should have the lat2d/lon2d attributes attached)
> "USA_adm/USA_adm2.shp" is the name of the shapefile
> "NAME_1" is the name of the variable on the shapefile that will contain the name of the area you want to use for masking (in this case, NAME_1 is the names of the U.S. states)
> "Ohio" is the name of the area (can be an array like (/"Ohio","Michigan"/)) you want to mask
> The last argument indicates whether you want to protect the values inside or outside of "Ohio". (True means protect them).
>
> If you change the "False" to "True", then all values outside of Ohio will get set to missing.
>
> See attached image. This was done using False for the last argument.
>
> --Mary
>
>
>
> On Feb 21, 2014, at 8:16 AM, Tabish Ansari <tabishumaransari@gmail.com> wrote:
>
> > Hi
> >
> > I am trying to mask my wrf data using the shapefile for India. I am doing this based on the method used in "mask_gadm.ncl" script recently released after the shapefiles webinar.
> >
> > To my knowledge I have made all the correct modifications, however I am getting the following error:
> >
> > fatal:No coordinate variable exists for dimension (south_north) in variable (data)
> > fatal:["Execute.c":7743]:Execute: Error occurred at or near line 29 in file masking.ncl
> >
> > fatal:["Execute.c":7743]:Execute: Error occurred at or near line 180 in file masking.ncl
> >
> > Also I would like to know what is the difference between a "rectilinear grid" and a "curvilinear grid" and is my wrf data suitable to be directly used in this script?
> >
> > I have attached the script below.
> >
> > --
> > Thanks & Regards
> > Tabish Umar Ansari
> > MS Research Scholar
> > Environmental & Water Resources Engineering Division
> > Department of Civil Engineering
> > IIT Madras
> > <masking.ncl>_______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
>
> --
> Thanks & Regards
> Tabish Umar Ansari
> MS Research Scholar
> Environmental & Water Resources Engineering Division
> Department of Civil Engineering
> IIT Madras
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 3 12:15:14 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 03 2014 - 14:26:18 MST