[GRASS-SVN] r29482 - in grass-addons/gipe: . i.eb.wetdrypix

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 20 09:15:39 EST 2007


Author: ychemin
Date: 2007-12-20 09:15:39 -0500 (Thu, 20 Dec 2007)
New Revision: 29482

Added:
   grass-addons/gipe/i.eb.wetdrypix/
   grass-addons/gipe/i.eb.wetdrypix/Makefile
   grass-addons/gipe/i.eb.wetdrypix/description.html
   grass-addons/gipe/i.eb.wetdrypix/main.c
Log:
Added support module for i.eb.h_SEBAL95

Added: grass-addons/gipe/i.eb.wetdrypix/Makefile
===================================================================
--- grass-addons/gipe/i.eb.wetdrypix/Makefile	                        (rev 0)
+++ grass-addons/gipe/i.eb.wetdrypix/Makefile	2007-12-20 14:15:39 UTC (rev 29482)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.eb.wetdrypix
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass-addons/gipe/i.eb.wetdrypix/Makefile
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/gipe/i.eb.wetdrypix/description.html
===================================================================
--- grass-addons/gipe/i.eb.wetdrypix/description.html	                        (rev 0)
+++ grass-addons/gipe/i.eb.wetdrypix/description.html	2007-12-20 14:15:39 UTC (rev 29482)
@@ -0,0 +1,161 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>r.evapo.PM</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass.smlogo.gif" alt="GRASS logo"><hr align=center size=6 noshade>
+
+<H2>NAME</H2> <B><I>i.eb.h_SEBAL95 </I></B>- computation of <i>sensible heat flux</i> [W/m2] after Bastiaanssen, 1995 in [1].
+
+<P><I>(GRASS Raster Program)</I>
+
+<H2>SYNOPSIS</H2>
+<B>i.eb.h_SEBAL95</B>
+<BR>
+<B>i.eb.h_SEBAL95</B> help</br>
+<BR>
+
+<B>i.eb.h_SEBAL95</b> <b>[ -qzn ]</b>
+
+<b>DEM</b>=name
+<b>T</b>=name
+<b>RH</b>=name
+<b>WS</b>=name
+<b>NSR</b>=name
+<b>Vh</b>=name
+<b>ETP</b>=name
+
+<H2>DESCRIPTION</H2>
+
+<p><EM>i.eb.h_SEBAL95</EM> given the vegetation height (hc), humidity (RU), 
+wind speed at two meters height (WS), temperature (T), digital terrain model (DEM), 
+and net radiation (NSR) raster input maps, 
+calculates the sensible heat flux map (h0).
+
+<p>Optionally the user can activate a flag (-z) 
+that allows him setting to zero all of the negative evapotranspiration cells; 
+in fact these negative values motivated by the condensation of the air water 
+vapour content, are sometime undesired because they can produce  computational 
+problems. The usage of the flag -n detect that the module is run in night hours 
+and the appropriate soil heat flux is calculated.
+
+<p>The algorithm implements well known approaches: the hourly Penman-Monteith method as presented in Allen et al. (1998) for land surfaces and the Penman method (Penman, 1948) for water surfaces.<br>
+
+<p>Land and water surfaces are idenfyied by Vh:<br>
+-	where Vh>0 vegetation is present and evapotranspiration is calculated;<br>
+-	where Vh=0 bare ground is present and evapotranspiration is calculated;<br>
+-	where Vh<0 water surface is present and evaporation is calculated;<br>
+
+<p>For more details on the algorithms see [1].
+
+
+<H2>OPTIONS</H2>
+
+The program will run non-interactively if the user specifies program
+arguments and flag settings on the command line using the following
+form:
+
+<P><B>i.eb.h_SEBAL95</b> <b>[ -qzd ]</b>
+<b>DEM</b>=name
+<b>T</b>=name
+<b>RH</b>=name
+<b>WS</b>=name
+<b>NSR</b>=name
+<b>Vh</b>=name
+<b>ETP</b>=name
+
+
+
+<P>Alternatively, the user can simply type <EM>i.eb.h_SEBAL95</EM> on the
+command line and the program will ask for parameter values and flag
+settings interactively, using the standard GRASS parser interface.
+
+
+<H3>Flags:</H3>
+<dl>
+  <dt><B>-q</B>
+   <dd>Run quietly (do not display status messages). By default
+   <EM>r.evapo.PM</EM> is run verbosely.
+ <dt><B>-z</B>
+  <dd>Set negative calculated evapotranspiration values to zero.
+ <dt><B>-n</B>
+  <dd>Calculate soil heat flux for night time. By default 
+  <EM>r.evapo.PM</EM> calculate it for day time.
+</dl>
+
+
+<H3>Parameters:</H3>
+<dl>
+ <dt><B>DEM</B>=<I>name</I>
+ <dd>Input elevation raster [m a.s.l.]. Required.</dd>
+
+ <dt><b>T</b>=<I>name</I>
+ <dd>Input temperature raster [�C]. Required.</dd>
+
+ <dt><b>RH</b> =<I>name</I>
+ <dd>Input relative humidity raster [%]. Required.</dd>
+
+ <dt><b>WS</b> =<I>name</I>
+ <dd>Input wind speed at two meters raster [m/s]. Required.</dd>
+
+ <dt><b>NSR</b> =<I>name</I>
+ <dd>Input net solar radiation raster [MJ/(m2*h)]. Required.</dd>
+
+ <dt><b>Vh</b> =<I>name</I>
+ <dd>Input vegetation heigth raster [m]. Required.</dd>
+
+ <dt><b>ETP</b> =<I>name</I>
+ <dd>Output evapotranspiration raster [mm/h]. Required.</dd>
+
+</dl>
+      
+
+<H2>NOTES</H2>
+
+<p>Net solar radiation map in MJ/(m2*h) can be computed from the combination of the r.sun , 
+run in mode 1, and the r.mapcalc commands.
+
+<p>The sum of the three radiation components outputted by r.sun (beam, diffuse, and reflected) 
+multiplied by the Wh->Mj conversion factor (0.0036) and optionally by a 
+clear sky factor [0-1] allows the generation of a map to be used as 
+an NSR input for the <EM>r.evapo.PM</EM> command.
+<dt>example:
+<br><dd>r.sun -s elevin=dem aspin=aspect slopein=slope lin=2 albedo=alb_Mar incidout=out beam_rad=beam diff_rad=diffuse refl_rad=reflected day=73 time=13:00 dist=100;
+<br><dd>r.mapcalc 'NSR=0.0036*(beam+diffuse+reflected)';
+
+
+<H2>SEE ALSO</H2>
+<ul>
+  <li><a href=i.eb.h_iter.html>i.eb.h_iter</a>,
+      <a href=i.eb.h0.html>i.eb.h0</a>
+</ul>
+
+
+
+<H2>AUTHORS</H2>
+  <p>
+  <i>
+   <br>Yann Chemin, International Rice Research Institute, Los Banos, The Philippines.
+  </i>
+  <p>Contact: <a href="mailto:y.chemin at cgiar.org"> Yann chemin</a>
+
+
+<H2>REFERENCES</H2>
+
+  <p>[1] Bastiaanssen, W.G.M., 1995.
+  Estimation of Land surface paramters by remote sensing under clear-sky conditions. PhD thesis, Wageningen University, Wageningen, The Netherlands.
+
+  <p>[2] Allen, R.G., L.S. Pereira, D. Raes, and M. Smith. 1998. 
+  Crop Evapotranspiration: Guidelines for computing crop water requirements. 
+  Irrigation and Drainage Paper 56, Food and Agriculture Organization of the 
+  United Nations, Rome, pp. 300
+       
+  <p>[3] Penman, H. L. 1948. Natural evaporation from open water, 
+  bare soil and grass. Proc. Roy. Soc. London, A193, pp. 120-146. 
+<p><i>Last changed: $Date: 2007/07/29 19:30:00 $</i>
+</body>
+</html>


