[Swift-commit] r6318 - in SwiftApps/modis: . bin conf tutorial

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Thu Feb 28 10:55:05 CST 2013


Author: davidk
Date: 2013-02-28 10:55:05 -0600 (Thu, 28 Feb 2013)
New Revision: 6318

Added:
   SwiftApps/modis/bin/assemble.sh
   SwiftApps/modis/bin/gray.rgb
   SwiftApps/modis/bin/rgb_adjust_color.pl
   SwiftApps/modis/bin/rgb_downscale.pl
   SwiftApps/modis/bin/rgb_draw_rectangle.pl
   SwiftApps/modis/bin/rgb_histogram.pl
   SwiftApps/modis/tutorial/modis06.swift
Removed:
   SwiftApps/modis/bin/adjust_color.pl
   SwiftApps/modis/bin/assemble.sh
   SwiftApps/modis/bin/assemble.sh.orig
   SwiftApps/modis/bin/assemble.sh.v2
   SwiftApps/modis/bin/assemble2.sh
   SwiftApps/modis/bin/draw_rectangle.pl
   SwiftApps/modis/bin/erasewater.sh
   SwiftApps/modis/bin/getlanduse.pl
   SwiftApps/modis/bin/gray.png
   SwiftApps/modis/bin/setborder.sh
Modified:
   SwiftApps/modis/bin/colormodis.sh
   SwiftApps/modis/bin/getlanduse.sh
   SwiftApps/modis/bin/markmap.sh
   SwiftApps/modis/conf/beagle-ssh.cf
   SwiftApps/modis/conf/beagle.cf
   SwiftApps/modis/conf/fusion.cf
   SwiftApps/modis/conf/local-coasters.cf
   SwiftApps/modis/conf/local.cf
   SwiftApps/modis/conf/midway.cf
   SwiftApps/modis/conf/raven.cf
   SwiftApps/modis/demo
   SwiftApps/modis/tutorial/modis05.swift
Log:
Starting work towards the assembly step
Added rgb_downscale.pl to resample an image
Some clean up


Deleted: SwiftApps/modis/bin/adjust_color.pl
===================================================================
--- SwiftApps/modis/bin/adjust_color.pl	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/adjust_color.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,35 +0,0 @@
-#!/usr/bin/perl 
-
-# Usage: adjust_color.pl input.rgb table.txt output.rgb
-
-my ($input_filename, $translation_table, $output_filename) = @ARGV;
-open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
-open(FILE_OUTPUT, ">$output_filename") || die "Unable to create $output_filename";
-
-# Read translation table into a hash
-my %tr_table = ();
-open(TRANSLATION_TABLE, "$translation_table") || die "Unable to open $translation_table";
-while(<TRANSLATION_TABLE>) {
-   my ($from, $to) = split;
-   $tr_table{$from} = $to;
-}
-
-# Read data
-$/ = \3;
-while(<FILE_INPUT>) {
-   my $hex = sprintf ("#%2.2X%2.2X%2.2X", unpack('C3', $_));
-
-   if(defined($tr_table{$hex})) { 
-      my $new_value = $tr_table{$hex};
-      print FILE_OUTPUT pack('C3', 
-                             hex(substr($new_value,1,2)),
-                             hex(substr($new_value,3,2)),
-                             hex(substr($new_value,5,2))
-      );
-   } 
-
-   else { print FILE_OUTPUT $_; }
-}
-
-close(FILE_INPUT);
-close(FILE_OUTPUT);

Deleted: SwiftApps/modis/bin/assemble.sh
===================================================================
--- SwiftApps/modis/bin/assemble.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/assemble.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,13 +0,0 @@
-output=$1
-shift
-inputs=$(ls -1 $*)
-labels=""
-for f in $inputs; do
-  labels="$labels -label $(echo $f | sed -e 's/^.*\(h..v..\).*/\1/') $f"
-done
-
-echo doing:
-echo montage $labels -font Courier-Regular $inputs $output
-
-montage $labels -font Courier-Regular $output
-

