Re: Masking using Shapefile

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 31 2014 - 16:15:07 MDT

Hi Rahmi,

I believe the issue is that this function is not currently set up to handle dimensions beyond lat/lon dimensions. That is, if you give it an array that has extra leftmost dimensions, like time and/or levels, it's going to fail.

Until I can get around to updating this function to handle multiple leftmost dimensions, I think you can do something like this:

land_mask = shapefile_mask_data(PR3(0,:,:),shpfile,opt) ; Create mask based on lat/lon part of PR3
land_mask_3d = conform_dims(dimsizes(PR3),land_mask,(/1,2/)) ; Conform land_mask to same size as PR3 so we can use "where" function
PR3_ocean_mask = where(land_mask_3d.eq.0,PR3,PR3@_FillValue)
copy_VarMeta(PR3,PR3_ocean_mask)

Note that the above assumes you have a rectilinear or curvilinear grid.

--Mary

On Mar 31, 2014, at 8:12 AM, rahmi ariani <rahmi.ariani@gmail.com> wrote:

>
> Dear everyone,
>
> I am trying to mask a data using a shapefile and i got an error like this: shapefile_mask_data: Error: not a valid rectilinear, curvilinear, or unstructured grid. I use my own shapefile (i cannot attach the file because the size is too big), but even i use the shapefile used in this example: https://www.ncl.ucar.edu/Applications/Scripts/mask_12.ncl (http://www.ngdc.noaa.gov/mgg/shorelines/data/gshhs/version2.2.0), its still giving the same error. Could someone help me with this problem? Any help will be appreciate. Thank you.
>
> Here is my script:
>
> load "./shapefile_mask_data.ncl"
> WRITE_MASK = True
> DEBUG = False
> in = addfile("TRMM_3LT.nc","r")
> PR3 = in->PR3(:,{-7:7}, {94:107})
> shpfile = "Sumatera.shp"
> opt = True
> opt@return_mask = True
> opt@minlat = -7
> opt@maxlat = 7
> opt@minlon = 94
> opt@maxlon = 107
> land_mask = shapefile_mask_data(PR3,shpfile,opt)
> PR3_ocean_mask = where(land_mask.eq.0,PR3,PR3@_FillValue)
> copy_VarMeta(PR3,PR3_ocean_mask)
>
> Best,
>
>
> --
> Rahmi Ariani
> Student of Applied Climatology
> Faculty of Mathematics and Natural Science
> Bogor Agricultural University
> Indonesia
> 16680
>
>
> _______________________________________________
> 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 31 16:15:20 2014

This archive was generated by hypermail 2.1.8 : Thu Apr 03 2014 - 13:36:27 MDT