Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / TestStatisticMultiFile.java @ 11396

History | View | Annotate | Download (4.63 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 junit.framework.TestCase;
28

    
29
import org.gvsig.raster.RasterLibrary;
30
import org.gvsig.raster.dataset.properties.DatasetStatistics;
31

    
32
/**
33
 * Prueba el calculo de estadisticas para un dataset con multiples ficheros.
34
 * Comprueba que los valores obtenidos en las estadisticas son correctos.
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 *
38
 */
39
public class TestStatisticMultiFile extends TestCase {
40

    
41
        private String baseDir = "./test-images/";
42
        private String path1 = baseDir + "band1-30x28byte.tif";
43
        private String path2 = baseDir + "band2-30x28byte.tif";
44
        private String path3 = baseDir + "band3-30x28byte.tif";
45
        
46
        private RasterDataset f1 = null;
47
        private RasterDataset f2 = null;
48
        private RasterDataset f3 = null;
49
        
50
        static {
51
                RasterLibrary.wakeUp();
52
        }
53
        
54
        public void start() {
55
                this.setUp();
56
                this.testStack();
57
        }
58
        
59
        public void setUp() {
60
                System.err.println("TestStatisticMultiFile running...");
61
                try {
62
                        f1 = RasterDataset.open(null, path1);
63
                        f2 = RasterDataset.open(null, path2);
64
                        f3 = RasterDataset.open(null, path3);
65
                } catch (NotSupportedExtensionException e) {
66
                        e.printStackTrace();
67
                } catch (RasterDriverException e) {
68
                        e.printStackTrace();
69
                }
70
        }
71
        
72
        public void testStack() {
73
                RasterMultiDataset grmf = new RasterMultiDataset("prueba");
74
                try {
75
                        grmf.addDataset(f1);
76
                        grmf.addDataset(f2);
77
                        grmf.addDataset(f3);
78
                        try {
79
                                grmf.getStatistics().calcFullStatistics();
80
                        } catch (FileNotOpenException e) {
81
                                e.printStackTrace();
82
                        } catch (RasterDriverException e) {
83
                                e.printStackTrace();
84
                        }
85
                        dataTestB1(grmf.getStatistics());
86
                        dataTestB2(grmf.getStatistics());
87
                        dataTestB3(grmf.getStatistics());
88
                        //print(grmf);
89
                } catch (FileNotFoundInListException e) {
90
                        e.printStackTrace();
91
                }
92
        }
93

    
94
        private void dataTestB1(DatasetStatistics stats){
95
                assertEquals(new Double(stats.getMax()[0]), new Double(249.0));
96
                assertEquals(new Double(stats.getMin()[0]), new Double(82.0));
97
                assertEquals(new Double(stats.getSecondMax()[0]), new Double(200.0));
98
                assertEquals(new Double(stats.getSecondMin()[0]), new Double(83.0));
99
                assertEquals((int)stats.getMean()[0], 119);
100
                assertEquals((int)stats.getVariance()[0], 583);
101
        }
102
        
103
        private void dataTestB2(DatasetStatistics stats){
104
                assertEquals(new Double(stats.getMax()[1]), new Double(234.0));
105
                assertEquals(new Double(stats.getMin()[1]), new Double(49.0));
106
                assertEquals(new Double(stats.getSecondMax()[1]), new Double(191.0));
107
                assertEquals(new Double(stats.getSecondMin()[1]), new Double(50.0));
108
                assertEquals((int)stats.getMean()[1], 102);
109
                assertEquals((int)stats.getVariance()[1], 1107);
110
        }
111
        
112
        private void dataTestB3(DatasetStatistics stats){
113
                assertEquals(new Double(stats.getMax()[2]), new Double(255.0));
114
                assertEquals(new Double(stats.getMin()[2]), new Double(28.0));
115
                assertEquals(new Double(stats.getSecondMax()[2]), new Double(231.0));
116
                assertEquals(new Double(stats.getSecondMin()[2]), new Double(34.0));
117
                assertEquals((int)stats.getMean()[2], 115);
118
                assertEquals((int)stats.getVariance()[2], 2833);
119
        }
120
        
121
        private void print(RasterMultiDataset grmf){
122
                for(int iBand = 0; iBand < grmf.getStatistics().getBandCount(); iBand ++){
123
                        System.out.println("Band " + iBand);
124
                        System.out.println("...Max: " + grmf.getStatistics().getMax()[iBand]);
125
                        System.out.println("...Min: " + grmf.getStatistics().getMin()[iBand]);
126
                        System.out.println("...SecondMax: " + grmf.getStatistics().getSecondMax()[iBand]);
127
                        System.out.println("...SecondMin: " + grmf.getStatistics().getSecondMin()[iBand]);
128
                        System.out.println("...Mean: " + grmf.getStatistics().getMean()[iBand]);
129
                        System.out.println("...Variance: " + grmf.getStatistics().getVariance()[iBand]);
130
                }
131
        }
132
}