Copied: SwiftApps/modis/bin/assemble.sh (from rev 6307, SwiftApps/modis/bin/assemble2.sh)
===================================================================
--- SwiftApps/modis/bin/assemble.sh	                        (rev 0)
+++ SwiftApps/modis/bin/assemble.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+output=$(cd $(dirname $1); echo $PWD/$(basename $1))     # Full pathname of output file
+selected=$(cd $(dirname $2); echo $PWD/$(basename $2))   # Full pathname of input text file "selected"
+indir=$(cd $(dirname $3); echo $PWD/$(basename $3))      # Full pathname of image input dir
+webdir=$4
+
+echo output=$output
+echo selected=$selected
+echo indir=$indir
+echo webdir=$webdir
+
+if [ ! -d $webdir ]; then
+   mkdir -p $webdir
+   if [ $? -ne 0 ]; then
+      echo Unable to create $webdir, quitting
+      exit 1
+   fi
+fi
+
+tmpdir=$( eval mktemp -d $PWD/modis.assemble.XXXX )
+bindir=$(cd $(dirname $0); pwd)
+graytile=$bindir/gray.rgb
+
+# input files are expected to start with hNNvNN. 
+# we reverse this to form the final image
+
+cd $indir
+
+for h in {0..35}; do
+   h=$( printf %02d $h );
+   
+   for v in {0..17}; do
+      v=$( printf %02d $v );
+      hv=h${h}v${v}
+      vh=v${v}h${h}
+
+      # Use graytile if the expected section is not found
+      if [ ! -f $indir/$hv.color.rgb ]; then
+         echo $indir/$hv.color.rgb does not exist
+         cp $graytile $tmpdir
+         mv $tmpdir/gray.rgb $tmpdir/$vh.rgb 
+
+      # Otherwise, downscale input images
+      #elif grep $hv $selected >&/dev/null; then
+      #   convert $hv.png -resize 290x290 $tmpdir/t.png
+      #   convert $tmp/t.png -bordercolor red -border 5x5 $tmpdir/$vh.png
+      else
+         $bindir/rgb_downscale.pl $indir/$hv.color.rgb 2400 2400 8 $tmpdir/$vh.rgb
+      fi
+  done
+done
+
+#montage -tile 36x18 -geometry +0+0 $tmpdir/v*png $tmpdir/bigmap.png
+#cp $tmp/bigmap.png $output
+
+###########
+
+exit 0
+
+inputs=$(ls -1 $*)
+labels=""
+for f in $inputs; do
+  labels="$labels -label $(echo $f | sed -e 's/^.*\(h..v..\).*/\1/') $f"
+done
+
+montage $labels -font Courier-Regular $output
+

Deleted: SwiftApps/modis/bin/assemble.sh.orig
===================================================================
--- SwiftApps/modis/bin/assemble.sh.orig	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/assemble.sh.orig	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,4 +0,0 @@
-output=$1
-shift
-inputs=$(ls -1 $*)
-montage -label '%f' -font Courier-Regular $inputs $output
\ No newline at end of file

Deleted: SwiftApps/modis/bin/assemble.sh.v2
===================================================================
--- SwiftApps/modis/bin/assemble.sh.v2	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/assemble.sh.v2	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,10 +0,0 @@
-output=$1
-shift
-inputs=$(ls -1 $*)
-labels=""
-for f in $inputs; do
-  labels="$labels -label $(echo $f | sed -e 's/^.*\(h..v..\).*/\1/') $f"
-done
-
-montage $label -font Courier-Regular $inputs $output
-

