Statistics
| Revision:

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

History | View | Annotate | Download (4.95 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.RasterLibrary;
28
import org.gvsig.raster.dataset.FileFoundInListException;
29
import org.gvsig.raster.dataset.FileNotOpenException;
30
import org.gvsig.raster.dataset.NotSupportedExtensionException;
31
import org.gvsig.raster.dataset.RasterDataset;
32
import org.gvsig.raster.dataset.RasterDriverException;
33
import org.gvsig.raster.dataset.RasterMultiDataset;
34
import org.gvsig.raster.dataset.properties.DatasetStatistics;
35

    
36
import junit.framework.TestCase;
37

    
38
/**
39
 * Prueba el calculo de estadisticas para un dataset con multiples ficheros.
40
 * Comprueba que los valores obtenidos en las estadisticas son correctos.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestStatisticMultiFile extends TestCase {
46

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

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