Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / driver / TestStatistics.java @ 11067

History | View | Annotate | Download (6.53 KB)

1
/*
2
 * Created on 9-ago-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.driver;
26

    
27
import junit.framework.TestCase;
28

    
29
import org.gvsig.raster.RasterLibrary;
30
import org.gvsig.raster.dataset.FileNotOpenException;
31
import org.gvsig.raster.dataset.NotSupportedExtensionException;
32
import org.gvsig.raster.dataset.RasterDataset;
33
import org.gvsig.raster.dataset.RasterDriverException;
34
import org.gvsig.raster.dataset.properties.DatasetStatistics;
35

    
36
/**
37
 * Este test prueba el calculo de estadisticas de un dataset. 
38
 * Comprueba que los valores obtenidos en las estadisticas son correctos.
39
 * 
40
 * 
41
 * Algunos costes del calculo de estadistica en el raster completo
42
 * 
43
 * Ordenador: AMD Athlon(tm) XP 1800+ 1540MHz, 256KB Cach?, 500M RAM
44
 *         Coste 1:
45
 *                 Raster: 17910x16062, 275M (GTiff), 1 Banda byte
46
 *                 Tiempo: 74.295 segs (sgtes igual)
47
 *         Coste 2:
48
 *                 Raster: 8955x8031, 69M (GTiff), 1 Banda byte
49
 *          Tiempo: 18.905 segs (sgtes 3.362s)
50
 *  Coste 3:
51
 *                 Raster: 812x586, 2.8M (GTiff), 3 Banda short
52
 *          Tiempo: 0.925 segs (sgtes 0.152s)
53
 *  Coste 4:
54
 *                 Raster: 870x870, 210K (Jpeg), 3 Banda byte
55
 *          Tiempo: 0.318 segs (sgtes 0.255s)
56
 * 
57
 * @author Nacho Brodin (nachobrodin@gmail.com)
58
 *
59
 */