Deleted: SwiftApps/modis/bin/assemble2.sh
===================================================================
--- SwiftApps/modis/bin/assemble2.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/assemble2.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,69 +0,0 @@
-#!/bin/bash
-
-output=$(cd $(dirname $1); echo $(pwd)/$(basename $1))     # get full pathname of output file
-selected=$(cd $(dirname $2); echo $(pwd)/$(basename $2))   # get full pathname of input file "selected"
-indir=$(cd $(dirname $3); pwd)                             # get full pathname of input dir "geos"
-webdir=$4
-
-if [ ! -d $webdir ]; then
-   mkdir -p $webdir
-   if [ $? -ne 0 ]; then
-      echo Unable to create $webdir, quitting
-      exit 1
-   fi
-fi
-
-tmpdir=$PWD/$( basename $( mktemp -d modis.assemble.XXXX ) )
-ls -ld $tmpdir
-
-bindir=$(cd $(dirname $0); pwd)
-graytile=$bindir/gray.png
-
-# input files are expected to start with hNNvNN. 
-# we reverse this to form the final image
-
-cd $indir
-
-for h in {0..35}; do
-   h=$( printf %02d $h );
-   
-   for v in {0..17}; do
-      v=$( printf %02d $v );
-      hv=h${h}v${v}
-      vh=v${v}h${h}
-
-      if [ ! -f $hv*png ]; then
-         cp $graytile $tmpdir/$vh.png
-      elif grep $hv $selected >&/dev/null; then
-         echo "adding border to $hv"
-         # add red border
-         convert $hv*png -resize 290x290 $tmp/t.png
-         convert $tmp/t.png -bordercolor red -border 5x5 $tmp/$vh.png
-      else
-         cp $hv*png $tmp/$vh.png
-      fi
-  done
-done
-
-montage -tile 36x18 -geometry +0+0 $tmp/v*png $tmp/bigmap.png
-convert $tmp/bigmap.png -resize 20% $tmp/map.png
-cp $tmp/map.png $output
-cp $tmp/bigmap.png $output
-
-if [ -d "$webdir" ]; then
-  cp $tmp/map.png $webdir
-fi
-
-
-###########
-
-exit 0
-
-inputs=$(ls -1 $*)
-labels=""
-for f in $inputs; do
-  labels="$labels -label $(echo $f | sed -e 's/^.*\(h..v..\).*/\1/') $f"
-done
-
-montage $labels -font Courier-Regular $output
-

Modified: SwiftApps/modis/bin/colormodis.sh
===================================================================
--- SwiftApps/modis/bin/colormodis.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/colormodis.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,9 +1,9 @@
-#
+#!/bin/bash
+
 # Return a new modis files with the 0-16 pixel values changed to
 # colors that reflect the land use of that region. (See legend)
 #
 # usage: colormodis.sh original.rgb recolored.rgb
-#
 
 infile=$1
 outfile=$2
@@ -32,4 +32,4 @@
 #101010 #949494
 EOF
 
-$BINDIR/adjust_color.pl $infile translate.txt $outfile
+$BINDIR/rgb_adjust_color.pl $infile translate.txt $outfile

Deleted: SwiftApps/modis/bin/draw_rectangle.pl
===================================================================
--- SwiftApps/modis/bin/draw_rectangle.pl	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/draw_rectangle.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,37 +0,0 @@
-#!/usr/bin/perl 
-
-# Draw a rectangle on an RGB file
-# Usage: draw_rectangle.pl infile.rgb xmin ymin xmax ymax outfile.rgb
-
-my ($input_filename, $xres, $yres, $xmin, $ymin, $xmax, $ymax, $output_filename) = @ARGV;
-open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
-open(FILE_OUTPUT, ">$output_filename") || die "Unable to create $output_filename";
-
-# Read data three bytes at a time (RGB)
-$/ = \3;
-my $x=0, $y=0;
-while(<FILE_INPUT>) {
-   (my $red, my $green, my $blue) = unpack('C3', $_);
-   #print "$red $green $blue\n";
-
-   # Left and right of rectangle, 2 pixels wide
-   if ( $x == $xmin || $x == $xmin+1 || $x == $xmax || $x == $xmax-1 ) {
-      if ( $y <= $ymax && $y >= $ymin ) { 
-         $red="255"; $blue="0"; $green="0"; }
-   } 
-
-   # Top and bottom, 2 pixels high
-   if ( $y == $ymin || $y == $ymin-1 || $y == $ymax || $y == $ymax-1 ) {
-      if ( $x <= $xmax && $x >= $xmin ) { 
-         $red="255"; $blue="0"; $green="0";
-      }
-   }
-   
-   print FILE_OUTPUT pack('C3', $red, $green, $blue);
-
-   if($x == $xres-1) { $x = 0; $y++; } 
-   else { $x++; }
-}
-
-close(FILE_INPUT);
-close(FILE_OUTPUT);

