[GRASS-SVN] r53388 - grass/trunk/imagery/i.pca
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Oct 13 12:07:13 PDT 2012
Author: mmetz
Date: 2012-10-13 12:07:12 -0700 (Sat, 13 Oct 2012)
New Revision: 53388
Modified:
grass/trunk/imagery/i.pca/i.pca.html
grass/trunk/imagery/i.pca/local_proto.h
grass/trunk/imagery/i.pca/main.c
grass/trunk/imagery/i.pca/support.c
Log:
i.pca: change output back to DCELL for no rescaling, update manual, copy color table from input band for filtering
Modified: grass/trunk/imagery/i.pca/i.pca.html
===================================================================
--- grass/trunk/imagery/i.pca/i.pca.html 2012-10-13 12:50:39 UTC (rev 53387)
+++ grass/trunk/imagery/i.pca/i.pca.html 2012-10-13 19:07:12 UTC (rev 53388)
@@ -12,41 +12,23 @@
option is used, the output files are rescaled to fit the
min,max range.
-<h2>OPTIONS</h2>
+<p>
+If the output is not rescaled (<em>rescale=0,0</em>, the output raster
+maps will be of type DCELL, otherwise the output raster maps will be of
+type CELL.
-<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.
-
-<dt><b>-n</b> <em>normalize input raster maps</em>
-<dd>By default, the values of the input raster maps are centered for each
+<p>By default, the values of the input raster maps are centered for each
map separately with <em>x - mean</em>. With <em>-n</em>, the input raster
maps are normalized for each map separately with <em>(x - mean) / stddev</em>.
Normalizing is highly recommended when the input raster maps have different
units, e.g. represent different environmental parameters.
-<dt><b>-f</b> <em>output will be filtered input bands</em>
-<dd>This option, together with the <em>percent</em> option, can be used
-to remove noise from input bands. Input bands will be recalculated from
-a subset of the principal components. The subset is selected by using
-only the most important (highest eigenvalue) principal components which
-explain together <em>percent</em> percent variance observed in the
-input bands.
-</dl>
+<p>The <em>-f</em> flag, together with the <em>percent</em> option, can
+be used to remove noise from input bands. Input bands will be
+recalculated from a subset of the principal components (inverse PCA).
+The subset is selected by using only the most important (highest
+eigenvalue) principal components which explain together <em>percent</em>
+percent variance observed in the input bands.
<h2>NOTES</h2>
@@ -60,16 +42,20 @@
<h2>EXAMPLE</h2>
-Using the Spearfish Imagery sample dataset
+Using Landsat imagery in the North Carolina sample dataset:
<div class="code"><pre>
-i.pca in=spot.ms.1,spot.ms.2,spot.ms.3 out=spot_pca
+i.pca in=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70 \
+ out=lsat7_2002_pca
-r.info -h spot_pca.1
+r.info -h lsat7_2002_pca.1
Eigen values, (vectors), and [percent importance]:
- PC1 1159.75 ( 0.6237, 0.6503, 0.4337) [88.38%]
- PC2 146.50 ( 0.2403, 0.3685,-0.8981) [11.16%]
- PC3 5.97 (-0.7438, 0.6643, 0.0735) [ 0.45%]
+ PC1 4334.35 ( 0.2824, 0.3342, 0.5092,-0.0087, 0.5264, 0.5217) [83.04%]
+ PC2 588.31 ( 0.2541, 0.1885, 0.2923,-0.7428,-0.5110,-0.0403) [11.27%]
+ PC3 239.22 ( 0.3801, 0.3819, 0.2681, 0.6238,-0.4000,-0.2980) [ 4.58%]
+ PC4 32.85 ( 0.1752,-0.0191,-0.4053, 0.1593,-0.4435, 0.7632) [ 0.63%]
+ PC5 20.73 (-0.6170,-0.2514, 0.6059, 0.1734,-0.3235, 0.2330) [ 0.40%]
+ PC6 4.08 (-0.5475, 0.8021,-0.2282,-0.0607,-0.0208, 0.0252) [ 0.08%]
</pre></div>
Modified: grass/trunk/imagery/i.pca/local_proto.h
===================================================================
--- grass/trunk/imagery/i.pca/local_proto.h 2012-10-13 12:50:39 UTC (rev 53387)
+++ grass/trunk/imagery/i.pca/local_proto.h 2012-10-13 19:07:12 UTC (rev 53388)
@@ -2,6 +2,6 @@
#define __LOCAL_PROTO_H__
/* support.c */
-void write_support(int, char *, double **, double *);
+void write_support(int, char *, char *, double **, double *);
#endif
Modified: grass/trunk/imagery/i.pca/main.c
===================================================================
--- grass/trunk/imagery/i.pca/main.c 2012-10-13 12:50:39 UTC (rev 53387)
+++ grass/trunk/imagery/i.pca/main.c 2012-10-13 19:07:12 UTC (rev 53388)
@@ -171,7 +171,7 @@
if (!calc_mu_cov(inp_fd, covar, mu, stddev, bands))
G_fatal_error(_("No non-null values"));
- G_math_d_copy(covar[0], eigmat[0], bands*bands);
+ G_math_d_copy(covar[0], eigmat[0], bands * bands);
G_debug(1, "Calculating eigenvalues and eigenvectors...");
G_math_eigen(eigmat, eigval, bands);
@@ -217,15 +217,18 @@
/* write colors and history to output */
for (i = 0; i < bands; i++) {
- char outname[80];
+ char outname[GNAME_MAX];
+ /* close input files */
+ Rast_unopen(inp_fd[i]);
+
sprintf(outname, "%s.%d", opt_out->answer, i + 1);
/* write colors and history to file */
- write_support(bands, outname, eigmat, eigval);
-
- /* close input files */
- Rast_unopen(inp_fd[i]);
+ if (flag_filt->answer)
+ write_support(bands, opt_in->answers[i], outname, eigmat, eigval);
+ else
+ write_support(bands, NULL, outname, eigmat, eigval);
}
/* free memory */
@@ -395,7 +398,7 @@
int rows = Rast_window_rows();
int cols = Rast_window_cols();
/* why CELL_TYPE when scaling output ? */
- int outmap_type = (scale) ? CELL_TYPE : FCELL_TYPE;
+ int outmap_type = (scale) ? CELL_TYPE : DCELL_TYPE;
int outcell_mapsiz = Rast_cell_size(outmap_type);
int *out_fd = (int *) G_malloc(bands * sizeof(int));
DCELL **inbuf = (DCELL **) G_malloc(bands * sizeof(DCELL *));
@@ -500,7 +503,6 @@
}
}
-
/* the cell entry is complete */
if (scale && (pass == 1)) {
if (first)
Modified: grass/trunk/imagery/i.pca/support.c
===================================================================
--- grass/trunk/imagery/i.pca/support.c 2012-10-13 12:50:39 UTC (rev 53387)
+++ grass/trunk/imagery/i.pca/support.c 2012-10-13 19:07:12 UTC (rev 53388)
@@ -8,19 +8,25 @@
static void write_history(int, char *, double **, double *);
-void write_support(int bands, char *outname, double **eigmat, double *eigval)
+void write_support(int bands, char *inname, char *outname, double **eigmat, double *eigval)
{
const char *mapset = G_mapset();
struct Colors colors;
struct FPRange range;
DCELL min, max;
- /* make grey scale color table */
- Rast_read_fp_range(outname, mapset, &range);
- Rast_get_fp_range_min_max(&range, &min, &max);
+ if (inname) {
+ Rast_read_colors(inname, "", &colors);
+ }
+ else {
+ /* make grey scale color table */
+ Rast_read_fp_range(outname, mapset, &range);
+ Rast_get_fp_range_min_max(&range, &min, &max);
- Rast_make_grey_scale_fp_colors(&colors, min, max);
+ Rast_make_grey_scale_fp_colors(&colors, min, max);
+ }
+
if (Rast_map_is_fp(outname, mapset))
Rast_mark_colors_as_fp(&colors);
@@ -66,14 +72,13 @@
Rast_append_history(&hist, tmpeigen);
/* write eigen values to screen */
- if(first_map)
+ if (first_map)
fprintf(stdout, "%s\n", tmpeigen);
}
- Rast_command_history(&hist);
-
/* only write to stderr the first time (this fn runs for every output map) */
first_map = FALSE;
+ Rast_command_history(&hist);
Rast_write_history(outname, &hist);
}
More information about the grass-commit
mailing list