[GRASS-SVN] r52118 - grass/branches/develbranch_6/scripts/i.landsat.rgb
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 18 01:16:05 PDT 2012
Author: hamish
Date: 2012-06-18 01:16:05 -0700 (Mon, 18 Jun 2012)
New Revision: 52118
Modified:
grass/branches/develbranch_6/scripts/i.landsat.rgb/description.html
grass/branches/develbranch_6/scripts/i.landsat.rgb/i.landsat.rgb
Log:
parallelize module, speeding it up 3x more (but using 3x the RAM)
Modified: grass/branches/develbranch_6/scripts/i.landsat.rgb/description.html
===================================================================
--- grass/branches/develbranch_6/scripts/i.landsat.rgb/description.html 2012-06-18 07:07:32 UTC (rev 52117)
+++ grass/branches/develbranch_6/scripts/i.landsat.rgb/description.html 2012-06-18 08:16:05 UTC (rev 52118)
@@ -27,7 +27,12 @@
similar results by switching to a coarser resolution before the running of
the module (using <em>g.region</em>) and then back to the original resolution
afterwards.
+<p>
+By default the module will process all three R,G,B bands in parallel. To
+run serially use the <b>-s</b> flag. Parallel mode requires three times the
+memory while running, but takes one third of the time to complete.
+
<h2>EXAMPLE</h2>
North Carolina sample dataset example:
Modified: grass/branches/develbranch_6/scripts/i.landsat.rgb/i.landsat.rgb
===================================================================
--- grass/branches/develbranch_6/scripts/i.landsat.rgb/i.landsat.rgb 2012-06-18 07:07:32 UTC (rev 52117)
+++ grass/branches/develbranch_6/scripts/i.landsat.rgb/i.landsat.rgb 2012-06-18 08:16:05 UTC (rev 52118)
@@ -64,6 +64,10 @@
#% key: r
#% description: Reset to standard color range
#%end
+#%flag
+#% key: s
+#% description: Process bands serially (default: run in parallel)
+#%end
if [ -z "$GISBASE" ] ; then
@@ -123,31 +127,102 @@
BRI_VAR_STR=percentile_`echo "$BRIGHTNESS" | awk '{printf("%.15g", $1)}' | tr '.' '_'`
if [ 0 -eq $GIS_FLAG_P ] ; then
- for i in $RED $GREEN $BLUE ; do
- g.message "Processing <$i>..."
- eval `r.univar -ge "$i" perc=2,"$BRIGHTNESS" | grep '^percentile_'`
- MIN="$percentile_2"
- eval `echo "MAX=\"\\$\$BRI_VAR_STR\""`
- g.message -d message="<$i>: min=$MIN max=$MAX"
- r.colors $i col=rules << EOF
+
+ if [ 1 -eq $GIS_FLAG_S ] ; then
+ # Unlocked, run serially
+ for i in $RED $GREEN $BLUE ; do
+ g.message "Processing <$i>..."
+ eval `r.univar -ge "$i" perc=2,"$BRIGHTNESS" | grep '^percentile_'`
+ MIN="$percentile_2"
+ eval `echo "MAX=\"\\$\$BRI_VAR_STR\""`
+ g.message -d message="<$i>: min=$MIN max=$MAX"
+ r.colors $i col=rules << EOF
+ 0% black
+ $MIN black
+ $MAX white
+ 100% white
+EOF
+ done
+ else
+ # Unlocked, run in parallel
+ g.message "Processing ..."
+ eval `(
+ r.univar -ge "$RED" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/R_/' &
+ r.univar -ge "$GREEN" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/G_/' &
+ r.univar -ge "$BLUE" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/B_/'
+ wait
+ )`
+
+ R_MIN="$R_percentile_2"
+ eval `echo "R_MAX=\"\\$R_\$BRI_VAR_STR\""`
+ G_MIN="$G_percentile_2"
+ eval `echo "G_MAX=\"\\$G_\$BRI_VAR_STR\""`
+ B_MIN="$B_percentile_2"
+ eval `echo "B_MAX=\"\\$B_\$BRI_VAR_STR\""`
+
+ r.colors "$RED" col=rules << EOF
0% black
- $MIN black
- $MAX white
+ $R_MIN black
+ $R_MAX white
100% white
EOF
+ r.colors "$GREEN" col=rules << EOF
+ 0% black
+ $G_MIN black
+ $G_MAX white
+ 100% white
+EOF
+ r.colors "$BLUE" col=rules << EOF
+ 0% black
+ $B_MIN black
+ $B_MAX white
+ 100% white
+EOF
+ fi
+
+else
+ g.message "Processing ..."
+ if [ 1 -eq $GIS_FLAG_S ] ; then
+ # Bands are locked, run serially
+
+ # we can combine all 3 bands into one r.univar call:
+ # [disabled: uses 3x the RAM and actually runs slightly slower than 3 in a row]
+ #eval `r.univar -ge "$RED,$GREEN,$BLUE" perc=2,"$BRIGHTNESS" | grep '^percentile_'`
+ #ALL_MIN="$percentile_2"
+ #eval `echo "ALL_MAX=\"\\$\$BRI_VAR_STR\""`
+
+ # using 3 separate r.univar calls:
+ ALL_MAX=0
+ ALL_MIN=999999
+ for i in $RED $GREEN $BLUE ; do
+ g.message "Processing <$i>..."
+ eval `r.univar -ge "$i" perc=2,"$BRIGHTNESS" | grep '^percentile_'`
+ MIN="$percentile_2"
+ eval `echo "MAX=\"\\$\$BRI_VAR_STR\""`
+ g.message -d message="<$i>: min=$MIN max=$MAX"
+ ALL_MAX=`echo "$MAX $ALL_MAX" | awk '{if ($1 > $2) print $1; else print $2}'`
+ ALL_MIN=`echo "$MIN $ALL_MIN" | awk '{if ($1 < $2) print $1; else print $2}'`
done
-else
- ALL_MAX=0
- ALL_MIN=999999
- for i in $RED $GREEN $BLUE ; do
- g.message "Processing <$i>..."
- eval `r.univar -ge "$i" perc=2,"$BRIGHTNESS" | grep '^percentile_'`
- MIN="$percentile_2"
- eval `echo "MAX=\"\\$\$BRI_VAR_STR\""`
- g.message -d message="<$i>: min=$MIN max=$MAX"
- ALL_MAX=`echo "$MAX $ALL_MAX" | awk '{if ($1 > $2) print $1; else print $2}'`
- ALL_MIN=`echo "$MIN $ALL_MIN" | awk '{if ($1 < $2) print $1; else print $2}'`
- done
+ else
+ # Bands are locked, run in parallel
+ eval `(
+ r.univar -ge "$RED" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/R_/' &
+ r.univar -ge "$GREEN" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/G_/' &
+ r.univar -ge "$BLUE" perc=2,"$BRIGHTNESS" | grep '^percentile_' | sed -e 's/^/B_/'
+ wait
+ )`
+
+ ALL_MAX=0
+ ALL_MIN=999999
+ for i in R G B ; do
+ eval `echo "MIN=\"\\$\${i}_percentile_2\""`
+ eval `echo "MAX=\"\\$\${i}_\$BRI_VAR_STR\""`
+ g.message -d message="<$i>: min=$MIN max=$MAX"
+ ALL_MAX=`echo "$MAX $ALL_MAX" | awk '{if ($1 > $2) print $1; else print $2}'`
+ ALL_MIN=`echo "$MIN $ALL_MIN" | awk '{if ($1 < $2) print $1; else print $2}'`
+ done
+ fi
+
g.message -d message="all_min=$ALL_MIN all_max=$ALL_MAX"
for i in $RED $GREEN $BLUE ; do
r.colors $i col=rules << EOF
More information about the grass-commit
mailing list