[ncl-talk] speeding up shapefile masking

Mary Haley haley at ucar.edu
Wed Oct 15 08:59:14 MDT 2014


Tabish,

One thing you can try is setting the options minlat, maxlat, minlon, and
maxlon to a box area that encloses the area you are interested in checking
against the shapefile.

For example, let's say your shapeflle contains outlines of the United
States, but your data is only over the state of New Mexico.

The state of New Mexico is roughly enclosed in the area: 31.3 to 37.1
latitude, and -109.1 to -102.9 longitude.

So, I might call the mask function with:

  opt             = True
  opt at debug       = True
  opt at shape_var   = "NAME_1"
  opt at shape_names = "New Mexico"
  opt at minlat      = 31.3
  opt at maxlat      = 37.1
  opt at minlon      = -109.1
  opt at maxlon      = -102.9
  hgt_mask  = shapefile_mask_data(hgt,"USA_adm1.shp",opt)

What happens, then, is that the masking function doesn't even bother
calling gc_inout for any area that is outside of this box, and thus it
should run a little faster.

Example "shapefiles_11.ncl" uses this method to speed up the masking:

http://www.ncl.ucar.edu/Applications/shapefiles.shtml#ex11

--Mary


On Wed, Oct 15, 2014 at 6:26 AM, Dennis Shea <shea at ucar.edu> wrote:

> [1]  shapefile_mask_data.ncl uses gc_inout which can be slow.
>
> [2] You should create a (say) netCDF file which contains a masked variable.
>      This should be saved and used in all subsequent applications.
>      *This need be done only once.*
>
> [3] Then use this variable (read from netCDF file) and then use NCL's mask
> function
>       on all subsequent applications.
>
>       https://www.ncl.ucar.edu/Document/Functions/Built-in/mask.shtml
>
> Reply only to ncl-talk. No personal salutation.
>
> On Tue, Oct 14, 2014 at 3:03 PM, Tabish Ansari <tabishumaransari at gmail.com
> > wrote:
>
>> Hi
>>
>> I have a script wherein I read-in some data from an ascii file and then
>> mask it on the basis of a shapefile by calling the script
>> "shapefile_mask_data.ncl" within my script. My data has approximately
>> 530x980 data points.
>>
>> Currently it takes around 2 hrs 10 minutes to finish the job. I have to
>> repeat this process several times. In future I may have to even do this
>> masking within a loop, which will make it impractical due to its
>> inefficiency.
>>
>> Is there a way to speed up this process?
>>
>> Thanks in advance!
>>
>>
>> Tabish U 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141015/610cf9fb/attachment.html 


More information about the ncl-talk mailing list