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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26