[Swift-commit] r6279 - in SwiftApps/modis: bin tutorial
davidk at ci.uchicago.edu
davidk at ci.uchicago.edu
Fri Feb 15 06:10:51 CST 2013
Author: davidk
Date: 2013-02-15 06:10:42 -0600 (Fri, 15 Feb 2013)
New Revision: 6279
Added:
SwiftApps/modis/bin/is_land.pl
Modified:
SwiftApps/modis/bin/analyzelanduse.sh
SwiftApps/modis/bin/getlanduse.pl
SwiftApps/modis/bin/markmap.sh
SwiftApps/modis/tutorial/modis03.swift
Log:
Start of ascii map generation
Modified: SwiftApps/modis/bin/analyzelanduse.sh
===================================================================
--- SwiftApps/modis/bin/analyzelanduse.sh 2013-02-15 11:33:21 UTC (rev 6278)
+++ SwiftApps/modis/bin/analyzelanduse.sh 2013-02-15 12:10:42 UTC (rev 6279)
@@ -31,13 +31,33 @@
# Max limit to analyze
maxnum=$4
+# ASCII map name
+asciimap=$6
+
+BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
# Write topselected.txt
result=$( grep " $usetype " $( eval echo $5 ) | sed s/':'/' '/g | sort -rnk2 | awk '{print $1 " " $2}' | head -$maxnum )
echo "$result" > $topselected
# Write selectedtiles.txt
+selected_tiles=""
for r in $( echo "$result" | awk '{print $1}' )
do
- echo $( basename $r ).ppm.gz |sed s/\.landuse\.byfreq//g >> $selectedtiles
+ tile=$( basename $r ).ppm.gz |sed s/\.landuse\.byfreq//g
+ echo $tile >> $selectedtiles
+ selected_tiles="$selected_tiles $tile"
done
+
+# Write ASCII map
+for image in $( eval echo $5 )
+do
+ is_land=$( $BINDIR/is_land.pl $image )
+ if [ "$is_land" == "1" ]; then
+ echo $image is land >> $asciimap
+ else
+ echo $image is water >> $asciimap
+ fi
+done
+
exit 0
Modified: SwiftApps/modis/bin/getlanduse.pl
===================================================================
--- SwiftApps/modis/bin/getlanduse.pl 2013-02-15 11:33:21 UTC (rev 6278)
+++ SwiftApps/modis/bin/getlanduse.pl 2013-02-15 12:10:42 UTC (rev 6279)
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
# Input to this program should be a gzipped PGM file
-# Usage: pgmhist.pl myfile.pgm.gz
+# Usage: getlanduse.pl myfile.pgm.gz
my $pgm_filename = shift;
open(PGMFILE, "gunzip -c $pgm_filename |") || die "Unable to open $pgm_filename!\n";
Added: SwiftApps/modis/bin/is_land.pl
===================================================================
--- SwiftApps/modis/bin/is_land.pl (rev 0)
+++ SwiftApps/modis/bin/is_land.pl 2013-02-15 12:10:42 UTC (rev 6279)
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+# Usage: is_land.pl myfile.pgm.gz
+# Returns 0 if image is land, 1 if water
+
+my $pgm_filename = shift;
+open(PGMFILE, "gunzip -c $pgm_filename |") || die "Unable to open $pgm_filename!\n";
+
+# Header
+my $magic = <PGMFILE>;
+my $resolution = <PGMFILE>;
+my $maxvalue = <PGMFILE>;
+my ($xres, $yres) = split(' ', $resolution);
+
+# Use arrays to count frequencies
+my @pixelcount;
+foreach my $count(0..$maxvalue) {
+ $pixelcount[$count] = 0;
+}
+
+# Read values
+foreach(<PGMFILE>) {
+ foreach $word(split) {
+ $pixelcount[$word]++;
+ }
+}
+close(PGMFILE);
+
+my $total_pixel_count=$xres*$yres;
+my $water_count=$pixelcount[0];
+
+if($water_count >= ($total_pixel_count/2)) { print "0\n"; }
+else { print "1\n"; }
+
Property changes on: SwiftApps/modis/bin/is_land.pl
___________________________________________________________________
Added: svn:executable
+ *
Modified: SwiftApps/modis/bin/markmap.sh
===================================================================
--- SwiftApps/modis/bin/markmap.sh 2013-02-15 11:33:21 UTC (rev 6278)
+++ SwiftApps/modis/bin/markmap.sh 2013-02-15 12:10:42 UTC (rev 6279)
@@ -12,7 +12,8 @@
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//')
- echo hv=$hv h=$h v=$v
$BINDIR/draw_rectangle.pl $outmap $((34+$h*16)) $((51+$v*16)) $((34+14+$h*16)) $((51+14+$v*16)) $outmap.tmp
mv $outmap.tmp $outmap
done
+
+
Modified: SwiftApps/modis/tutorial/modis03.swift
===================================================================
--- SwiftApps/modis/tutorial/modis03.swift 2013-02-15 11:33:21 UTC (rev 6278)
+++ SwiftApps/modis/tutorial/modis03.swift 2013-02-15 12:10:42 UTC (rev 6279)
@@ -7,9 +7,9 @@
getlanduse @filename(input) stdout=@filename(output);
}
-app (file output, file tilelist) analyzeLandUse (landuse input[], string usetype, int maxnum)
+app (file output, file tilelist, file asciimap) analyzeLandUse (landuse input[], string usetype, int maxnum)
{
- analyzelanduse @output @tilelist usetype maxnum @input;
+ analyzelanduse @output @tilelist usetype maxnum @input @filename(asciimap);
}
# Constants and command line arguments
@@ -31,4 +31,5 @@
# 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);
+file asciiMap <"map.txt">;
+(topSelected, selectedTiles, asciiMap) = analyzeLandUse(land, landType, nSelect);
More information about the Swift-commit
mailing list