浏览代码

merge fixes from devbr6

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@36184 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 16 年之前
父节点
当前提交
8d34148d6a
共有 4 个文件被更改,包括 65 次插入33 次删除
  1. 33 15
      imagery/i.pca/i.pca.html
  2. 1 1
      imagery/i.pca/local_proto.h
  3. 8 2
      imagery/i.pca/main.c
  4. 23 15
      imagery/i.pca/support.c

+ 33 - 15
imagery/i.pca/i.pca.html

@@ -8,7 +8,7 @@ raster map layers containing the principal components of
 the input data in decreasing order of variance
 ("contrast").  The output raster map layers are assigned
 names with .1, .2, ... .n suffixes.  The current geographic
-region definition and mask settings are respected when
+region definition and MASK settings are respected when
 reading the input raster map layers. When the rescale
 option is used, the output files are rescaled to fit the
 min,max range.
@@ -16,35 +16,49 @@ min,max range.
 <H2>OPTIONS</H2>
 
 <H3>Parameters:</H3>
-
 <DL>
-
 <DT><B>input=</B><EM>name,name</EM>[<EM>,name,name</EM>,...] 
-
 <DD>Name of two or more input raster map layers.
 
 <DT><B>output=</B><EM>name</EM> 
-
 <DD>The output raster map layer name to which suffixes are
 added.  Each output raster map layer is assigned this
 user-specified <EM>name</EM> with a numerical (.1, .2, ...
 .n) suffix.
 
 <DT><B>rescale=</B><EM>min,max</EM> 
-
 <DD>The optional output category range. (Default: 0,255) If
 rescale=0,0,  no rescaling is performed on output files.
 
 <DD>If output is rescaled, the output raster will be of type CELL. If 
 the output is not rescaled, the output raster will be of type DCELL.
-
 </DL>
 
+
 <H2>NOTES</H2>
 
 Richards (1986) gives a good example of the application of principal
 components analysis (pca) to a time series of LANDSAT images of a burned
 region in Australia.
+<P>
+Eigenvalue and eigenvector information is stored in the output maps'
+history files. View with <em>r.info</em>.
+
+
+<H2>EXAMPLE</H2>
+
+Using the Spearfish Imagery sample dataset
+
+<div class="code"><pre>
+i.pca in=spot.ms.1,spot.ms.2,spot.ms.3 out=spot_pca
+
+r.info -h spot_pca.1
+   Eigen values, (vectors), and [percent importance]:
+   PC1   1170.12 ( -0.63 -0.65 -0.43 ) [ 88.07% ]
+   PC2    152.49 (  0.23  0.37 -0.90 ) [ 11.48% ]
+   PC3      6.01 (  0.75 -0.66 -0.08 ) [  0.45% ]
+</pre></div>
+
 
 <H2>SEE ALSO</H2>
 
@@ -61,13 +75,16 @@ University of Texas, Austin, 1990.
 
 <P>
 
-<EM><A HREF="i.cca.html">i.cca</A></EM><br>
-<EM><A HREF="i.class.html">i.class</A></EM><br>
-<EM><A HREF="i.fft.html">i.fft</A></EM><br>
-<EM><A HREF="i.ifft.html">i.ifft</A></EM><br>
-<EM><A HREF="m.eigensystem.html">m.eigensystem</A></EM><br>
-<EM><A HREF="r.covar.html">r.covar</A></EM><br>
-<EM><A HREF="r.mapcalc.html">r.mapcalc</A></EM>
+<EM>
+<A HREF="i.cca.html">i.cca</A><br>
+<A HREF="i.class.html">i.class</A><br>
+<A HREF="i.fft.html">i.fft</A><br>
+<A HREF="i.ifft.html">i.ifft</A><br>
+<A HREF="m.eigensystem.html">m.eigensystem</A><br>
+<A HREF="r.covar.html">r.covar</A><br>
+<A HREF="r.mapcalc.html">r.mapcalc</A>
+</EM>
+
 
 <H2>AUTHOR</H2>
 
@@ -82,4 +99,5 @@ Research Laboratory
 Rewritten for GRASS 6.x and major modifications by <br>
 Brad Douglas
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

+ 1 - 1
imagery/i.pca/local_proto.h

@@ -2,6 +2,6 @@
 #define __LOCAL_PROTO_H__
 
 /* support.c */
-int write_support(int, char *, double **);
+int write_support(int, char *, double **, double *);
 
 #endif

