[GRASS-SVN] r37954 - in grass/trunk/imagery: . i.eb.evapfr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 19 07:56:01 EDT 2009


Author: ychemin
Date: 2009-06-19 07:56:01 -0400 (Fri, 19 Jun 2009)
New Revision: 37954

Added:
   grass/trunk/imagery/i.eb.evapfr/
   grass/trunk/imagery/i.eb.evapfr/Makefile
   grass/trunk/imagery/i.eb.evapfr/evap_fr.c
   grass/trunk/imagery/i.eb.evapfr/i.eb.evapfr.html
   grass/trunk/imagery/i.eb.evapfr/main.c
   grass/trunk/imagery/i.eb.evapfr/soilmoisture.c
Log:
Added i.eb.evapfr

Added: grass/trunk/imagery/i.eb.evapfr/Makefile
===================================================================
--- grass/trunk/imagery/i.eb.evapfr/Makefile	                        (rev 0)
+++ grass/trunk/imagery/i.eb.evapfr/Makefile	2009-06-19 11:56:01 UTC (rev 37954)
@@ -0,0 +1,14 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.eb.evapfr
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+ifneq ($(USE_LARGEFILES),)
+	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
+endif
+
+default: cmd

Added: grass/trunk/imagery/i.eb.evapfr/evap_fr.c
===================================================================
--- grass/trunk/imagery/i.eb.evapfr/evap_fr.c	                        (rev 0)
+++ grass/trunk/imagery/i.eb.evapfr/evap_fr.c	2009-06-19 11:56:01 UTC (rev 37954)
@@ -0,0 +1,7 @@
+#include<stdio.h>
+#include<math.h>
+
+double evap_fr(double r_net, double g0, double h0)
+{
+    return((r_net - g0 - h0) / (r_net - g0));
+}

Added: grass/trunk/imagery/i.eb.evapfr/i.eb.evapfr.html
===================================================================
--- grass/trunk/imagery/i.eb.evapfr/i.eb.evapfr.html	                        (rev 0)
+++ grass/trunk/imagery/i.eb.evapfr/i.eb.evapfr.html	2009-06-19 11:56:01 UTC (rev 37954)
@@ -0,0 +1,34 @@
+<H2>DESCRIPTION</H2>
+
+<EM>i.eb.evapfr</EM> calculates the evaporative fraction after [1]. Main implementation in [3].
+It takes input of Net Radiation (see r.sun, i.eb.netrad (grass-addons)), soil heat flux (see i.eb.g0) and sensible heat flux (see i.eb.h_SEBAL01). 
+A flag adds a root zone empirical soil moisture output from the article of Makin, Molden and Bastiaanssen (2001).
+<H2>NOTES</H2>
+
+<H2>TODO</H2>
+
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="r.sun.html">r.sun</A><br>
+<A HREF="i.eb.g0.html">i.eb.g0</A><br>
+<A HREF="i.eb.h_SEBAL01.html">i.eb.h_SEBAL01</A><br>
+</em>
+
+<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] Chemin Y., Alexandridis T.A., 2001. Improving spatial resolution of ET seasonal for irrigated rice in Zhanghe, China. Asian Journal of Geoinformatics. 5(1):3-11,2004. 
+
+  <p>[3] Alexandridis T.K., Cherif I., Chemin Y., Silleos N.G., Stavrinos E., Zalidis G.C. Integrated methodology for estimating water use in Mediterranean agricultural areas. Remote Sensing. -(-):,2009. (submitted))
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, Asian Institute of Technology, Thailand<BR>
+
+
+<p>
+<i>Last changed: $Date: 2006/10/10 11:28:44 $</i>