Deleted: SwiftApps/modis/bin/erasewater.sh
===================================================================
--- SwiftApps/modis/bin/erasewater.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/erasewater.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,78 +0,0 @@
-#
-# Return a new modis files with the 0-16 pixel values changed to
-# colors that reflect the land use of that region. (See legend)
-#
-# usage: colormodis.sh modis.tif recolored.tif
-#
-
-infile=$1
-outfile=$2
-tmp=`mktemp /tmp/modis.$USER.XXXXXX`
-mv $tmp $tmp.tif
-tmp=$tmp.tif
-tmp=$2
-map=`mktemp /tmp/colormap.$USER.XXXXXX`
-
-# Create color set
-
-(
-  cat |
-  sed -e 's/ c.=/ /g' -e 's/[^0-9 ]//g' |
-  awk '{printf("#%02x%02x%02x #%02x%02x%02x\n",$1,$2,$3,255,255,255)}') >$map <<EOF
-       <Entry c1="32" c2="65" c3="179" c4="255"/>
-EOF
-
-cp $infile $tmp
-
-# output logged to stdout/error is ignored by swift for this app()
-
-while read mval color ; do
-  echo color $mval is $color
-  echo convert $tmp "-fill" "$color" "-opaque" "$mval" $tmp
-  convert $tmp "-fill" "$color" "-opaque" "$mval" $tmp
-done <$map
-
-exit
-
-#cp $tmp $outfile
-convert -thumbnail 300x300 $tmp $outfile
-
-# rm $tmp $map # Keep these for debugging, for now.
-
-cat >/dev/null <<END # PIXELVALUES
-   0  water
-   1  evergreen needleleaf forest
-   2  evergreen broadleaf forest
-   3  deciduous needleleaf forest
-   4  deciduous broadleaf forest
-   5  mixed forests
-   6  closed shrubland
-   7  open shrublands
-   8  woody savannas
-   9  savannas
-   10 grasslands
-   11 permanent wetlands
-   12 croplands
-   13 urban and built-up
-   14 cropland/natural vegetation mosaic
-   15 snow and ice
-   16 barren or sparsely vegetated
-   254 unclassified
-0       <Entry c1="32" c2="65" c3="179" c4="255"/>
-1       <Entry c1="0" c2="106" c3="15" c4="255"/>
-2       <Entry c1="0" c2="124" c3="37" c4="255"/>
-3       <Entry c1="0" c2="162" c3="91" c4="255"/>
-4       <Entry c1="0" c2="161" c3="37" c4="255"/>
-5       <Entry c1="6" c2="146" c3="40" c4="255"/>
-6       <Entry c1="158" c2="150" c3="104" c4="255"/>
-7       <Entry c1="193" c2="196" c3="143" c4="255"/>
-8       <Entry c1="133" c2="170" c3="91" c4="255"/>
-9       <Entry c1="177" c2="183" c3="65" c4="255"/>
-10      <Entry c1="164" c2="208" c3="126" c4="255"/>
-11      <Entry c1="115" c2="171" c3="174" c4="255"/>
-12      <Entry c1="204" c2="210" c3="83" c4="255"/>
-13      <Entry c1="217" c2="0" c3="0" c4="255"/>
-14      <Entry c1="157" c2="227" c3="110" c4="255"/>
-15      <Entry c1="182" c2="181" c3="194" c4="255"/>
-16      <Entry c1="148" c2="148" c3="148" c4="255"/>
-EOF
\ No newline at end of file

