/[xulu]/trunk/src/appl/parallel/test/XuluGridTestCase.java
ViewVC logotype

Contents of /trunk/src/appl/parallel/test/XuluGridTestCase.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 114 - (show annotations)
Mon Jul 11 11:31:25 2011 UTC (13 years, 5 months ago) by mojays
File size: 7016 byte(s)
SCHMITZM library updated to current version (2.6-SNAPSHOT)
Added gt-xsd-filter.jar, gt-xsd-gml2.jar, picocontainer.jar and xsd.jar from Geotools 2.6.5
1 package appl.parallel.test;
2
3 import java.awt.Rectangle;
4 import java.io.BufferedOutputStream;
5 import java.io.File;
6 import java.io.FileOutputStream;
7
8 import junit.framework.Test;
9 import junit.framework.TestCase;
10 import junit.framework.TestSuite;
11 import appl.parallel.data.xulugridfile.XuluGridFile;
12 import appl.parallel.spmd.split.WritableGridPartition;
13 import appl.util.RasterUtil;
14 import de.appl.util.RasterMetaData;
15 import de.schmitzm.geotools.data.WritableGrid;
16 import de.schmitzm.geotools.data.WritableGridArray;
17 import de.schmitzm.geotools.data.WritableGridRaster;
18 import de.schmitzm.geotools.io.GeoExportUtil;
19 import de.schmitzm.geotools.io.GeoImportUtil;
20 import edu.bonn.xulu.plugin.io.grid.array.WritableGridArrayFactory_ArcInfoAsciiGrid;
21
22 /**
23 * Generated code for the test suite <b>XuluGridTestCase</b> located at
24 * <i>/Xulu-latest/javasrc/appl/test/XuluGridTestCase.testsuite</i>.
25 *
26 * Extensivly tests the XuluGridFile for errors
27 */
28 public class XuluGridTestCase extends TestCase {
29 XuluGridFile gridFile;
30
31 /**
32 * Constructor for XuluGridTestCase.
33 * @param name
34 */
35 public XuluGridTestCase(String name) {
36 super(name);
37 }
38
39 /**
40 * Returns the JUnit test suite that implements the <b>XuluGridTestCase</b>
41 * definition.
42 */
43 public static Test suite() {
44 TestSuite xuluGridTestCase = new TestSuite("XuluGridTestCase");
45 // xuluGridTestCase.setArbiter(DefaultTestArbiter.INSTANCE).setId(
46 // "D14CC6AE1994BD92F864B0C0A54011DB");
47 //
48 // xuluGridTestCase.addTest(new XuluGridTestCase("testReadingPartitialGrid")
49 // .setId("D14CC6AE1994BD92132B3E60A54111DB").setTestInvocationId(
50 // "D14CC6AE1994BD9269E4C820A54111DB"));
51 //
52 // xuluGridTestCase.addTest(new XuluGridTestCase("testMartin").setId(
53 // "D14CC6AE1994BD92FC1EA54AA62111DB").setTestInvocationId(
54 // "D14CC6AE1994BD9262B92000A62211DB"));
55 return xuluGridTestCase;
56 }
57
58 /**
59 * @see junit.framework.TestCase#setUp()
60 */
61 protected void setUp() throws Exception {
62 }
63
64 /**
65 * @see junit.framework.TestCase#tearDown()
66 */
67 protected void tearDown() throws Exception {
68 if (gridFile!=null)
69 gridFile.close();
70 }
71
72 /**
73 * testReadingPartitial Grid
74 * @throws Exception
75 */
76 public void testReadingPartitialGrid()
77 throws Exception
78 {
79
80 //base file: all assertions are checked against this grid
81 WritableGridRaster baseGrid = GeoImportUtil.readGridRasterFromArcInfoASCII(new File("../Xulu-Data/minigrid.arc"));
82 printSmall(baseGrid);
83 GeoExportUtil.writeGridRasterToArcInfoASCII(baseGrid, new File("BaseGridExport_miniGrid_export1"));
84
85 // write a XuluGridFile / check it against baseGrid
86 File file = new File("XuluGridFile_miniGrid.xgrid");
87 XuluGridFile.writeToXuluGridFile(baseGrid,file);
88 // fill the grid2 with any Data
89 WritableGrid grid2 = GeoImportUtil.readGridRasterFromArcInfoASCII(new File("../Xulu-Data/SimpleGrid.arc"));
90 assertFalse(RasterUtil.checkEqual(baseGrid,grid2,true));
91 XuluGridFile.readIntoGridFromXuluGridFile(grid2, file);
92 assertTrue(RasterUtil.checkEqual(baseGrid,grid2,true));
93
94 //export und reimport an check it again (this caused some hard to trace errors in the past, even if it should not.)
95 GeoExportUtil.writeGridRasterToArcInfoASCII((WritableGridRaster)grid2, new File("BaseGridExport_miniGrid_export2"));
96 grid2 = GeoImportUtil.readGridRasterFromArcInfoASCII(new File("BaseGridExport_miniGrid_export2"));
97 assertTrue(RasterUtil.checkEqual(baseGrid,grid2,true));
98
99 //initialize a new XuluGrid
100 gridFile = new XuluGridFile(new File("XuluGridFile_miniGrid.xgrid"),"r");
101 RasterMetaData meta = gridFile.getMetaData();
102 //get the whole gridFile using the partition method and check it
103 WritableGrid wholeGrid = gridFile.getPartitialGrid2D(new Rectangle(0, 0, meta.getWidth(), meta.getHeight()));
104 assertTrue(RasterUtil.checkEqual(baseGrid,wholeGrid,true));
105 assertTrue(RasterUtil.checkEqual(grid2,wholeGrid,true));
106 //write all data from wholeGrid into grid2, then export grid2
107 for (int y = meta.getMinY(); y < meta.getHeight()- meta.getMinY(); y++)
108 for (int x = meta.getMinX(); x < meta.getWidth() - meta.getMinY(); x++)
109 grid2.setRasterSample(wholeGrid.getRasterSample(x,y),x,y);
110 GeoExportUtil.writeGridRasterToArcInfoASCII(baseGrid, new File("XuluGrid2FromWholeGrid_test"));
111
112
113 //new WritableGridArrayFactory_ArcInfoAsciiGrid().exportObject(wholeGrid, new BufferedOutputStream(new FileOutputStream("XuluGridTest_ARCINFO2")));
114
115 // for (y = 1; y < metadata.getheight(); y++)
116 // for (x = 1; x < metadata.getwidth(); x++) {
117 //get left half of the gridFile
118 WritableGrid leftHalf = gridFile.getPartitialGrid2D(new Rectangle(0, 0, (meta.getWidth()/2), meta.getHeight()));
119 new WritableGridArrayFactory_ArcInfoAsciiGrid().exportObject(leftHalf, new BufferedOutputStream(new FileOutputStream("LeftHalf_XULUGRID")));
120
121 //########################### no gridfile test ###############################
122 XuluGridFile gridfile = new XuluGridFile(new File("XuluGridFile_miniGrid.xgrid"),"rw");
123 WritableGridPartition partition = gridfile.getPartitialGrid2D(new Rectangle(0,0,5,5));
124 printSmall(partition);
125 partition = gridfile.getPartitialGrid2D(new Rectangle(0,0,4,4));
126 printSmall(partition);
127 partition = gridfile.getPartitialGrid2D(new Rectangle(1,1,8,8));
128 printSmall(partition);
129 partition = gridfile.getPartitialGrid2D(new Rectangle(5,5,5,5));
130 printSmall(partition);
131 partition = gridfile.getPartitialGrid2D(new Rectangle(1,1,2,2));
132 printSmall(partition);
133
134 }
135 /**
136 * prints only small grids
137 *
138 * @param grid
139 */
140 public void printSmall(WritableGrid grid){
141 if(grid.getWidth()<20 && grid.getHeight()<20)
142 RasterUtil.printGrid(grid,5,1,"output");
143 }
144
145 public void testMartin()
146 throws Exception
147 {
148 WritableGridRaster baseGrid = GeoImportUtil.readGridRasterFromArcInfoASCII(new File("../Xulu-Data/standard_clue_data/CLUE-Datensatz1/sc1gr0.23"));
149 WritableGridArray testGrid = new WritableGridArray.Float(baseGrid.getMinX(),baseGrid.getMinY(),baseGrid.getWidth(),baseGrid.getHeight(),baseGrid.getX(),baseGrid.getY(),baseGrid.getRealWidth(),baseGrid.getRealHeight(),null,null);
150 for (int y = baseGrid.getMinY(); y < baseGrid.getHeight()- baseGrid.getMinY(); y++)
151 for (int x = baseGrid.getMinX(); x < baseGrid.getWidth() - baseGrid.getMinY(); x++)
152 testGrid.setRasterSample(baseGrid.getRasterSample(x,y),x,y);
153 GeoExportUtil.writeGridRasterToArcInfoASCII(baseGrid, new File("Test_baseGrid"));
154 new WritableGridArrayFactory_ArcInfoAsciiGrid().exportObject(testGrid,new FileOutputStream("Test_testGrid2"));
155 }
156 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26