[GRASS-SVN] r33701 - in grass-addons/gipe: . i.modis.stateqa
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 6 22:23:06 EDT 2008
Author: ychemin
Date: 2008-10-06 22:23:06 -0400 (Mon, 06 Oct 2008)
New Revision: 33701
Added:
grass-addons/gipe/i.modis.stateqa/
grass-addons/gipe/i.modis.stateqa/Makefile
grass-addons/gipe/i.modis.stateqa/i.modis.stateqa.html
grass-addons/gipe/i.modis.stateqa/main.c
grass-addons/gipe/i.modis.stateqa/stateqa500a.c
grass-addons/gipe/i.modis.stateqa/stateqa500b.c
grass-addons/gipe/i.modis.stateqa/stateqa500c.c
grass-addons/gipe/i.modis.stateqa/stateqa500d.c
grass-addons/gipe/i.modis.stateqa/stateqa500e.c
grass-addons/gipe/i.modis.stateqa/stateqa500f.c
grass-addons/gipe/i.modis.stateqa/stateqa500g.c
grass-addons/gipe/i.modis.stateqa/stateqa500h.c
grass-addons/gipe/i.modis.stateqa/stateqa500i.c
grass-addons/gipe/i.modis.stateqa/stateqa500j.c
grass-addons/gipe/i.modis.stateqa/stateqa500k.c
Modified:
grass-addons/gipe/Makefile.imagery
Log:
Added modis State QA module
Modified: grass-addons/gipe/Makefile.imagery
===================================================================
--- grass-addons/gipe/Makefile.imagery 2008-10-06 23:10:29 UTC (rev 33700)
+++ grass-addons/gipe/Makefile.imagery 2008-10-07 02:23:06 UTC (rev 33701)
@@ -38,6 +38,7 @@
i.latitude \
i.lmf \
i.longitude \
+ i.modis.stateqa \
i.sattime \
i.sunhours \
i.vi.mpi \
Added: grass-addons/gipe/i.modis.stateqa/Makefile
===================================================================
--- grass-addons/gipe/i.modis.stateqa/Makefile (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/Makefile 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,14 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.modis.stateqa
+
+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-addons/gipe/i.modis.stateqa/i.modis.stateqa.html
===================================================================
--- grass-addons/gipe/i.modis.stateqa/i.modis.stateqa.html (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/i.modis.stateqa.html 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,132 @@
+<H2>DESCRIPTION</H2>
+
+<em>i.qc.modis</em> Extracts Requested State Quality Assessment flags from Modis 09 A product
+This is the QA_state_500m layer.
+
+<pre>
+<em> Cloud State unsigned int bits[0-1]</em>
+</pre>
+<ul>
+ <li>[00]= class 0: clear</li>
+ <li>[01]= class 1: cloudy</li>
+ <li>[10]= class 2: mixed</li>
+ <li>[11]= class 3: not set, assumed clear</li>
+</ul>
+
+<pre>
+<em>Cloud shadow unsigned int bits[2]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: yes</li>
+ <li>[1]= class 1: no</li>
+</ul>
+
+<pre>
+<em>Land/Water Flag unsigned int bits[3-5]</em>
+</pre>
+<ul>
+ <li>[000]= class 0: Shallow ocean</li>
+ <li>[001]= class 1: Land</li>
+ <li>[010]= class 2: Ocean coastlines and lake shorelines</li>
+ <li>[011]= class 3: Shallow inland water</li>
+ <li>[100]= class 4: Ephemeral water</li>
+ <li>[101]= class 5: Deep inland water</li>
+ <li>[110]= class 6: Continental/moderate ocean</li>
+ <li>[111]= class 7: Deep ocean</li>
+</ul>
+
+<pre>
+<em>Aerosol Quantity unsigned int bits[6-7]</em>
+</pre>
+<ul>
+ <li>[00]= class 0: Climatology</li>
+ <li>[01]= class 1: Low</li>
+ <li>[10]= class 2: Average</li>
+ <li>[11]= class 3: High</li>
+</ul>
+
+<pre>
+<em>Cirrus detected unsigned int bits[8-9]</em>
+</pre>
+<ul>
+ <li>[00]= class 0: None</li>
+ <li>[01]= class 1: Small</li>
+ <li>[10]= class 2: Average</li>
+ <li>[11]= class 3: High</li>
+</ul>
+
+<pre>
+<em>Internal Cloud Algorithm Flag unsigned int bits[10]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Cloud</li>
+ <li>[1]= class 1: No cloud</li>
+</ul>
+
+<pre>
+<em>Internal Fire Algorithm Flag unsigned int bits[11]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Fire</li>
+ <li>[1]= class 1: No fire</li>
+</ul>
+
+<pre>
+<em>MOD35 snow/ice flag unsigned int bits [12]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Yes</li>
+ <li>[1]= class 1: No</li>
+</ul>
+
+<pre>
+<em>Pixel adjacent to cloud unsigned int bits[13]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Yes</li>
+ <li>[1]= class 1: No</li>
+</ul>
+
+<pre>
+<em>BRDF correction performed unsigned int bits[14]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Yes</li>
+ <li>[1]= class 1: No</li>
+</ul>
+
+<pre>
+<em>Internal Snow Mask unsigned int bits[15]</em>
+</pre>
+<ul>
+ <li>[0]= class 0: Snow</li>
+ <li>[1]= class 1: No snow</li>
+</ul>
+
+<H2>NOTES</H2>
+This module uses State-QA 500m images (see Vermote et al., 2008),
+this is the proper place to find cloud related information.
+
+<H2>TODO</H2>
+Testing is required.
+
+<H2>SEE ALSO</H2>
+
+Vermote E.F., Kotchenova S.Y., Ray J.P.
+MODIS Surface Reflectance User's Guide.
+Version 1.2. June 2008.
+MODIS Land Surface Reflectance Science Computing Facility.
+<A HREF="http://modis-sr.ltdri.org">Homepage</A><br>
+
+
+<em>
+<A HREF="i.qc.modis.html">i.qc.modis</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+Yann Chemin, International Rice Research Institute, The Philippines.<BR>
+
+
+<p>
+<i>Last changed: $Date: 2008/07/28 15:33:42 $</i>
Added: grass-addons/gipe/i.modis.stateqa/main.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/main.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/main.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,187 @@
+
+/****************************************************************************
+ *
+ * MODULE: i.modis.stateqa
+ * AUTHOR(S): Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE: Converts State Quality Assessment flags into human readable
+ * classes for Modis surface reflectance products 500m
+ * (MOD09A)
+ *
+ * COPYRIGHT: (C) 2008 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>
+
+/* 500m State QA Products in MOD09A */
+CELL stateqa500a(CELL pixel);
+CELL stateqa500b(CELL pixel);
+CELL stateqa500c(CELL pixel);
+CELL stateqa500d(CELL pixel);
+CELL stateqa500e(CELL pixel);
+CELL stateqa500f(CELL pixel);
+CELL stateqa500g(CELL pixel);
+CELL stateqa500h(CELL pixel);
+CELL stateqa500i(CELL pixel);
+CELL stateqa500j(CELL pixel);
+CELL stateqa500k(CELL pixel);
+
+int main(int argc, char *argv[])
+{
+ struct Cell_head cellhd; /*region+header info */
+ int nrows, ncols;
+ int row, col;
+ char *qcflag; /*Switch for particular index */
+ struct GModule *module;
+ struct Option *input1, *input2, *output;
+ struct Flag *flag1;
+ struct History history; /*metadata */
+ struct Colors colors; /*Color rules */
+
+ /************************************/
+ char *result;/*output raster name */
+
+ /*File Descriptors */
+ int infd;
+ int outfd;
+ char *qcchan;
+ CELL *inrast;
+ CELL *outrast;
+ RASTER_MAP_TYPE data_type_output = CELL_TYPE;
+
+ /************************************/
+ G_gisinit(argv[0]);
+ module = G_define_module();
+ module->keywords = _("imagery, State QA, Quality Control, surface reflectance, Modis");
+ module->description =
+ _("Extract quality control parameters from Modis 500m State QA layers");
+
+ /* Define the different options */
+ input1 = G_define_option();
+ input1->key = _("qcname");
+ input1->type = TYPE_STRING;
+ input1->required = YES;
+ input1->gisprompt = _("Name of QC type to extract");
+ input1->description = _("Name of QC");
+ input1->options = "cloud_state,cloud_shadow,land_water_flag,aerosol_quantity,cirrus_detected,internal_cloud_alg_flag,internal_fire_alg_flag,MOD35_snow_ice_flag,pixel_adjacent_to_cloud,brdf_correction,internal_snow_mask";
+ input1->answer = _("cloud_state");
+
+ input2 = G_define_standard_option(G_OPT_R_INPUT);
+ input2->description =
+ _("Name of the surface reflectance state QA layer [bit array]");
+
+ output = G_define_standard_option(G_OPT_R_OUTPUT);
+ output->key = _("output");
+ output->description =
+ _("Name of the output state QA type classification layer");
+ output->answer = _("qc");
+
+ /********************/
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ qcflag = input1->answer;
+ qcchan = input2->answer;
+
+ result = output->answer;
+
+ if ((infd = G_open_cell_old(qcchan, "")) < 0)
+ G_fatal_error(_("Cannot open cell file [%s]"), qcchan);
+
+ if (G_get_cellhd(qcchan, "", &cellhd) < 0)
+ G_fatal_error(_("Cannot read file header of [%s]"), qcchan);
+
+ inrast = G_allocate_c_raster_buf();
+
+ G_debug(3, "number of rows %d", cellhd.rows);
+ nrows = G_window_rows();
+ ncols = G_window_cols();
+ outrast = G_allocate_c_raster_buf();
+
+ /* Create New raster files */
+ if ((outfd = G_open_raster_new(result, data_type_output)) < 0)
+ G_fatal_error(_("Could not open <%s>"), result);
+
+ /* Process pixels */
+ for (row = 0; row < nrows; row++)
+ {
+ CELL c;
+ CELL qa500chan;
+ G_percent(row, nrows, 2);
+ if (G_get_c_raster_row(infd, inrast, row) < 0)
+ G_fatal_error(_("Could not read from <%s>"), qcchan);
+
+ /*process the data */
+ for (col = 0; col < ncols; col++)
+ {
+ c = inrast[col];
+ qa500chan = c ;
+
+ if (G_is_c_null_value(&c))
+ G_set_c_null_value(&outrast[col], 1);
+ else if (!strcmp(qcflag, "cloud_state"))
+ /*calculate cloud state */
+ c = stateqa500a(qa500chan);
+ else if (!strcmp(qcflag, "cloud_shadow"))
+ /*calculate cloud state */
+ c = stateqa500b(qa500chan);
+ else if (!strcmp(qcflag, "land_water_flag"))
+ /*calculate land/water flag */
+ c = stateqa500c(qa500chan);
+ else if (!strcmp(qcflag, "aerosol_quantity"))
+ /*calculate aerosol quantity */
+ c = stateqa500d(qa500chan);
+ else if (!strcmp(qcflag, "cirrus_detected"))
+ /*calculate cirrus detected flag */
+ c = stateqa500e(qa500chan);
+ else if (!strcmp(qcflag, "internal_cloud_alg_flag"))
+ /*calculate internal cloud algorithm flag */
+ c = stateqa500f(qa500chan);
+ else if (!strcmp(qcflag, "internal_fire_alg_flag"))
+ /*calculate internal fire algorithm flag */
+ c = stateqa500g(qa500chan);
+ else if (!strcmp(qcflag, "mod35_snow_ice_flag"))
+ /*calculate MOD35 snow/ice flag */
+ c = stateqa500h(qa500chan);
+ else if (!strcmp(qcflag, "pixel_adjacent_to_cloud"))
+ /*calculate pixel is adjacent to cloud flag */
+ c = stateqa500i(qa500chan);
+ else if (!strcmp(qcflag, "brdf_correction"))
+ /*calculate BRDF correction performed flag */
+ c = stateqa500j(qa500chan);
+ else if (!strcmp(qcflag, "internal_snow_mask"))
+ /*calculate internal snow mask flag */
+ c = stateqa500k(qa500chan);
+ else
+ G_fatal_error(_("Unknown flag name, please check spelling"));
+
+ outrast[col] = c;
+ }
+
+ if (G_put_c_raster_row(outfd, outrast) < 0)
+ G_fatal_error(_("Cannot write to output raster file"));
+ }
+
+ G_free(inrast);
+ G_close_cell(infd);
+ G_free(outrast);
+ G_close_cell(outfd);
+
+ /* Color from 0 to 7 in grey */
+ G_init_colors(&colors);
+ G_add_color_rule(0, 0, 0, 0, 7, 255, 255, 255, &colors);
+ G_short_history(result, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result, &history);
+ exit(EXIT_SUCCESS);
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500a.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500a.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500a.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,22 @@
+/* Cloud State unsigned int bits[0-1]
+ * 00 -> class 0: clear
+ * 01 -> class 1: cloudy
+ * 10 -> class 2: mixed
+ * 11 -> class 3: not set, assumed clear
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500a(CELL pixel)
+{
+ CELL qctemp;
+
+ /* Select bit 0 and 1 (right-side).
+ * hexadecimal "0x03" => binary "11"
+ * this will set all other bits to null */
+ qctemp = pixel & 0x03;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500b.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500b.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500b.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* cloud shadow unsigned int bits[2]
+ * 0 -> class 0: yes
+ * 1 -> class 1: no
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500b(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 2;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500c.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500c.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500c.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,24 @@
+/* LAND/WATER FLAG unsigned int bits[3-5]
+ * 000 -> class 0: Shallow ocean
+ * 001 -> class 1: Land
+ * 010 -> class 2: Ocean coastlines and lake shorelines
+ * 011 -> class 3: Shallow inland water
+ * 100 -> class 4: Ephemeral water
+ * 101 -> class 5: Deep inland water
+ * 110 -> class 6: Continental/moderate ocean
+ * 111 -> class 7: Deep ocean
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500c(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 3;
+ qctemp = pixel & 0x07;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500d.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500d.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500d.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,20 @@
+/* AEROSOL QUANTITY unsigned int bits[6-7]
+ * 00 -> class 0: Climatology
+ * 01 -> class 1: Low
+ * 10 -> class 2: Average
+ * 11 -> class 3: High
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500d(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 6;
+ qctemp = pixel & 0x03;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500e.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500e.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500e.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,20 @@
+/* CIRRUS DETECTED unsigned int bits[8-9]
+ * 00 -> class 0: None
+ * 01 -> class 1: Small
+ * 10 -> class 2: Average
+ * 11 -> class 3: High
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500e(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 8;
+ qctemp = pixel & 0x03;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500f.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500f.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500f.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* Internal Cloud Algorithm Flag unsigned int bits[10]
+ * 0 -> class 0: Cloud
+ * 1 -> class 1: No cloud
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500f(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 10;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500g.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500g.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500g.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* Internal Fire Algorithm Flag unsigned int bits[11]
+ * 0 -> class 0: Fire
+ * 1 -> class 1: No fire
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500g(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 11;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500h.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500h.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500h.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* MOD35 snow/ice flag unsigned int bits [12]
+ * 0 -> class 0: Yes
+ * 1 -> class 1: No
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500h(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 12;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500i.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500i.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500i.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* Pixel adjacent to cloud unsigned int bits[13]
+ * 0 -> class 0: Yes
+ * 1 -> class 1: No
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500i(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 13;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500j.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500j.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500j.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* BRDF correction performed unsigned int bits[14]
+ * 0 -> class 0: Yes
+ * 1 -> class 1: No
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500j(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 14;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
Added: grass-addons/gipe/i.modis.stateqa/stateqa500k.c
===================================================================
--- grass-addons/gipe/i.modis.stateqa/stateqa500k.c (rev 0)
+++ grass-addons/gipe/i.modis.stateqa/stateqa500k.c 2008-10-07 02:23:06 UTC (rev 33701)
@@ -0,0 +1,18 @@
+/* Internal Snow Mask unsigned int bits[15]
+ * 0 -> class 0: Snow
+ * 1 -> class 1: No snow
+ */
+
+#include "grass/gis.h"
+
+CELL stateqa500k(CELL pixel)
+{
+ CELL qctemp;
+
+ pixel >> 15;
+ qctemp = pixel & 0x01;
+
+ return qctemp;
+}
+
+
More information about the grass-commit
mailing list