Deleted: SwiftApps/modis/bin/getlanduse.pl
===================================================================
--- SwiftApps/modis/bin/getlanduse.pl	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/getlanduse.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,23 +0,0 @@
-#!/usr/bin/perl -w
-
-# Input to this program should be a raw, greyscale RGB file
-# Usage: getlanduse.pl myfile.rgb
-
-my $image_filename = shift;
-open(IMAGEFILE, "$image_filename") || die "Unable to open $image_filename!\n";
-binmode IMAGEFILE;
-
-my @pixelcount;
-foreach my $count (0..255) { $pixelcount[$count] = 0; }
-
-# Read values, three bytes at a time
-$/ = \3; 
-foreach(<IMAGEFILE>) {
-   $pixelcount[unpack('C', $_)]++;
-}
-close(IMAGEFILE);
-
-foreach my $count (0..255) {
-   if($pixelcount[$count] == 0) { next; }
-   printf("%d %d %02x\n", $pixelcount[$count], $count, $count);
-}

Modified: SwiftApps/modis/bin/getlanduse.sh
===================================================================
--- SwiftApps/modis/bin/getlanduse.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/getlanduse.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1,4 +1,4 @@
 #!/bin/bash
 
 BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-$BINDIR/getlanduse.pl $1 | sort -rn
+$BINDIR/rgb_histogram.pl $1 | sort -rn

Deleted: SwiftApps/modis/bin/gray.png
===================================================================
(Binary files differ)

Added: SwiftApps/modis/bin/gray.rgb
===================================================================
(Binary files differ)


Property changes on: SwiftApps/modis/bin/gray.rgb
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: SwiftApps/modis/bin/markmap.sh
===================================================================
--- SwiftApps/modis/bin/markmap.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/markmap.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -14,7 +14,7 @@
   hv=$(echo $f | sed -e 's,^.*/,,' -e 's/\..*//')
   h=$(echo $hv | sed -e 's/h//' -e 's/v..//' -e 's/^0//')
   v=$(echo $hv | sed -e 's/h..//' -e 's/v//' -e 's/^0//')
-  $BINDIR/draw_rectangle.pl $outmap.step $xres $yres $(( $h * 20 )) $(( $v * 20 )) $(( $h * 20 + 20 )) $(( $v * 20 + 20)) $outmap.tmp
+  $BINDIR/rgb_draw_rectangle.pl $outmap.step $xres $yres $(( $h * 20 )) $(( $v * 20 )) $(( $h * 20 + 20 )) $(( $v * 20 + 20)) $outmap.tmp
   mv $outmap.tmp $outmap.step
 done
 

Copied: SwiftApps/modis/bin/rgb_adjust_color.pl (from rev 6311, SwiftApps/modis/bin/adjust_color.pl)
===================================================================
--- SwiftApps/modis/bin/rgb_adjust_color.pl	                        (rev 0)
+++ SwiftApps/modis/bin/rgb_adjust_color.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,35 @@
+#!/usr/bin/perl 
+
+# Usage: rgb_adjust_color.pl input.rgb table.txt output.rgb
+
+my ($input_filename, $translation_table, $output_filename) = @ARGV;
+open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
+open(FILE_OUTPUT, ">$output_filename") || die "Unable to create $output_filename";
+
+# Read translation table into a hash
+my %tr_table = ();
+open(TRANSLATION_TABLE, "$translation_table") || die "Unable to open $translation_table";
+while(<TRANSLATION_TABLE>) {
+   my ($from, $to) = split;
+   $tr_table{$from} = $to;
+}
+
+# Read data
+$/ = \3;
+while(<FILE_INPUT>) {
+   my $hex = sprintf ("#%2.2X%2.2X%2.2X", unpack('C3', $_));
+
+   if(defined($tr_table{$hex})) { 
+      my $new_value = $tr_table{$hex};
+      print FILE_OUTPUT pack('C3', 
+                             hex(substr($new_value,1,2)),
+                             hex(substr($new_value,3,2)),
+                             hex(substr($new_value,5,2))
+      );
+   } 
+
+   else { print FILE_OUTPUT $_; }
+}
+
+close(FILE_INPUT);
+close(FILE_OUTPUT);