60
public class TestStatistics extends TestCase{
61

    
62
        private String baseDir = "./test-images/";
63
        private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
64
        private String path2 = baseDir + "wcs16bits.tif";
65

    
66
        private RasterDataset f1 = null;
67
        private RasterDataset f2 = null;
68
        private DatasetStatistics stats1 = null;
69
        private DatasetStatistics stats2 = null;
70
        
71
        static{
72
                RasterLibrary.wakeUp();
73
        }
74
        
75
        public void start(){
76
                this.setUp();
77
                this.testStack();
78
        }
79
        
80
        public void setUp() {
81
                System.err.println("TestStatistics running...");
82
                try {
83
                        f1 = RasterDataset.openFile(null, path1);
84
                        f2 = RasterDataset.openFile(null, path2);
85
                } catch (NotSupportedExtensionException e) {
86
                        e.printStackTrace();
87
                } catch (RasterDriverException e) {
88
                        e.printStackTrace();
89
                }
90
                stats1 = f1.getStatistics();
91
                stats2 = f2.getStatistics();
92
        }
93
        
94
        public void testStack(){
95
                try {
96
                        stats1.calcFullStatistics();
97
                } catch (FileNotOpenException e) {
98
                        e.printStackTrace();
99
                } catch (RasterDriverException e) {
100
                        e.printStackTrace();
101
                }
102
                dataTestB1(stats1);
103
                dataTestB2(stats1);
104
                dataTestB3(stats1);
105
                //print(stats1);
106
                try {
107
                        stats2.calcFullStatistics();
108
                } catch (FileNotOpenException e) {
109
                        e.printStackTrace();
110
                } catch (RasterDriverException e) {
111
                        e.printStackTrace();
112
                }
113
                dataTestB1_2(stats2);
114
                dataTestB2_2(stats2);
115
                dataTestB3_2(stats2);
116
                //print(stats2);
117
        }
118
        
119
        private void dataTestB1(DatasetStatistics stats){
120
                assertEquals(new Double(stats.getMax()[0]), new Double(255.0));
121
                assertEquals(new Double(stats.getMin()[0]), new Double(0.0));
122
                assertEquals(new Double(stats.getSecondMax()[0]), new Double(253.0));
123
                assertEquals(new Double(stats.getSecondMin()[0]), new Double(7.0));
124
                assertEquals((int)stats.getMean()[0], 109);
125
                assertEquals((int)stats.getVariance()[0], 6125);
126
        }
127
        
128
        private void dataTestB2(DatasetStatistics stats){
129
                assertEquals(new Double(stats.getMax()[1]), new Double(255.0));
130
                assertEquals(new Double(stats.getMin()[1]), new Double(0.0));
131
                assertEquals(new Double(stats.getSecondMax()[1]), new Double(254.0));
132
                assertEquals(new Double(stats.getSecondMin()[1]), new Double(1.0));
133
                assertEquals((int)stats.getMean()[1], 111);
134
                assertEquals((int)stats.getVariance()[1], 5722);
135
        }
136
        
137
        private void dataTestB3(DatasetStatistics stats){
138
                assertEquals(new Double(stats.getMax()[2]), new Double(255.0));
139
                assertEquals(new Double(stats.getMin()[2]), new Double(0.0));
140
                assertEquals(new Double(stats.getSecondMax()[2]), new Double(253.0));
141
                assertEquals(new Double(stats.getSecondMin()[2]), new Double(5.0));
142
                assertEquals((int)stats.getMean()[2], 98);
143
                assertEquals((int)stats.getVariance()[2], 5495);
144
        }
145
        
146
        private void dataTestB1_2(DatasetStatistics stats){
147
                assertEquals(new Double(stats.getMax()[0]), new Double(1269.0));
148
                assertEquals(new Double(stats.getMin()[0]), new Double(0.0));
149
                assertEquals(new Double(stats.getSecondMax()[0]), new Double(1233.0));
150
                assertEquals(new Double(stats.getSecondMin()[0]), new Double(27.0));
151
                assertEquals((int)stats.getMean()[0], 71);
152
                assertEquals((int)stats.getVariance()[0], 22678);
153
        }
154
        
155
        private void dataTestB2_2(DatasetStatistics stats){
156
                assertEquals(new Double(stats.getMax()[1]), new Double(1525.0));
157
                assertEquals(new Double(stats.getMin()[1]), new Double(0.0));
158
                assertEquals(new Double(stats.getSecondMax()[1]), new Double(1498.0));
159
                assertEquals(new Double(stats.getSecondMin()[1]), new Double(35.0));
160
                assertEquals((int)stats.getMean()[1], 104);
161
                assertEquals((int)stats.getVariance()[1], 37907);
162
        }
163
        
164
        private void dataTestB3_2(DatasetStatistics stats){
165
                assertEquals(new Double(stats.getMax()[2]), new Double(888.0));
166
                assertEquals(new Double(stats.getMin()[2]), new Double(0.0));
167
                assertEquals(new Double(stats.getSecondMax()[2]), new Double(884.0));
168
                assertEquals(new Double(stats.getSecondMin()[2]), new Double(24.0));
169
                assertEquals((int)stats.getMean()[2], 75);
170
                assertEquals((int)stats.getVariance()[2], 17437);
171
        }
172
        
173
        private void print(DatasetStatistics stats){
174
                for(int iBand = 0; iBand < f1.getBandCount(); iBand ++){
175
                        System.out.println("Band " + iBand);
176
                        System.out.println("...Max: " + stats.getMax()[iBand]);
177
                        System.out.println("...Min: " + stats.getMin()[iBand]);
178
                        System.out.println("...SecondMax: " + stats.getSecondMax()[iBand]);
179
                        System.out.println("...SecondMin: " + stats.getSecondMin()[iBand]);
180
                        System.out.println("...Mean: " + stats.getMean()[iBand]);
181
                        System.out.println("...Variance: " + stats.getVariance()[iBand]);
182
                }
183
        }
184

    
185
}