Added: grass/trunk/imagery/i.eb.evapfr/main.c
===================================================================
--- grass/trunk/imagery/i.eb.evapfr/main.c	                        (rev 0)
+++ grass/trunk/imagery/i.eb.evapfr/main.c	2009-06-19 11:56:01 UTC (rev 37954)
@@ -0,0 +1,199 @@
+
+/****************************************************************************
+ *
+ * MODULE:       i.eb.evapfr
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE:      Calculates the evaporative fraction
+ *               as seen in Bastiaanssen (1995) 
+ *
+ * COPYRIGHT:    (C) 2002-2006 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.
+ *
+ *****************************************************************************/
+     
+    
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+double evap_fr(double r_net, double g0, double h0);
+double soilmoisture(double evapfr);
+
+int main(int argc, char *argv[]) 
+{
+    int nrows, ncols;
+    int row, col;
+    int makin = 0;		/*Makin Flag for root zone soil moisture output */
+    struct GModule *module;
+    struct Option *input1, *input2, *input3, *output1, *output2;
+    struct Flag *flag1, *flag2;
+    struct History history;	/*metadata */
+    char *result1, *result2;	/*output raster name */
+    
+    int infd_rnet, infd_g0, infd_h0;
+    int outfd1, outfd2;
+    char *rnet, *g0, *h0;
+    char *evapfr, *theta;
+    void *inrast_rnet, *inrast_g0, *inrast_h0;
+
+    DCELL * outrast1, *outrast2;
+
+    /************************************/ 
+    G_gisinit(argv[0]);
+    module = G_define_module();
+    module->keywords =
+	_("evaporative fraction, soil moisture, energy balance, SEBAL");
+    module->description =
+	_("evaporative fraction (Bastiaanssen, 1995) and root zone soil moisture (Makin, Molden and Bastiaanssen, 2001)");
+    
+    /* Define the different options */ 
+    input1 = G_define_standard_option(G_OPT_R_INPUT);
+    input1->key = _("rnet");
+    input1->description = _("Name of the Net Radiation map [W/m2]");
+    input1->answer = _("rnet");
+
+    input2 = G_define_standard_option(G_OPT_R_INPUT);
+    input2->key = _("g0");
+    input2->description = _("Name of the soil heat flux map [W/m2]");
+    input2->answer = _("g0");
+
+    input3 = G_define_standard_option(G_OPT_R_INPUT);
+    input3->key = _("h0");
+    input3->description = _("Name of the sensible heat flux map [W/m2]");
+    input3->answer = _("h0");
+
+    output1 = G_define_standard_option(G_OPT_R_OUTPUT);
+    output1->key = _("evapfr");
+    output1->description =
+	_("Name of the output evaporative fraction layer");
+    output1->answer = _("evapfr");
+
+    output2 = G_define_standard_option(G_OPT_R_OUTPUT);
+    output2->key = _("theta");
+    output2->required = NO;
+    output2->description =
+	_("Name of the output root zone soil moisture layer");
+    output2->answer = _("theta");
+
+    flag1 = G_define_flag();
+    flag1->key = 'm';
+    flag1->description =
+	_("root zone soil moisture output (Makin, Molden and Bastiaanssen, 2001)");
+
+    /********************/ 
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    rnet = input1->answer;
+    g0 = input2->answer;
+    h0 = input3->answer;
+    result1 = output1->answer;
+    result2 = output2->answer;
+    makin = flag1->answer;
+    
+    /***************************************************/ 
+    if ((infd_rnet = G_open_cell_old(rnet, "")) < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), rnet);
+    inrast_rnet = G_allocate_d_raster_buf();
+    
+    /***************************************************/ 
+    if ((infd_g0 = G_open_cell_old(g0, "")) < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), g0);
+    inrast_g0 = G_allocate_d_raster_buf();
+    
+    /***************************************************/ 
+    if ((infd_h0 = G_open_cell_old(h0, "")) < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), h0);
+    inrast_h0 = G_allocate_d_raster_buf();
+    
+    /***************************************************/ 
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+    outrast1 = G_allocate_d_raster_buf();
+    if (makin) 
+	outrast2 = G_allocate_d_raster_buf();
+    
+    /* Create New raster files */ 
+    if ((outfd1 = G_open_raster_new(result1,DCELL_TYPE)) < 0)
+	G_fatal_error(_("Unable to open raster map <%s>"), result1);
+    if (makin) 
+	if ((outfd2 = G_open_raster_new(result2,DCELL_TYPE)) < 0)
+	    G_fatal_error(_("Unable to open raster map <%s>"), result2);
+        
+    /* Process pixels */ 
+    for (row = 0; row < nrows; row++)
+    {
+	DCELL d;
+	DCELL d_rnet;
+	DCELL d_g0;
+	DCELL d_h0;
+	G_percent(row, nrows, 2);
+	
+        /* read input maps */ 
+        if (G_get_d_raster_row(infd_rnet, inrast_rnet, row)<0)
+	    G_fatal_error(_("Unable to read from <%s>"), rnet);
+	if (G_get_d_raster_row(infd_g0, inrast_g0, row) < 0)
+	    G_fatal_error(_("Unable to read from <%s>"), g0);
+	if (G_get_d_raster_row(infd_h0, inrast_h0, row) < 0)
+	    G_fatal_error(_("Unable to read from <%s>"), h0);
+        /*process the data */ 
+        for (col = 0; col < ncols; col++)
+        {
+            d_rnet = ((DCELL *) inrast_rnet)[col];
+            d_g0 = ((DCELL *) inrast_g0)[col];
+            d_h0 = ((DCELL *) inrast_h0)[col];
+	    if (G_is_d_null_value(&d_rnet) || 
+                G_is_d_null_value(&d_g0) ||
+		G_is_d_null_value(&d_h0)) {
+		G_set_d_null_value(&outrast1[col], 1);
+		if (makin) 
+		    G_set_d_null_value(&outrast2[col], 1);
+	    }
+	    else {
+                /* calculate evaporative fraction       */ 
+                d = evap_fr(d_rnet, d_g0, d_h0);
+		outrast1[col] = d;
+                /* calculate soil moisture              */ 
+                if (makin) 
+                {
+                    d = soilmoisture(d);
+                    outrast2[col] = d;
+		}
+	    }
+        }
+	if (G_put_d_raster_row(outfd1, outrast1) < 0)
+	    G_fatal_error(_("Unable to write to output raster map"));
+	if (makin) 
+        {
+            if (G_put_d_raster_row(outfd2, outrast2) < 0)
+                G_fatal_error(_("Unable to write to output raster map"));
+        }
+    }
+    G_free(inrast_rnet);
+    G_free(inrast_g0);
+    G_free(inrast_h0);
+    G_close_cell(infd_rnet);
+    G_close_cell(infd_g0);
+    G_close_cell(infd_h0);
+    G_free(outrast1);
+    G_free(outrast2);
+    if (makin) {
+	G_close_cell(outfd1);
+	G_close_cell(outfd2);
+    }
+    G_short_history(result1, "raster", &history);
+    G_command_history(&history);
+    G_write_history(result1, &history);
+    if (makin) {
+	G_short_history(result2, "raster", &history);
+	G_command_history(&history);
+	G_write_history(result2, &history);
+    }
+    exit(EXIT_SUCCESS);
+}
+
+

Added: grass/trunk/imagery/i.eb.evapfr/soilmoisture.c
===================================================================
--- grass/trunk/imagery/i.eb.evapfr/soilmoisture.c	                        (rev 0)
+++ grass/trunk/imagery/i.eb.evapfr/soilmoisture.c	2009-06-19 11:56:01 UTC (rev 37954)
@@ -0,0 +1,13 @@
+#include<stdio.h>
+#include<math.h>
+#include<stdlib.h>
+
+    /* soil moisture in the root zone
+     * Makin, Molden and Bastiaanssen, 2001
+     */ 
+double soilmoisture(double evap_fr) 
+{
+    return ((exp((evap_fr - 1.2836) / 0.4213)) / 0.511);
+}
+
+



More information about the grass-commit mailing list