This is a continuation of my earlier emails, which Mary has been
helping me with.
I have 100s of polygons which map out the distribution of a specific
tree type
in N America, with latit(npoly,npts) and longit(npoly,npts)
representing the
points on each polygon. I want to created a 269x457 grid over N
America with
1s if the tree exists there (is within any of the polygons) or 0s if
not.
We have 2 solutions, both taking about the same amount of time and
are very slow
(I need a faster solution to realistically do this). Any suggestions?
I am wondering if, with method 2 from Mary, that we could avoid using
3D and instead
perform 1D calculations. Actually, that method crashes for lack of
memory for some trees
if there are a lot of polygons.
Method 1:
grid=new((/269,457/),float)
grid!0="lat"
grid!1="lon"
grid&lat=lat
grid&lon=lon
grid=0.
latit@_FillValue=-999.
longit@_FillValue=-999.
do i=0,npoly-1
system("date")
npts=num(.not.ismissing(latit(i,:)))
do ilat=0,268
do ilon=0,456
if (.not.ismissing(oro(ilat,ilon))) then
inout=gc_inout(lat(ilat),lon(ilon),latit(i,0:npts-1),longit
(i,0:npts-1))
if (inout.eq.True) then
grid(ilat,ilon)=1.
end if
end if
end do
end do
end do
--------------------
Method 2:
grid=new((/269,457/),float)
grid!0="lat"
grid!1="lon"
grid&lat=lat
grid&lon=lon
grid=0.
latit@_FillValue=-999.
longit@_FillValue=-999.
lat2d=conform(grid,lat,0)
lon2d=conform(grid,lon,1)
do i=0,npoly-1
npts=num(.not.ismissing(latit(i,:)))
grid3d = new((/269,457,npts/),typeof(latit))
latit3d = conform(grid3d,latit(i,0:npts-1),2)
longit3d = conform(grid3d,longit(i,0:npts-1),2)
delete(grid3d)
inout = gc_inout(lat2d,lon2d,latit3d,longit3d)
grid = where(inout,1.,grid)
delete(latit3d)
delete(longit3d)
end do
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jul 22 2009 - 10:47:26 MDT
This archive was generated by hypermail 2.2.0 : Thu Jul 23 2009 - 08:02:42 MDT