Visualizing Spatial Output

From Rhessys
Revision as of 09:56, 30 October 2009 by Dgroulx (talk | contribs)
Jump to navigationJump to search

In module III you looked at time series output. In this module you will look at RHESSys output displayed spatially. Output variables can be viewed spatially by replacing map ID numbers with values for a particular output variable. This requires using a map that has multiple ID’s so that spatial variation exists, such as the hillslope or patch maps. For instance, you wouldn’t use the basin map as it only has a single ID of 1; therefore, there is no spatial variation. You match the spatial aggregation of generated RHESSys output (i.e. hillslope output) to the map used to define that spatial level (i.e. the hillslope map). For this exercise you will display the patch output you created in module III, or you can use the patch output provided with the tutorial data (in the getting started portion of this tutorial, you should have copied the following files from the data/out directory into your own out directory: w8nc_patch.monthly and w8cut_patch.monthly). The GRASS GIS program will be used to view the RHESSys data spatially.

First you must extract the data you are interested in viewing spatially from the patch.monthly file, and convert it to a format that can be read into GRASS. You will use a command language called AWK to extract the data in the correct format. AWK is a programming language designed to search for and match patterns, and allows you to manipulate files containing columns of data and strings. AWK is very useful for general operation of UNIX commands and for reducing data files, and comes with all UNIX operating systems. For information on AWK, see the on-line help and information pages (you may also want to look at a similar UNIX command called SED).

AWK can be run from a single command line at the UNIX prompt, or from a command file. You will be using an AWK script written in a command file called extmonth.awk (this program should be available in the bin; it has also been provided with the tutorial data in the data/out directory so you can run it right from the out directory).

You must decide what variable you want to look at spatially, and what the column number of that data is in the output file. For this exercise, you will look at LAI. A list of output headings is available on the RHESSys website. For these exercises you are using patch.monthly output, in the Patch Monthly Output File Column Contents average monthly LAI is column 14. You can also see what variable headings are contained within the patch.monthly file by typing the UNIX command:

• U> head –n 1 w8nc_patch.monthly

This will return the first line of the file which contains the headings. Count what column number the variable lai is in (14).

Now you can use the AWK program to extract the LAI column in the format necessary to be read into GRASS. AWK is a pattern matching program, so you must give the AWK program extmonth.awk some conditional information so it is able to extract what you want from patch.monthly file. Spatial output is only viewed for a single temporal period, i.e. one day or one month. So you need to know what time period of data your output file contains. These instructions are written for the patch output provided with the tutorial data, which contain output for August from the year 1985 and 2000 (results are for 5 and 20 years of recovery after clearcutting the forest). If you are using the patch output you created in module III, adjust the dates accordingly.

Move into the out directory. • U> awk –f extmonth.awk mth=8 year=2000 col=14

    < w8nc_patch.monthly > w8nc.lai
	

• U> awk –f extmonth.awk mth=8 year=1985 col=14

    < w8cut_patch.monthly > w8cut5.lai
 

• U> awk –f extmonth.awk mth=8 year=2000 col=14

    < w8cut_patch.monthly > w8cut20.lai

This will create 3 new text files: w8nc.lai = LAI from a mature w8 forest (nc = no cut) w8cut5.lai = LAI from the w8 forest 5 years after harvesting w8cut20.lai = LAI from the w8 forest 20 years after harvesting

Start GRASS. The GRASS r.recode command is used to map the LAI values to the patch map. Input is the name of the map you are recoding the LAI values to, output is the new LAI map you are creating, and < indicates the text file you are inputting. You can use any output name you like (the examples given simply indicate to fill in a map name for each scenario.)

grass> r.recode input=w8dem.cl output=nc_map_name < w8nc.lai

grass> r.recode input=w8dem.cl output=cut5_map_name < w8cut5.lai

grass> r.recode input=w8dem.cl output=cut20_map_name < w8cut20.lai

• Display the maps (don’t forget to open a monitor with d.mon; you may need to run

     r.support on the new map if it does not appear)

grass> d.rast new_map_name (a map you just created with r.recode)

 Include a legend

grass> d.legend map=new_map_name

You can create a new ‘difference’ map that shows the change in LAI at 5 and 20 years after harvesting with the r.mapcalc command.

grass> r.mapcalc ‘diff_map_name = nc_map_name – cut5_map_name’