Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRaster / src-test / org / gvsig / raster / dataset / TestStatisticMultiFile.java @ 30754

History | View | Annotate | Download (4.89 KB)

1
/*
2
 * Created on 19-jul-2006
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 */
25
package org.gvsig.raster.dataset;
26

    
27
import org.gvsig.raster.BaseTestCase;
28
import org.gvsig.raster.RasterLibrary;
29
import org.gvsig.raster.dataset.properties.DatasetStatistics;
30
/**
31
 * Prueba el calculo de estadisticas para un dataset con multiples ficheros.
32
 * Comprueba que los valores obtenidos en las estadisticas son correctos.
33
 *
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class TestStatisticMultiFile extends BaseTestCase {
37

    
38
        private String baseDir = "./test-images/";
39
        private String path1 = baseDir + "band1-30x28byte.tif";
40
        private String path2 = baseDir + "band2-30x28byte.tif";
41
        private String path3 = baseDir + "band3-30x28byte.tif";
42

    
43
        private RasterDataset f1 = null;
44
        private RasterDataset f2 = null;
45
        private RasterDataset f3 = null;
46

    
47
        static {
48
                RasterLibrary.wakeUp();
49
        }
50

    
51
        public void start() throws Exception {
52
                this.setUp();
53
                this.testStack();
54
        }
55

    
56
        protected void doSetUp() throws Exception {
57
                super.doSetUp();
58
                System.err.println("TestStatisticMultiFile running...");
59
                try {
60
                        deleteRMF(path1);
61
                        deleteRMF(path2);
62
                        deleteRMF(path3);
63
                        f1 = RasterDataset.open(null, path1);
64
                        f2 = RasterDataset.open(null, path2);
65
                        f3 = RasterDataset.open(null, path3);
66
                } catch (NotSupportedExtensionException e) {
67
                        e.printStackTrace();
68
                } catch (RasterDriverException e) {
69
                        e.printStackTrace();
70
                }
71
        }
72

    
73
        public void testStack() {
74
                MultiRasterDataset grmf = new MultiRasterDataset();
75
                try {
76
                        grmf.addDataset(new RasterDataset[]{f1});
77
                        grmf.addDataset(new RasterDataset[]{f2});
78
                        grmf.addDataset(new RasterDataset[]{f3});
79
                        try {
80
                                grmf.getStatistics().calcFullStatistics();
81
                        } catch (FileNotOpenException e) {
82
                                e.printStackTrace();
83
                        } catch (RasterDriverException e) {
84
                                e.printStackTrace();
85
                        } catch (InterruptedException e) {
86
                                e.printStackTrace();
87
                        }
88
//                        print(grmf);
89
                        dataTestB1(grmf.getStatistics());
90
                        dataTestB2(grmf.getStatistics());
91
                        dataTestB3(grmf.getStatistics());
92
                } catch (FileNotFoundInListException e) {
93
                        e.printStackTrace();
94
                }
95
        }
96

    
97
        private void dataTestB1(DatasetStatistics stats){
98
                assertEquals(new Double(stats.getMaxRGB()[0]), new Double(249.0));
99
                assertEquals(new Double(stats.getMinRGB()[0]), new Double(82.0));
100
                assertEquals(new Double(stats.getSecondMaxRGB()[0]), new Double(211.0));
101
                assertEquals(new Double(stats.getSecondMinRGB()[0]), new Double(83.0));
102
                assertEquals((int)stats.getMean()[0], 19);
103
                assertEquals((int)stats.getVariance()[0], 11599);
104
        }
105

    
106
        private void dataTestB2(DatasetStatistics stats){
107
                assertEquals(new Double(stats.getMaxRGB()[1]), new Double(234.0));
108
                assertEquals(new Double(stats.getMinRGB()[1]), new Double(49.0));
109
                assertEquals(new Double(stats.getSecondMaxRGB()[1]), new Double(216.0));
110
                assertEquals(new Double(stats.getSecondMinRGB()[1]), new Double(50.0));
111
                assertEquals((int)stats.getMean()[1], 51);
112
                assertEquals((int)stats.getVariance()[1], 7109);
113
        }
114

    
115
        private void dataTestB3(DatasetStatistics stats){
116
                assertEquals(new Double(stats.getMaxRGB()[2]), new Double(255.0));
117
                assertEquals(new Double(stats.getMinRGB()[2]), new Double(28.0));
118
                assertEquals(new Double(stats.getSecondMaxRGB()[2]), new Double(250.0));
119
                assertEquals(new Double(stats.getSecondMinRGB()[2]), new Double(34.0));
120
                assertEquals((int)stats.getMean()[2], -12);
121
                assertEquals((int)stats.getVariance()[2], 7991);
122
        }
123

    
124
        public void print(MultiRasterDataset grmf) {
125
                for (int iBand = 0; iBand < grmf.getStatistics().getBandCount(); iBand++) {
126
                        System.out.println("Band " + iBand);
127
                        System.out.println("...Max: " + grmf.getStatistics().getMax()[iBand]);
128
                        System.out.println("...Min: " + grmf.getStatistics().getMin()[iBand]);
129
                        System.out.println("...SecondMax: " + grmf.getStatistics().getSecondMax()[iBand]);
130
                        System.out.println("...SecondMin: " + grmf.getStatistics().getSecondMin()[iBand]);
131
                        System.out.println("...Mean: " + grmf.getStatistics().getMean()[iBand]);
132
                        System.out.println("...Variance: " + grmf.getStatistics().getVariance()[iBand]);
133
                }
134
        }
135
}