Added: SwiftApps/modis/bin/rgb_downscale.pl
===================================================================
--- SwiftApps/modis/bin/rgb_downscale.pl	                        (rev 0)
+++ SwiftApps/modis/bin/rgb_downscale.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,43 @@
+#!/usr/bin/perl 
+
+# Downscale an rgb image
+# Usage: rgb_downscale.pl input.rgb xres yres scalefactor output.rgb
+
+sub array_avg {
+    my $result=0;
+    foreach(@_){ $result += $_; }
+    return int($result/@_);
+}
+
+my ($input_filename, $xres, $yres, $scalefactor, $output_filename) = @ARGV;
+
+open(FILE_OUTPUT, ">$output_filename") || die "Unable to write to $output_filename!";
+open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
+local $/;
+my @values = unpack('C*', <FILE_INPUT>);
+close(FILE_INPUT);
+
+my $x=0, $y=0;
+while($y < $yres) {
+   my (@reds, @greens, @blues) = ();
+
+   foreach my $yloc ($y..$y+($scalefactor-1)) {
+      foreach my $xloc ($x..$x+($scalefactor-1)) {
+         my $index = ($yloc * $xres + $xloc) * 3;
+         push(@reds, $values[$index]);
+         push(@greens, $values[$index+1]);
+         push(@blues, $values[$index+2]);         
+      }
+   }
+
+   my $red = &array_avg(@reds);
+   my $green = &array_avg(@greens);
+   my $blue = &array_avg(@blues);
+   print FILE_OUTPUT pack('C3', $red, $green, $blue);
+
+   if( ($x+$scalefactor) >= $xres ) { $x = 0; $y += $scalefactor; } 
+   else { $x += $scalefactor; }
+}
+
+close(FILE_INPUT);
+close(FILE_OUTPUT);


Property changes on: SwiftApps/modis/bin/rgb_downscale.pl
___________________________________________________________________
Added: svn:executable
   + *

Copied: SwiftApps/modis/bin/rgb_draw_rectangle.pl (from rev 6308, SwiftApps/modis/bin/draw_rectangle.pl)
===================================================================
--- SwiftApps/modis/bin/rgb_draw_rectangle.pl	                        (rev 0)
+++ SwiftApps/modis/bin/rgb_draw_rectangle.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,36 @@
+#!/usr/bin/perl 
+
+# Draw a rectangle on an RGB file
+# Usage: draw_rectangle.pl infile.rgb xmin ymin xmax ymax outfile.rgb
+
+my ($input_filename, $xres, $yres, $xmin, $ymin, $xmax, $ymax, $output_filename) = @ARGV;
+open(FILE_INPUT, "$input_filename") || die "Unable to open $input_filename!";
+open(FILE_OUTPUT, ">$output_filename") || die "Unable to create $output_filename";
+
+# Read data three bytes at a time (RGB)
+$/ = \3;
+my $x=0, $y=0;
+while(<FILE_INPUT>) {
+   (my $red, my $green, my $blue) = unpack('C3', $_);
+
+   # Left and right of rectangle, 2 pixels wide
+   if ( $x == $xmin || $x == $xmin+1 || $x == $xmax || $x == $xmax-1 ) {
+      if ( $y <= $ymax && $y >= $ymin ) { 
+         $red="255"; $blue="0"; $green="0"; }
+   } 
+
+   # Top and bottom, 2 pixels high
+   if ( $y == $ymin || $y == $ymin-1 || $y == $ymax || $y == $ymax-1 ) {
+      if ( $x <= $xmax && $x >= $xmin ) { 
+         $red="255"; $blue="0"; $green="0";
+      }
+   }
+   
+   print FILE_OUTPUT pack('C3', $red, $green, $blue);
+
+   if($x == $xres-1) { $x = 0; $y++; } 
+   else { $x++; }
+}
+
+close(FILE_INPUT);
+close(FILE_OUTPUT);

