[GRASS-dev] testing results of r.watershed2 against old r.watershed

Markus Metz markus_metz at gmx.de
Tue Dec 2 06:37:16 EST 2008


Hamish wrote:
> Hamish:
>   
>>> see the man page for an example of making a nicely colored accum map
>>> based on standard deviations.
>>>       
> MMetz:
>   
>> Why not setting colors for accum in the module?
>>     
>
> If you like, but a simple linear color model will not work well:
>   
Hmm, it does work with the existing visual output:
1. all negative values are set to 0
2. standard rainbow color rules are applied to the range 1 to 120,
leaving out anything beyond.

Since the bulk of the flow accumulation output has little flow, a simple
fixed linear model would work in most cases as it does for the visual output

Suggested color rules for flow accumulation including negative values
(offmap inflow), inspired from the color model of the visual output
covering the full range of flow accumulation values:
0% black
-200 black
-150 blue
-40 cyan
-20 green
0 yellow
20 green
40 cyan
150 blue
200 black
100% black

first making sure that 0% is smaller than -200 and 100% is larger than 200

The attached diffs for ram and seg mode apply these color rules.

Both visual output and these color rules may not look nice for DEMs with
very high resolution, e.g. LIDAR (just a guess that there will be more
cells with high accum values), then custom color rules can be set. A
fancier color model could use quartiles or quantiles, e.g. 20% steps.

>> The speed increase is not static, the new version will be
>> faster the larger the region (more cells). For somewhat
>> larger regions, the new module is >1000 times faster.
>>     
>
> ok, can you suggest better wording for the release announcement?
>   
Something like:
The new version of r.watershed produces results identical to the
original version at a substantial speed increase by optimizing the A *
search method. The speed increase with the new version is relative to
the size of the region, i.e. the more cells have to be processed the
higher is the speed gain. E.g a region with 2,000,000 cells is processed
about 100 times faster and a region with 20,000,000 cells is processed
about 5000 times faster (exact differences are system-dependent). More
technically, the time needed with the new version for a given region is
(in theory) proportional to the logarithm of the time needed with the
original version. [Now that is terrible wording...]
> t>1000 may as well be infinite, as before the user hit ^C after 2-3 days
> and so it never finished. So this opens the door to analyzing much bigger
> (ie modern) datasets; r.terraflow is nice for those, but doesn't provide
> the catchment basin output maps.
>   
In my personal opinion, flow accumulation of r.watershed is also more
realistic than flow accumulation of r.terraflow (SFD), but I have
admittedly not tested it in detail.

Regards,
Markus

-------------- next part --------------
--- r.watershed2.orig/seg/close_maps.c	2008-11-29 11:45:15.000000000 +0100
+++ r.watershed2/seg/close_maps.c	2008-12-02 11:11:56.000000000 +0100
@@ -7,11 +7,51 @@
     int r, c;
     CELL is_swale, value;
     double dvalue;
+    struct Range accRange;
+    CELL min, max;
 
     dseg_close(&slp);
     cseg_close(&alt);
-    if (wat_flag)
+    if (wat_flag) {
 	cseg_write_cellfile(&wat, wat_name);
+
+	/*
+	   color rules for flow accumulation
+		 0% black
+	   -200 black
+	   -150 blue
+		-40 cyan
+		-20 green
+		  0 yellow
+		 20 green
+		 40 cyan
+		150 blue
+		200 black
+	   100% black
+	*/
+
+	G_read_range(wat_name, this_mapset, &accRange);
+	min = max = 0;
+	G_get_range_min_max(&accRange, &min, &max);
+
+	G_init_colors(&colors);
+	if (min < -200)
+	    G_add_color_rule(min, 0, 0, 0, -200, 0, 0, 0, &colors);
+
+	G_add_color_rule(-200, 0, 0, 0, -150, 0, 0, 255, &colors);
+	G_add_color_rule(-150, 0, 0, 255, -40, 0, 255, 255, &colors);
+	G_add_color_rule(-40, 0, 255, 255, -20, 0, 255, 0, &colors);
+	G_add_color_rule(-20, 0, 255, 0, 0, 255, 255, 0, &colors);
+	G_add_color_rule(0, 255, 255, 0, 20, 0, 255, 0, &colors);
+	G_add_color_rule(20, 0, 255, 0, 40, 0, 255, 255, &colors);
+	G_add_color_rule(40, 0, 255, 255, 150, 0, 0, 255, &colors);
+	G_add_color_rule(150, 0, 0, 255, 200, 0, 0, 0, &colors);
+
+	if (max > 200)
+	    G_add_color_rule(200, 0, 0, 0, max, 0, 0, 0, &colors);
+
+	G_write_colors(wat_name, this_mapset, &colors);
+    }
     if (asp_flag) {
 	cseg_write_cellfile(&asp, asp_name);
 	G_init_colors(&colors);
-------------- next part --------------
--- r.watershed2.orig/ram/close_maps.c	2008-11-29 11:45:15.000000000 +0100
+++ r.watershed2/ram/close_maps.c	2008-12-02 11:11:59.000000000 +0100
@@ -9,6 +9,8 @@
     struct Colors colors;
     int value, r, c, fd;
     CELL *buf = NULL;
+    struct Range accRange;
+    CELL min, max;
 
     if (wat_flag || asp_flag || dis_flag || ls_flag || sl_flag || sg_flag)
 	buf = G_allocate_cell_buf();
@@ -30,6 +32,43 @@
 	    }
 	    if (G_close_cell(fd) < 0)
 		G_warning(_("Close failed."));
+
+        /*
+           color rules for flow accumulation
+             0% black
+           -200 black
+           -150 blue
+            -40 cyan
+            -20 green
+              0 yellow
+             20 green
+             40 cyan
+            150 blue
+            200 black
+           100% black
+        */
+
+	    G_read_range(wat_name, this_mapset, &accRange);
+	    min = max = 0;
+	    G_get_range_min_max(&accRange, &min, &max);
+
+	    G_init_colors(&colors);
+	    if (min < -200)
+		G_add_color_rule(min, 0, 0, 0, -200, 0, 0, 0, &colors);
+
+	    G_add_color_rule(-200, 0, 0, 0, -150, 0, 0, 255, &colors);
+	    G_add_color_rule(-150, 0, 0, 255, -40, 0, 255, 255, &colors);
+	    G_add_color_rule(-40, 0, 255, 255, -20, 0, 255, 0, &colors);
+	    G_add_color_rule(-20, 0, 255, 0, 0, 255, 255, 0, &colors);
+	    G_add_color_rule(0, 255, 255, 0, 20, 0, 255, 0, &colors);
+	    G_add_color_rule(20, 0, 255, 0, 40, 0, 255, 255, &colors);
+	    G_add_color_rule(40, 0, 255, 255, 150, 0, 0, 255, &colors);
+	    G_add_color_rule(150, 0, 0, 255, 200, 0, 0, 0, &colors);
+
+	    if (max > 200)
+		G_add_color_rule(200, 0, 0, 0, max, 0, 0, 0, &colors);
+
+	    G_write_colors(wat_name, this_mapset, &colors);
 	}
     }
 


More information about the grass-dev mailing list