[Swift-commit] r6311 - in SwiftApps/modis: bin conf tutorial
davidk at ci.uchicago.edu
davidk at ci.uchicago.edu
Sat Feb 23 13:18:21 CST 2013
Author: davidk
Date: 2013-02-23 13:18:20 -0600 (Sat, 23 Feb 2013)
New Revision: 6311
Added:
SwiftApps/modis/bin/adjust_color.pl
SwiftApps/modis/tutorial/modis05.swift
Modified:
SwiftApps/modis/bin/colormodis.sh
SwiftApps/modis/conf/local.cf
Log:
Color map
Added: SwiftApps/modis/bin/adjust_color.pl
===================================================================
--- SwiftApps/modis/bin/adjust_color.pl (rev 0)
+++ SwiftApps/modis/bin/adjust_color.pl 2013-02-23 19:18:20 UTC (rev 6311)
@@ -0,0 +1,35 @@
+#!/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);
Property changes on: SwiftApps/modis/bin/adjust_color.pl
___________________________________________________________________
Added: svn:executable
+ *
Modified: SwiftApps/modis/bin/colormodis.sh
===================================================================
--- SwiftApps/modis/bin/colormodis.sh 2013-02-23 12:48:03 UTC (rev 6310)
+++ SwiftApps/modis/bin/colormodis.sh 2013-02-23 19:18:20 UTC (rev 6311)
@@ -2,11 +2,13 @@
# 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.ppm.gz recolored.tif
+# usage: colormodis.sh original.rgb recolored.rgb
#
infile=$1
outfile=$2
+xres=2400
+yres=2400
BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Translation table - edit colors here
Modified: SwiftApps/modis/conf/local.cf
===================================================================
--- SwiftApps/modis/conf/local.cf 2013-02-23 12:48:03 UTC (rev 6310)
+++ SwiftApps/modis/conf/local.cf 2013-02-23 19:18:20 UTC (rev 6311)
@@ -1,6 +1,6 @@
wrapperlog.always.transfer=true
sitedir.keep=true
-execution.retries=0
+execution.retries=5
lazy.errors=false
status.mode=provider
use.provider.staging=false
Added: SwiftApps/modis/tutorial/modis05.swift
===================================================================
--- SwiftApps/modis/tutorial/modis05.swift (rev 0)
+++ SwiftApps/modis/tutorial/modis05.swift 2013-02-23 19:18:20 UTC (rev 6311)
@@ -0,0 +1,62 @@
+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("landuse/\\1.color.png")>;
+
+foreach g, i in geos {
+ colorImage[i] = colorModis(g);
+}
+
+# Assemble a montage of the top selected areas
+#imagefile montage<"map.png">; # @arg
+#file assemble_olog <"logs/assemble.o.log">;
+#file assemble_elog <"logs/assemble.e.log">;
+#tracef("Calling assemble %s %s %s %s\n", @montage, @selectedTiles, @colorImage[0], webDir);
+#(montage, assemble_olog, assemble_elog) = assemble(selectedTiles,colorImage,webDir);
More information about the Swift-commit
mailing list