<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>speeding up context evaluation...</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>

<P><FONT SIZE=2>Hi list,<BR>
<BR>
for a validation exercise I need to extract the class values around certain pixel location.<BR>
<BR>
I have a map with all the locations (numbered) and a map with the validation map.<BR>
<BR>
The code you find below is the one I came up with to get this information (only output to terminal for the moment).<BR>
<BR>
However, this code includes a loop and is terribly slow. Has anyone an idea how to speed things up?<BR>
<BR>
Kind regards,<BR>
Koen<BR>
<BR>
---------- my code -------------<BR>
<BR>
#!/bin/bash<BR>
#<BR>
###########################################################################################################################<BR>
#<BR>
# Get context around pixels...<BR>
#<BR>
# !!! Bash script only works within the GRASS terminal !!!<BR>
#<BR>
###########################################################################################################################<BR>
<BR>
<BR>
#<BR>
# get number of pixels in location file... write to variable $pixels...<BR>
#<BR>
<BR>
pixels=`r.info -r map=$1 | tail -n +2 | sed 's/max=//'`<BR>
<BR>
echo &quot;their are $pixels groundtruth points...&quot;<BR>
<BR>
for i in `seq 1 $pixels`;<BR>
do<BR>
<BR>
echo &quot;evaluating pixel $i of $pixels pixels...&quot;<BR>
<BR>
#<BR>
# Make MASK based upon pixel number evaluate one at a time. Mask name is MASK and patch.mask<BR>
# after renaming... If kept as MASK it will apply to all operations and is a system wide setting (not wanted)...<BR>
#<BR>
<BR>
r.mask -o input=$1 maskcats=$i --quiet<BR>
g.rename rast=MASK,pixel.mask --overwrite --quiet<BR>
<BR>
#<BR>
# create buffer around pixel value...<BR>
#<BR>
<BR>
r.buffer input=pixel.mask output=tmp.buffer distances=4 units=meters --overwrite --quiet<BR>
<BR>
#<BR>
# writes temporary reclass rules file...<BR>
#<BR>
<BR>
echo &quot;1 = NULL&quot; &gt; tmp.rules<BR>
echo &quot;2 = 1&quot; &gt;&gt; tmp.rules<BR>
echo &quot;end&quot; &gt;&gt; tmp.rules<BR>
<BR>
#<BR>
# reclass context values using rules above...<BR>
#<BR>
<BR>
r.reclass input=tmp.buffer output=context.mask rules=tmp.rules --overwrite<BR>
<BR>
#<BR>
# calculate category statistics for pixel and context location...<BR>
#<BR>
<BR>
r.mapcalculator amap=pixel.mask bmap=$2 formula=A*B outfile=pixel.category help=- --overwrite --quiet<BR>
echo &quot;pixel data...&quot;<BR>
r.stats -c -n input=pixel.category fs=space nv=* nsteps=255<BR>
<BR>
r.mapcalculator amap=context.mask bmap=$2 formula=A*B outfile=context.category help=- --overwrite --quiet<BR>
echo &quot;context data...&quot;<BR>
r.stats -c -n input=context.category fs=space nv=* nsteps=255<BR>
<BR>
done<BR>
<BR>
#<BR>
# clean up tmp files...<BR>
#<BR>
<BR>
rm tmp.rules<BR>
g.remove rast=pixel.mask<BR>
g.remove rast=context.mask<BR>
<BR>
echo &quot;!!!DONE!!!&quot;<BR>
echo &quot;#########################################################################&quot;</FONT>
</P>

</BODY>
</HTML>