[ncl-talk] Issue with Masking with shapefile

Rick Brownrigg brownrig at ucar.edu
Thu Aug 4 09:46:53 MDT 2016


Hi,

Its rather hard to say with certainty what's going on here, but my best
guess is:

i)  The original error message likely came about because the variable "var"
did not have coordinate arrays associated with it.  This is from the
comments for shapefile_mask_data():

;  - If a rectilinear grid, then "data" must have coordinate arrays
;    attached.
;  - If a curvilinear grid, then "data" must have the special lat2d
;    and lon2d attributes attached.
;  - If a unstructured grid, then "data"must have the special lat1d
;    and lon1d attributes attached.

If you are not familiar with the notion of coordinate arrays in
NetCDF, please see:

http://ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#Coordinates

If there have been no other changes to your script, in the original,
you had already extracted
the variable var as a 2D variable via:

var 				= doubletofloat(a->HEM_DLY(0,:,:))

Thus when you attempt to slice it again in the call to
shapefile_mask_data(), you get the error regarding "using 3, 2
expected"


Hope that helps...

Rick


On Wed, Aug 3, 2016 at 10:14 PM, Amit Kumar <amitkumar.777 at hotmail.com>
wrote:

> Hi,
>
>
> Earlier I was using
>
>
> *shp_mask = shapefile_mask_data(var,filename,opt) , so here I got the
> error:*
>
>
> *(0)    shapefile_mask_data: Error: not a valid rectilinear, curvilinear,
> or unstructured grid*
>
>
> so then I used
>
>
> *shp_mask = shapefile_mask_data(var(0,:,:),filename,opt) , but I got this
> error,*
>
>
> *fatal:Number of subscripts do not match number of dimensions of
> variable,(3) Subscripts used, (2) Subscripts expected*
>
>
> so please suggest how to mention my variable in which has three dimensions *var(0,:,:)
> i.e. time, lon, lat so that shapefile_mask_data works.*
>
>
> *Regards*
>
> *Amit*
> ------------------------------
> *From:* Guido Cioni <guidocioni at gmail.com>
> *Sent:* Wednesday, August 3, 2016 5:01:47 PM
> *To:* Amit Kumar
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] Issue with Masking with shapefile
>
> Just judging from what you are saying (I didn’t read the script), you had
> some error regarding the shape file which was blocking the execution of the
> script at line xxx, but then you fixed that error and now you have another
> error at line yyy (with yyy > xxx likely to be) that wasn’t detected before
> since you didn’t actually reach that line while executing the script.
>
> Please mark the line where the error (subscripts) is happening and go into
> the code to see all the assignments that you made at that point. Usually a
> few print statements (printVarSummary) before that line can lead you the
> way..
> Without the line where the error is happening you are forcing people to
> read your code entirely, which many be time consuming :)
>
> Guido Cioni
> http://guidocioni.altervista.org
>
> On 03 Aug 2016, at 13:26, Amit Kumar <amitkumar.777 at hotmail.com> wrote:
>
>
> Hi,
>
> I'm truing to do masking using shapefile, script is attached.
>
> I'm getting following error:
>
>
>
> *(0)    shapefile_mask_data: Error: not a valid rectilinear, curvilinear,
> or unstructured grid *so I made following changes:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> * opt             = True   opt at return_mask = True   shp_mask =
> shapefile_mask_data(var(0,:,:),filename,opt) shp_mask_3d =
> conform_dims(dimsizes(var),shp_mask,(/1,2/))  var_shp_mask =
> where(shp_mask_3d.eq.1,var,var at _FillValue) copy_VarMeta(var,var_shp_mask)
> ;---For shapefile plot, use the shapefile outlines.   res at mpOutlineOn  =
> False ;---Create plot of original data masked by shapefile outlines
> res at tiMainString = "Original data masked by shapefile outlines"
> var_shp_plot = gsn_csm_contour_map(wks,var_shp_mask,res)   dum =
> gsn_add_shapefile_polylines(wks,var_shp_plot,filename,False)  draw(plot)
>  frame(wks)  end *after these changes earlier error is rectified but now
> I'm getting following error:
>
> *fatal:Number of subscripts do not match number of dimensions of
> variable,(3) Subscripts used, (2) Subscripts expected*
>
> Please suggest how to proceed further.
>
> <hem_shp_mask_1.ncl>_______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> _______________________________________________
> 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/20160804/918abe64/attachment.html 


More information about the ncl-talk mailing list