Copied: SwiftApps/modis/bin/rgb_histogram.pl (from rev 6307, SwiftApps/modis/bin/getlanduse.pl)
===================================================================
--- SwiftApps/modis/bin/rgb_histogram.pl	                        (rev 0)
+++ SwiftApps/modis/bin/rgb_histogram.pl	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+# Input to this program should be a raw, greyscale RGB file
+# Usage: rgb_histogram.pl myfile.rgb
+
+my $image_filename = shift;
+open(IMAGEFILE, "$image_filename") || die "Unable to open $image_filename!\n";
+binmode IMAGEFILE;
+
+my @pixelcount;
+foreach my $count (0..255) { $pixelcount[$count] = 0; }
+
+# Read values, three bytes at a time
+$/ = \3; 
+foreach(<IMAGEFILE>) {
+   $pixelcount[unpack('C', $_)]++;
+}
+close(IMAGEFILE);
+
+foreach my $count (0..255) {
+   if($pixelcount[$count] == 0) { next; }
+   printf("%d %d %02x\n", $pixelcount[$count], $count, $count);
+}

Deleted: SwiftApps/modis/bin/setborder.sh
===================================================================
--- SwiftApps/modis/bin/setborder.sh	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/bin/setborder.sh	2013-02-28 16:55:05 UTC (rev 6318)
@@ -1 +0,0 @@
-convert $1 -bordercolor red -border 20 $2

Modified: SwiftApps/modis/conf/beagle-ssh.cf
===================================================================
--- SwiftApps/modis/conf/beagle-ssh.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/beagle-ssh.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -10,6 +10,6 @@
 #app getlanduse=/lustre/beagle/davidk/modis/bin/getlanduse.sh
 #app analyzelanduse=/lustre/beagle/davidk/modis/bin/analyzelanduse.sh
 #app colormodis=/lustre/beagle/davidk/modis/bin/colormodis.sh
-#app assemble=/lustre/beagle/davidk/modis/bin/assemble2.sh
+#app assemble=/lustre/beagle/davidk/modis/bin/assemble.sh
 #app markmap=/lustre/beagle/davidk/modis/bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/beagle.cf
===================================================================
--- SwiftApps/modis/conf/beagle.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/beagle.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -10,6 +10,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/fusion.cf
===================================================================
--- SwiftApps/modis/conf/fusion.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/fusion.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -9,6 +9,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/local-coasters.cf
===================================================================
--- SwiftApps/modis/conf/local-coasters.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/local-coasters.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -10,6 +10,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/local.cf
===================================================================
--- SwiftApps/modis/conf/local.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/local.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -10,6 +10,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/midway.cf
===================================================================
--- SwiftApps/modis/conf/midway.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/midway.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -11,6 +11,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/conf/raven.cf
===================================================================
--- SwiftApps/modis/conf/raven.cf	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/conf/raven.cf	2013-02-28 16:55:05 UTC (rev 6318)
@@ -10,6 +10,6 @@
 #app getlanduse=$PWD/../bin/getlanduse.sh
 #app analyzelanduse=$PWD/../bin/analyzelanduse.sh
 #app colormodis=$PWD/../bin/colormodis.sh
-#app assemble=$PWD/../bin/assemble2.sh
+#app assemble=$PWD/../bin/assemble.sh
 #app markmap=$PWD/../bin/markmap.sh
 #app echo=/bin/echo

Modified: SwiftApps/modis/demo
===================================================================
--- SwiftApps/modis/demo	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/demo	2013-02-28 16:55:05 UTC (rev 6318)
@@ -65,7 +65,13 @@
 # Select script
 echo
 prompt="Pick an option:"
