Re: help with using shapefile to mask an array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Apr 18 2012 - 08:06:42 MDT

Hi Mark,

I was unable to download your tar file because I need the name in order to get it (the ftp doesn't allow "ls").

Maybe I can help clear up the confusion about how gc_inout works.

The gc_inout function should be returning an array that is the same dimensionality as the first two arguments to gc_inout, which is dlat2d/dlon2d in this case.

What gc_inout does under the hood is loops through every (i,j) pair of dlat2d and dlon2d, and checks to see if it's inside the polygon formed by plat/plon.

This "pseudo" code shows an example of what the internal gc_inout wrapper code looks like (gcinout_fort is the internal Fortran routine that only takes one lat/lon point at a time):

  inout_array = new((/nlat,nlon/),logical)
  do i = 0,nlat-1
    do j=0,nlon-1
      inout_array(i,j) = gcinout_fort(dlat2d(i,j),dlon2d(i,j),plat,plon)
    end do
  end do

If I understand what you are asking, you were thinking that every lat point in dlat2d was paired with every lon point in dlon2d, and hence you would get back a dlat**2 x dlon**2 vector of True/False values?

I'm not sure this what you want, because doesn't dlat2d/dlon2d represent a 2D lat/lon grid?

If you want to me look into this further, can you tar up the latest files and give me the name?

Thanks,

--Mary

On Apr 17, 2012, at 10:08 PM, mark collier wrote:

> Hi,
> I have reworked the logic and got rid of my bug which referenced the wrong array (p instead of pr), I don't understand why inout is a scalar and not a vector to match the product of the shape of dlat2d,dlon2d or pr?
>
> Inside the polygon drawing loop I now have:
>
> if(isdefined("plat"))then delete(plat) end if
> if(isdefined("plon"))then delete(plon) end if
> plat=lat(startPT:endPT)
> plon=lon(startPT:endPT)
>
> dlat=p&lat
> dlon=p&lon
>
> nlat=dimsizes(dlat)
> nlon=dimsizes(dlon)
>
> dlat2d=ndtooned(conform_dims((/nlat,nlon/),dlat,0))
> dlon2d=ndtooned(conform_dims((/nlat,nlon/),dlon,1))
>
> if(isdefined("inout"))then delete(inout) end if
> inout=gc_inout(dlat2d,dlon2d,plat,plon)
> print(inout)
>
> I was hoping to have a 2d mask from which I can apply to 2d variable pr and form a polygon average.
>
> Many thanks,
> Mark.
> _______________________________________________
> 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 Wed Apr 18 08:06:53 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 20 2012 - 16:21:18 MDT