[ncl-talk] Masking 3d data from Shapefile
Mary Haley
haley at ucar.edu
Thu Mar 24 10:53:13 MDT 2016
Hi Samar,
You can use the shapefile_mask_data function to return a mask of your data
at the first time step. You need to set the special "return_mask" attribute
to True, so the 0/1 mask array is returned.
You can then use this mask to apply it to the other time steps of your
data. This is assuming that your lat/lon grid is the same for every time
step. Is that true for your dataset?
I've attached an example that takes a global dataset and uses the
USA_adm0.shp shapefile to mask the values over the United States. The
comments of the file indicate where you can download the data files needed
to run this example.
The masking can take awhile (about 192 CPU seconds). Once you have the
mask array, however, masking the rest of your data should be faster, using
the "mask" function.
--Mary
On Wed, Mar 23, 2016 at 9:26 PM, Samar Min Allah <minallah at umich.edu> wrote:
> Hello,
>
> I have a shapefile of a basin (irregular polygon) and I want to use it to
> clip a netcdf file (i.e, select only the points lying inside the shapefile).
>
> There is an example that does the same on a 2d array however I have a
> variable with (time, lat, lon) coordinates for which this does not work;
>
> https://www.ncl.ucar.edu/Applications/Scripts/shapefiles_4.ncl
>
> I am having a hard time modifying this to 3d.
> Looping through all the time (thousands of values) is not feasible.
>
> I
> s it possible to mask the variable and output it as a separate netcdf or
> alternatively subset a
> netcdf with irregular polygon.
>
> Thanks
> --
> Samar
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20160324/58041d6c/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefile.maskeddata.png
Type: image/png
Size: 244198 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160324/58041d6c/attachment-0002.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefile.fulldata.png
Type: image/png
Size: 322076 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160324/58041d6c/attachment-0003.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefile_utils.ncl
Type: application/octet-stream
Size: 19284 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160324/58041d6c/attachment-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles_20.ncl
Type: application/octet-stream
Size: 4212 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160324/58041d6c/attachment-0003.obj
More information about the ncl-talk
mailing list