-options=("Tutorial 1" "Tutorial 2" "Tutorial 3" "Tutorial 4")
+options=(
+         "Tutorial 1 - Analyze landuse for a single image" 
+         "Tutorial 2 - Analyze landuse for 317 images"
+         "Tutorial 3 - Create text files summarizing results"
+         "Tutorial 4 - Highlight top areas on a map"
+         "Tutorial 5 - Create colored images"
+)
 
 echo "Select script"
 PS3="$prompt "
@@ -75,6 +81,7 @@
        2 ) run tutorial/modis02.swift; break;;
        3 ) run tutorial/modis03.swift; break;;
        4 ) run tutorial/modis04.swift; break;;
+       5 ) run tutorial/modis05.swift; break;;
        $(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
        *) echo "Invalid option. Try another one.";continue;;
     esac

Modified: SwiftApps/modis/tutorial/modis05.swift
===================================================================
--- SwiftApps/modis/tutorial/modis05.swift	2013-02-28 02:36:11 UTC (rev 6317)
+++ SwiftApps/modis/tutorial/modis05.swift	2013-02-28 16:55:05 UTC (rev 6318)
@@ -48,7 +48,7 @@
 gridmap = markMap(topSelected);
 
 # Create multi-color images for all tiles
-imagefile colorImage[] <structured_regexp_mapper; source=geos, match="(h..v..)", transform=@strcat("landuse/\\1.color.png")>;
+imagefile colorImage[] <structured_regexp_mapper; source=geos, match="(h..v..)", transform=@strcat("colorImages/\\1.color.rgb")>;
 
 foreach g, i in geos {
   colorImage[i] = colorModis(g);

Added: SwiftApps/modis/tutorial/modis06.swift
===================================================================
--- SwiftApps/modis/tutorial/modis06.swift	                        (rev 0)
+++ SwiftApps/modis/tutorial/modis06.swift	2013-02-28 16:55:05 UTC (rev 6318)
@@ -0,0 +1,59 @@
+type file;
+type imagefile;
+type landuse;
+
+app (landuse output) getLandUse (imagefile input)
+{
+  getlanduse @filename(input) stdout=@filename(output);
+}
+
+app (file output, file tilelist) analyzeLandUse (landuse input[], string usetype, int maxnum)
+{
+  analyzelanduse @output @tilelist usetype maxnum @input;
+}
+
+app (imagefile grid) markMap (file tilelist) 
+{
+  markmap @tilelist @grid;
+}
+
+app (imagefile output) colorModis (imagefile input)
+{
+  colormodis @input @output;
+}
+
+# Constants and command line arguments
+int nFiles       = @toInt(@arg("nfiles", "1000"));
+int nSelect      = @toInt(@arg("nselect", "10"));
+string landType  = @arg("landtype", "urban");
+string MODISdir  = @arg("modisdir", "../data/modis/2002");
+
+# Input Dataset
+imagefile geos[] <ext; exec="../bin/modis.mapper", location=MODISdir, suffix=".rgb", n=nFiles>;
+
+# Compute the land use summary of each MODIS tile
+landuse land[]    <structured_regexp_mapper; source=geos, match="(h..v..)", transform=@strcat("landuse/\\1.landuse.byfreq")>;
+
+foreach g,i in geos {
+    land[i] = getLandUse(g);
+}
+
+# Find the top N tiles (by total area of selected landuse types)
+file topSelected <"topselected.txt">;
+file selectedTiles <"selectedtiles.txt">;
+(topSelected, selectedTiles) = analyzeLandUse(land, landType, nSelect);
+
+# Mark the top N tiles on a sinusoidal gridded map
+imagefile gridmap <"gridmap.png">;
+gridmap = markMap(topSelected);
+
+# Create multi-color images for all tiles
+imagefile colorImage[] <structured_regexp_mapper; source=geos, match="(h..v..)", transform=@strcat("colorImages/\\1.color.rgb")>;
+
+foreach g, i in geos {
+  colorImage[i] = colorModis(g);
+}
+
+# Assemble a montage of the top selected areas
+imagefile montage<"map.png">; 
+assemble(selectedTiles,colorImage,webDir);




More information about the Swift-commit mailing list