Property changes on: grass-addons/gipe/i.eb.wetdrypix/description.html
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/gipe/i.eb.wetdrypix/main.c
===================================================================
--- grass-addons/gipe/i.eb.wetdrypix/main.c	                        (rev 0)
+++ grass-addons/gipe/i.eb.wetdrypix/main.c	2007-12-20 14:15:39 UTC (rev 29482)
@@ -0,0 +1,309 @@
+/****************************************************************************
+ *
+ * MODULE:       i.eb.wetdrypix
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE:      Tries to zero in areas of potential pixel candidates for
+ * 		 use in the initialisation of the sensible heat flux in SEBAL
+ * 		 iteration, where Delta T is reassessed in each iteration.
+ *
+ * COPYRIGHT:    (C) 2002-2007 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	 for details.
+ *
+ * CHANGELOG:	
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include <math.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[])
+{	
+	struct Cell_head cellhd;
+	
+	/* buffer for in out raster */
+	DCELL *inrast_T,*inrast_ndvi,*inrast_alb,*inrast_DEM,*inrast_Rn,*inrast_g0,*outrast,*outrast1;
+	unsigned char *wet, *dry;
+	
+	int nrows, ncols;
+	int row, col;
+	int infd_T,infd_ndvi,infd_alb,infd_DEM,infd_Rn,infd_g0;
+	int outfd, outfd1;
+	
+	char *mapset_T,*mapset_ndvi,*mapset_alb,*mapset_DEM,*mapset_Rn,*mapset_g0;
+	char *T, *ndvi, *alb, *DEM, *Rn, *g0; 
+	
+        struct History history;
+	struct GModule *module;
+	struct Option *input_T, *input_ndvi, *input_alb, *input_DEM, *input_Rn, *input_g0, *output, *output1;
+	
+	struct Flag *flag1, *zero;
+	
+	G_gisinit(argv[0]);
+	
+	module = G_define_module();
+	module->description = _("Wet and Dry pixels candidates for SEBAL 95");
+	
+	/* Define different options */
+	input_T = G_define_option();
+	input_T->key	= "T";
+	input_T->type = TYPE_STRING;
+	input_T->required = YES;
+	input_T->gisprompt = "old,cell,raster";
+	input_T->description = _("Name of Surface Skin Temperature input map [K]");
+		
+	input_alb = G_define_option();
+	input_alb->key	= "alb";
+	input_alb->type = TYPE_STRING;
+	input_alb->required = YES;
+	input_alb->gisprompt = "old,cell,raster";
+	input_alb->description = _("Name of Broadband Albedo input map [-]");
+		
+	input_DEM = G_define_option();
+	input_DEM->key	= "DEM";
+	input_DEM->type = TYPE_STRING;
+	input_DEM->required = YES;
+	input_DEM->gisprompt = "old,cell,raster";
+	input_DEM->description = _("Name of DEM input map [m a.s.l.]");
+	
+	input_ndvi = G_define_option();
+	input_ndvi->key	= "ndvi";
+	input_ndvi->type = TYPE_STRING;
+	input_ndvi->required = YES;
+	input_ndvi->gisprompt = "old,cell,raster";
+	input_ndvi->description = _("Name of NDVI input map [-]");
+	
+	input_Rn = G_define_option();
+	input_Rn->key	= "Rn";
+	input_Rn->type = TYPE_STRING;
+	input_Rn->required = YES;
+	input_Rn->gisprompt = "old,cell,raster";
+	input_Rn->description = _("Name of Diurnal Net Solar Radiation input map [W/m2]");
+	
+	input_g0 = G_define_option();
+	input_g0->key	= "g0";
+	input_g0->type = TYPE_STRING;
+	input_g0->required = YES;
+	input_g0->gisprompt = "old,cell,raster";
+	input_g0->description = _("Name of Soil Heat Flux input map [W/m2]");	
+	
+	output = G_define_option() ;
+	output->key        = "wet";
+	output->type       = TYPE_STRING;
+	output->required   = YES;
+	output->gisprompt  = "new,cell,raster" ;
+	output->description= _("Name of output wet pixels areas layer [-]");
+	
+	output1 = G_define_option() ;
+	output1->key        = "dry";
+	output1->type       = TYPE_STRING;
+	output1->required   = YES;
+	output1->gisprompt  = "new,cell,raster" ;
+	output1->description= _("Name of output dry pixels areas layer [-]");
+	
+	/* Define the different flags */
+	//flag1 = G_define_flag() ;
+	//flag1->key         = 'q' ;
+	//flag1->description = "Quiet" ;
+	
+	zero = G_define_flag() ;
+	zero->key         = 'z' ;
+	zero->description = _("set negative to zero");
+	
+	if (G_parser(argc, argv))
+	  exit(EXIT_FAILURE);
+	
+	/* get entered parameters */
+	T=input_T->answer;
+	alb=input_alb->answer;
+	DEM=input_DEM->answer;
+	ndvi=input_ndvi->answer;
+	Rn=input_Rn->answer;
+	g0=input_g0->answer;
+	wet=output->answer;
+	dry=output1->answer;
+	
+	/* find maps in mapset */
+	mapset_T = G_find_cell2 (T, "");
+	if (mapset_T == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), T);
+	mapset_alb = G_find_cell2 (alb, "");
+	if (mapset_alb == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), alb);
+	mapset_DEM = G_find_cell2 (DEM, "");
+	if (mapset_DEM == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), DEM);
+	mapset_ndvi = G_find_cell2 (ndvi, "");
+	if (mapset_ndvi == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), ndvi);
+	mapset_Rn = G_find_cell2 (Rn, "");
+	if (mapset_Rn == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), Rn);
+	mapset_g0 = G_find_cell2 (g0, "");
+	if (mapset_g0 == NULL)
+	        G_fatal_error (_("cell file [%s] not found"), g0);
+
+	/* check legal output name */ 
+	if (G_legal_filename (wet) < 0)
+			G_fatal_error (_("[%s] is an illegal name"), wet);
+	if (G_legal_filename (dry) < 0)
+			G_fatal_error (_("[%s] is an illegal name"), dry);
+		
+	/* determine the input map type (CELL/FCELL/DCELL) */
+	//data_type = G_raster_map_type(T, mapset);
+
+	if ( (infd_T = G_open_cell_old (T, mapset_T)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"), T);
+	if ( (infd_alb = G_open_cell_old (alb, mapset_alb)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"),alb);
+	if ( (infd_DEM = G_open_cell_old (DEM, mapset_DEM)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"),DEM);
+	if ( (infd_ndvi = G_open_cell_old (ndvi, mapset_ndvi)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"),ndvi);
+	if ( (infd_Rn = G_open_cell_old (Rn, mapset_Rn)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"),Rn);
+	if ( (infd_g0 = G_open_cell_old (g0, mapset_g0)) < 0)
+		G_fatal_error (_("Cannot open cell file [%s]"),g0);
+	
+	if (G_get_cellhd (T, mapset_T, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), T);
+	if (G_get_cellhd (alb, mapset_alb, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), alb);
+	if (G_get_cellhd (DEM, mapset_DEM, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), DEM);
+	if (G_get_cellhd (ndvi, mapset_ndvi, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), ndvi);
+	if (G_get_cellhd (Rn, mapset_Rn, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), Rn);
+	if (G_get_cellhd (g0, mapset_g0, &cellhd) < 0)
+		G_fatal_error (_("Cannot read file header of [%s]"), g0);
+
+	/* Allocate input buffer */
+	inrast_T  = G_allocate_d_raster_buf();
+	inrast_alb = G_allocate_d_raster_buf();
+	inrast_DEM = G_allocate_d_raster_buf();
+	inrast_ndvi = G_allocate_d_raster_buf();
+	inrast_Rn = G_allocate_d_raster_buf();
+	inrast_g0 = G_allocate_d_raster_buf();
+	
+	/* Allocate output buffer */
+	nrows = G_window_rows();
+	ncols = G_window_cols();
+	outrast = G_allocate_d_raster_buf();
+	outrast1 = G_allocate_d_raster_buf();
+
+	if ( (outfd = G_open_raster_new (wet,DCELL_TYPE)) < 0)
+		G_fatal_error (_("Could not open <%s>"),wet);
+	if ( (outfd = G_open_raster_new (dry,DCELL_TYPE)) < 0)
+		G_fatal_error (_("Could not open <%s>"),dry);
+
+	for (row = 0; row < nrows; row++)
+	{
+		DCELL d_tempk; 		/* Input raster */
+		DCELL d_alb; 		/* Input raster */
+		DCELL d_dem; 		/* Input raster */
+		DCELL d_ndvi; 		/* Input raster */
+		DCELL d_Rn;		/* Input raster */
+		DCELL d_g0;		/* Input raster */
+		DCELL d_wet;	/* Output pixel */
+		DCELL d_dry;	/* Output pixel */
+		DCELL d_t0dem;	/* Generated here */
+
+		/* read a line input maps into buffers*/	
+		if (G_get_d_raster_row (infd_T, inrast_T, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),T);
+		if (G_get_d_raster_row (infd_alb, inrast_alb, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),alb);
+		if (G_get_d_raster_row (infd_DEM, inrast_DEM, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),DEM);
+		if (G_get_d_raster_row (infd_ndvi, inrast_ndvi, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),ndvi);
+		if (G_get_d_raster_row (infd_Rn, inrast_Rn, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),Rn);
+		if (G_get_d_raster_row (infd_g0, inrast_g0, row) < 0)
+			G_fatal_error (_("Could not read from <%s>"),g0);
+		
+		/* read every cell in the line buffers */
+		for (col=0; col < ncols; col++)
+		{
+			d_tempk	= ((DCELL *) inrast_T)[col];
+			d_alb	= ((DCELL *) inrast_alb)[col];
+			d_dem	= ((DCELL *) inrast_DEM)[col];
+			d_ndvi	= ((DCELL *) inrast_ndvi)[col];
+			d_Rn	= ((DCELL *) inrast_Rn)[col];
+			d_g0	= ((DCELL *) inrast_g0)[col];
+			
+			/* Initialize pixels as negative */
+			d_wet = -1.0;
+			d_dry = -1.0;
+
+			/* Calculate T0dem */
+			d_t0dem = d_dem * 0.00627 + d_tempk;
+			/* if Albedo is high and H is positive */
+			if(d_alb>0.3&&(d_Rn-d_g0)>0.0){
+				d_wet = 0.0; /* Not Wet pixel Candidate */
+				d_dry = 1.0; /* Dry pixel candidate */
+			/* if Albedo is not high and H is negative */
+			} else if (d_alb<0.3&&(d_Rn-d_g0)<=0.0){
+				d_wet = 1.0; /* Wet pixel Candidate */
+				d_dry = 0.0; /* Not dry pixel Candidate */
+			/* if g0 is negative, then not a candidate */
+			} else if (d_g0<=0.0){
+				d_wet = 0.0; /* Not wet pixel candidate */
+				d_dry = 0.0; /* Not dry pixel candidate */
+			}
+			/* if altitude corrected temperature is strange, then not a candidate */
+			if (d_t0dem<=273.15||d_t0dem>340.0){
+				d_wet = 0.0; /* Not wet pixel candidate */
+				d_dry = 0.0; /* Not dry pixel candidate */
+			}
+
+			if (zero->answer && d_wet<0.0){
+				d_wet = 0.0;
+			}
+			if (zero->answer && d_dry<0.0){
+				d_dry = 0.0;
+			}
+			((DCELL *) outrast)[col] = d_wet;
+			((DCELL *) outrast1)[col] = d_dry;
+		}
+		
+		if (G_put_d_raster_row (outfd, outrast) < 0)
+			G_fatal_error (_("Cannot write to <%s>"),wet);
+		if (G_put_d_raster_row (outfd, outrast1) < 0)
+			G_fatal_error (_("Cannot write to <%s>"),dry);
+	}	
+	G_free(inrast_T);
+	G_free(inrast_alb);
+	G_free(inrast_DEM);
+	G_free(inrast_ndvi);
+	G_free(inrast_Rn);
+	G_free(inrast_g0);
+	G_free(outrast);
+	G_free(outrast1);
+	G_close_cell (infd_T);
+	G_close_cell (infd_alb);
+	G_close_cell (infd_DEM);
+	G_close_cell (infd_ndvi);
+	G_close_cell (infd_Rn);
+	G_close_cell (infd_g0);
+	G_close_cell (outfd);
+	G_close_cell (outfd1);
+	
+        /* add command line incantation to history file */
+        G_short_history(wet, "raster", &history);
+        G_command_history(&history);
+        G_write_history(wet, &history);
+        G_short_history(dry, "raster", &history);
+        G_command_history(&history);
+        G_write_history(dry, &history);
+
+	exit(EXIT_SUCCESS);
+}


Property changes on: grass-addons/gipe/i.eb.wetdrypix/main.c
___________________________________________________________________
Name: svn:executable
   + *



More information about the grass-commit mailing list