+ 8 - 2
imagery/i.pca/main.c

@@ -66,7 +66,12 @@ int main(int argc, char *argv[])
 
     /* Define options */
     opt_in = G_define_standard_option(G_OPT_R_INPUTS);
+    opt_in->description = _("Name of two or more input raster maps");
+
     opt_out = G_define_standard_option(G_OPT_R_OUTPUT);
+    opt_out->label = _("Base name for output raster maps");
+    opt_out->description =
+	_("A numerical suffix will be added for each component map");
 
     opt_scale = G_define_option();
     opt_scale->key = "rescale";
@@ -75,11 +80,12 @@ int main(int argc, char *argv[])
     opt_scale->required = NO;
     opt_scale->answer = "0,255";
     opt_scale->description =
-	_("Rescaling range output (For no rescaling use 0,0)");
+	_("Rescaling range for output maps (for no rescaling use 0,0)");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+
     /* determine number of bands passed in */
     for (bands = 0; opt_in->answers[bands] != NULL; bands++) ;
 
@@ -162,7 +168,7 @@ int main(int argc, char *argv[])
 	sprintf(outname, "%s.%d", opt_out->answer, i + 1);
 
 	/* write colors and history to file */
-	write_support(bands, outname, eigmat);
+	write_support(bands, outname, eigmat, eigval);
 
 	/* close output file */
 	G_unopen_cell(inp_fd[i]);

+ 23 - 15
imagery/i.pca/support.c

@@ -4,10 +4,10 @@
 
 
 /* function prototypes */
-static int write_history(int, char *, double **);
+static int write_history(int, char *, double **, double *);
 
 
-int write_support(int bands, char *outname, double **eigmat)
+int write_support(int bands, char *outname, double **eigmat, double *eigval)
 {
     const char *mapset = G_mapset();
     struct Colors colors;
@@ -26,44 +26,52 @@ int write_support(int bands, char *outname, double **eigmat)
     if (G_write_colors(outname, mapset, &colors) < 0)
 	G_message(_("Unable to write color table for raster map <%s>"), outname);
 
-    return write_history(bands, outname, eigmat);
+    return write_history(bands, outname, eigmat, eigval);
 }
 
 
-static int write_history(int bands, char *outname, double **eigmat)
+static int write_history(int bands, char *outname, double **eigmat, double *eigval)
 {
     int i, j;
-    static int to_std = 0;	/* write to stderr? */
+    static int first_map = TRUE;     /* write to stderr? */
     struct History hist;
+    double eigval_total = 0.0;
 
     G_short_history(outname, "raster", &hist);
-    sprintf(hist.edhist[0], "Eigen vectors:");
+    sprintf(hist.edhist[0], "Eigen values, (vectors), and [percent importance]:");
 
-    if (!to_std)
-	G_message(_("Eigen values:"));
+    if(first_map)
+	G_message(_("Eigen values, (vectors), and [percent importance]:"));
+
+    for (i = 0; i < bands; i++)
+	eigval_total += eigval[i];
 
     for (i = 0; i < bands; i++) {
-	char tmpeigen[80], tmpa[80];
+	char tmpeigen[256], tmpa[80];
 
-	sprintf(tmpeigen, "( ");
+	sprintf(tmpeigen, "PC%d %9.2f ( ", i+1, eigval[i]);
 	for (j = 0; j < bands; j++) {
-	    sprintf(tmpa, "%.2f ", eigmat[i][j]);
+	    sprintf(tmpa, "%5.2f ", eigmat[i][j]);
 	    strcat(tmpeigen, tmpa);
 	}
-	strcat(tmpeigen, ")");
+
+	strcat(tmpeigen, ") ");
+	
+	sprintf(tmpa, "[ %5.2f%% ]", eigval[i] * 100/eigval_total);
+	strcat(tmpeigen, tmpa);
 
 	sprintf(hist.edhist[i + 1], tmpeigen);
 
 	/* write eigen values to screen */
-	if (!to_std)
+	if(first_map)
 	    G_message("%s", tmpeigen);
     }
 
     hist.edlinecnt = i + 1;
     G_command_history(&hist);
 
-    /* only write to stderr the first time */
-    to_std = 1;
+    /* only write to stderr the first time (this fn runs for every output map) */
+    first_map = FALSE;
 
     return G_write_history(outname, &hist);
 }