package phd; /** * This file is distributed as part of the uk.ac.leeds.ccg.grids library * This library is a resource for manipulating spatial data stored as grids. * Copyright (C) 2002 Andy Turner * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import uk.ac.leeds.ccg.grids.*; import java.io.File; import java.util.Vector; public class ProcessorRuns { public ProcessorRuns(){} long time; AbstractGrid2DSquareCellDoubleFactory gridFactory; public static void main(String[] args) throws java.io.IOException { ProcessorRuns p = new ProcessorRuns(); p.run(); } public void run() { System.out.println( "Initialising ..." ); time = System.currentTimeMillis(); // Method to run //regionStatistics1(); regionStatistics2(); //compare(); //globalCompare(); //geometricDensity(); System.out.println( "Processing complete in " + Utilities.time( System.currentTimeMillis() - time ) ); } public void geometricDensity() { //String filename0 = "test_160x230_1" ; //String filename0 = "casnull" ; //String filename0 = "road" ; String filename0 = "rcw" ; //String dataDirectory0 = "d:/andyt/data/testdata/gridascii/"; String dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/"; File inputGridFile = new File( dataDirectory0 + filename0 + ".asc" ); Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFileFactory( dataDirectory0 ); AbstractGrid2DSquareCellDouble inputGrid = ff.createGrid2DSquareCellDouble( inputGridFile ); System.out.println( "inputGrid" ); System.out.println( inputGrid.toString() ); //inputGrid.setToNoDataValue( 0.0d, 0.0d ); //System.out.println(inputGrid.toString()); int nrows = inputGrid.getNrows(); int ncols = inputGrid.getNcols(); System.out.println( "Processing..." ); AbstractGrid2DSquareCellDouble[] geometricDensity = Grid2DSquareCellDoubleProcessor.geometricDensity( inputGrid, 5000.0d, ff, 537 ); //AbstractGrid2DSquareCellDouble[] geometricDensity = Grid2DSquareCellDoubleProcessor.geometricDensity( inputGrid, inputGrid.getCellsize() * 10.0d, ff, 50 ); //AbstractGrid2DSquareCellDouble geometricDensityCrossScale = ff.createGrid2DSquareCellDouble( inputGrid ); //double weight = 1.0d; //for ( int i = 0; i < geometricDensity.length; i ++ ) { // geometricDensityCrossScale.addToGrid( geometricDensity[ i ], weight ); //} System.out.println( "Exchanging..." ); for ( int i = 0; i < geometricDensity.length; i ++ ) { //Grid2DSquareCellDoubleExchange.toImage( geometricDensity[ i ], new File( dataDirectory0 + filename0 + "g" + i + ".png" ), "PNG" ); Grid2DSquareCellDoubleExchange.toAsciiFile( geometricDensity[ i ], new File( dataDirectory0 + filename0 + "g" + i + ".asc" ) ); } //Grid2DSquareCellDoubleExchange.toImage( geometricDenityCrossScale, new File( dataDirectory0 + filename0 + "g.png" ), "PNG" ); //Grid2DSquareCellDoubleExchange.toAsciiFile( geometricDensityCrossScale, new File( dataDirectory0 + filename0 + "g.asc" ) ); System.out.println( "Finalising..." ); inputGrid.clear(); for ( int i = 0; i < geometricDensity.length; i ++ ) { geometricDensity[ i ].clear(); } //geometricDensityCrossScale.clear(); } public void regionStatistics1() { // Set grid factory Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9296/"; //String dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/temp/road/"; //String inFileName0 = "roadz"; String inFileName0 = "acc9296z"; File inFile0 = new File( dataDirectory0, inFileName0 + ".asc" ); AbstractGrid2DSquareCellDouble grid0 = jf.createGrid2DSquareCellDouble( inFile0 ); double distance = grid0.getCellsize() * 20.0d; double weightIntersect = 1.0d; double weightFactor = 1.0d; Vector statistics = new Vector(); statistics.add( new String( "WSum" ) ); statistics.add( new String( "WMean" ) ); Vector regionStatistics = Grid2DSquareCellDoubleProcessor.regionStatistics( grid0, statistics, distance, weightIntersect, weightFactor, jf ); AbstractGrid2DSquareCellDouble result = null; File outFile0 = null; new File( dataDirectory0, inFileName0 + ".asc" ); for ( int k = 0; k < regionStatistics.size(); k ++ ) { result = ( ( AbstractGrid2DSquareCellDouble ) regionStatistics.elementAt( k ) ); System.out.println( result.getName() ); System.out.println( result.toString() ); outFile0 = new File( new String( dataDirectory0 + inFileName0 + "_" + result.getName() + "_" + distance + "_" + weightIntersect + "_" + weightFactor + ".asc" ) ); System.out.println( "Exchanging to " + outFile0 + " ..."); Grid2DSquareCellDoubleExchange.toAsciiFile( result, outFile0 ); result.clear(); } } public void regionStatistics2() { // Set Parameters // Set grid factory Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String dataDirectory0 = null; String inFileName0 = null; // Set kernel paramters double weightFactor = 1.0d; double weightIntersect = 1.0d; double distance; // Set statistics Vector statistics = new Vector(); //statistics.add( new String( "Sum" ) ); statistics.add( new String( "WSum" ) ); statistics.add( new String( "WMean" ) ); statistics.add( new String( "WProp" ) ); statistics.add( new String( "WVar" ) ); //statistics.add( new String( "WeightedFirstOrder" ) ); //statistics.add( new String( "WeightedSecondOrder" ) ); //statistics.add( new String( "FirstOrder" ) ); //statistics.add( new String( "SecondOrder" ) ); String allstatistics = "("; for ( int i = 0; i < statistics.size(); i ++ ) { allstatistics += " " + ( String ) statistics.elementAt( i ); } allstatistics += " )"; // Process for ( int j = 11; j < 12; j ++ ) { dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/"; if ( j == 0 ) inFileName0 = "acc92"; if ( j == 1 ) inFileName0 = "acc93"; if ( j == 2 ) inFileName0 = "acc94"; if ( j == 3 ) inFileName0 = "acc95"; if ( j == 4 ) inFileName0 = "acc96"; if ( j == 5 ) inFileName0 = "acc97"; if ( j == 6 ) inFileName0 = "acc98"; if ( j == 7 ) inFileName0 = "acc99"; if ( j == 8 ) inFileName0 = "acc00"; if ( j == 9 ) inFileName0 = "acc01"; if ( j == 10 ) inFileName0 = "acc9201"; if ( j == 11 ) inFileName0 = "acc9296"; if ( j == 12 ) inFileName0 = "acc9701"; if ( j == 13 ) { inFileName0 = "road"; dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/temp/road/"; } if ( j == 14 ) { inFileName0 = "a"; dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/temp/diff/9296_9701/"; } String inFileName00 = null; File inFile0 = null; File outFile0 = null; AbstractGrid2DSquareCellDouble grid0 = null ; Vector regionStatistics = null; for ( int i = 0; i < 3; i ++ ) { // Prepare if ( i == 0 ) inFileName00 = inFileName0; if ( i == 1 ) inFileName00 = inFileName0 + "n"; if ( i == 2 ) inFileName00 = inFileName0 + "z"; //inFile0 = new File( dataDirectory0, inFileName00 + ".asc" ); inFile0 = new File( dataDirectory0 + inFileName0 + "/", inFileName00 + ".asc" ); grid0 = jf.createGrid2DSquareCellDouble( inFile0 ); distance = grid0.getCellsize() * 20.0d; System.out.println( "Calculating " + allstatistics + " Statistics for " + inFileName00 + ".asc ..." ); // Process regionStatistics = Grid2DSquareCellDoubleProcessor.regionStatistics( grid0, statistics, distance, weightIntersect, weightFactor, jf ); System.out.println( "Number of GWS returned " + regionStatistics.size() ); // Exchange AbstractGrid2DSquareCellDouble grid = null; for ( int k = 0; k < regionStatistics.size(); k ++ ) { grid = ( ( AbstractGrid2DSquareCellDouble ) regionStatistics.elementAt( k ) ); System.out.println( grid.getName() ); System.out.println( grid.toString() ); outFile0 = new File( new String( dataDirectory0 + inFileName00 + "_" + grid.getName() + "_" + distance + "_" + weightIntersect + "_" + weightFactor + ".asc" ) ); //outFile0 = new File( new String( dataDirectory0 + inFileName0 + "/" + inFileName00 + "_" + grid.getName() + "_" + distance + "_" + weightIntersect + "_" + weightFactor + ".asc" ) ); //outFile0 = new File( new String( dataDirectory0 + inFileName0 + "/" + inFileName00 + "_zscore_" + distance + "_" + weightIntersect + "_" + weightFactor + ".asc" ) ); System.out.println( "Exchanging to " + outFile0 + " ..."); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, outFile0 ); //outFile0 = new File( new String( dataDirectory0 + inFileName0 + "/" + inFileName00 + "_" + statistics[ k ] + "_" + distance + "_" + weightIntersect + "_" + weightFactor + ".png" ) ); //System.out.println( "Exchanging to " + outFile0 ); //Grid2DSquareCellDoubleExchange.toImage( grid1, outFile0, "PNG" ); grid.clear(); } System.out.println( "Calculation complete. Time taken for processing so far " + Utilities.time( System.currentTimeMillis() - time ) ); } grid0.clear(); } } public void compare(){ // Set gridFactory Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); //Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); //Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFactory( dataDirectory1 ); //Grid2DSquareCellDoubleChunkFactory cf = new Grid2DSquareCellDoubleChunkFactory( dataDirectory1 ); AbstractGrid2DSquareCellDoubleFactory gridFactory = jf; // Set Parameters // Set kernel paramters double cellDistances = 20.0d; double weightIntersect = 1.0d; double distance; double weightFactor = 1.0d; // Set statistics Vector statistics = new Vector(); statistics.add( new String( "diff" ) ); statistics.add( new String( "corr" ) ); statistics.add( new String( "zdiff" ) ); // Set files and directories String dataDirectory0 = null; String dataDirectory1 = null; String dataDirectory3 = null; String inFileName0 = null; String inFileName1 = null; String inFileName00 = null; String inFileName11 = null; for ( int j = 0; j < 9; j ++ ) { if ( j == 0 ) { inFileName0 = "acc01"; inFileName1 = "acc00"; } if ( j == 1 ) { inFileName0 = "acc00"; inFileName1 = "acc99"; } if ( j == 2 ) { inFileName0 = "acc99"; inFileName1 = "acc98"; } if ( j == 3 ) { inFileName0 = "acc98"; inFileName1 = "acc97"; } if ( j == 4 ) { inFileName0 = "acc97"; inFileName1 = "acc96"; } if ( j == 5 ) { inFileName0 = "acc96"; inFileName1 = "acc95"; } if ( j == 6 ) { inFileName0 = "acc95"; inFileName1 = "acc94"; } if ( j == 7 ) { inFileName0 = "acc94"; inFileName1 = "acc93"; } if ( j == 8 ) { inFileName0 = "acc93"; inFileName1 = "acc92"; } dataDirectory0 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/" + inFileName0 + "/" ); dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/" + inFileName1 + "/" ); dataDirectory3 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/temp/diff/" + inFileName0 + inFileName1 ); // Process for ( int i = 1; i < 3; i ++ ) { // Prepare if ( i == 0 ) { inFileName00 = inFileName0; inFileName11 = inFileName1;} if ( i == 1 ) { inFileName00 = inFileName0 + "n"; inFileName11 = inFileName1 + "n"; } if ( i == 2 ) { inFileName00 = inFileName0 + "z"; inFileName11 = inFileName1 + "z"; } File inFile0 = new File( dataDirectory0, inFileName00 + ".asc" ); File inFile1 = new File( dataDirectory1, inFileName11 + ".asc" ); AbstractGrid2DSquareCellDouble grid0 = gridFactory.createGrid2DSquareCellDouble( inFile0 ); grid0.setName( inFileName00 ); AbstractGrid2DSquareCellDouble grid1 = gridFactory.createGrid2DSquareCellDouble( inFile1 ); grid1.setName( inFileName11 ); distance = grid0.getCellsize() * cellDistances; System.out.println( "Comparing " + inFileName00 + " with " + inFileName11 ); // Process AbstractGrid2DSquareCellDouble[] result = Grid2DSquareCellDoubleProcessor.compare( grid0, grid1, statistics, distance, weightIntersect, weightFactor, gridFactory ); // Exchange for ( int k = 0; k < result.length; k ++ ) { System.out.println( result[ k ].toString() ); String outfilename0 = new String( dataDirectory3 + result[ k ].getName() + "_" + distance + "_" + weightIntersect + "_" + weightFactor ); String type = "asc"; System.out.println( "Exchanging to " + outfilename0 + "." + type ); Grid2DSquareCellDoubleExchange.toAsciiFile( result[ k ], new File( outfilename0 + "." + type ) ); // Tidy result[ k ].clear(); } // Tidy grid0.clear(); grid1.clear(); } } } public void globalCompare(){ String dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/100/" ); File inFile0 = new File( new String( dataDirectory1 + "road.asc" ) ); File inFile1 = new File( new String( dataDirectory1 + "casnull.asc" ) ); Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); //Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); //Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFactory( dataDirectory1 ); //Grid2DSquareCellDoubleChunkFactory cf = new Grid2DSquareCellDoubleChunkFactory( dataDirectory1 ); AbstractGrid2DSquareCellDoubleFactory gridFactory = jf; AbstractGrid2DSquareCellDouble grid0 = gridFactory.createGrid2DSquareCellDouble( inFile0 ); AbstractGrid2DSquareCellDouble grid1 = gridFactory.createGrid2DSquareCellDouble( inFile1 ); System.out.println( grid0.toString() ); System.out.println( grid1.toString() ); System.out.println( "Processing..." ); String comparator = "pearsons"; double result = Grid2DSquareCellDoubleProcessor.globalCompare( grid0, grid1, comparator ); System.out.println( comparator + " " + result ); System.out.println( "Finalising..." ); grid0.clear(); grid1.clear(); } public void aggregate(){ String dataDirectory0 = new String( "d:/andyt/projects/medaction/data/arc/dem/" ); File inFile0 = new File( new String( dataDirectory0 + "dem4.asc" ) ); Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); AbstractGrid2DSquareCellDouble grid0 = jf.createGrid2DSquareCellDouble( inFile0 ); System.out.println( "grid0" ); System.out.println( grid0.toString() ); System.out.println( "Processing..." ); //String statistic = "min"; //String statistic = "max"; //String statistic = "sum"; String statistic = "mean"; //int cellFactor = 2; double resultCellsize = 1000.0d; double resultXllcorner = -1594713.25; double resultYllcorner = -1312168.125; AbstractGrid2DSquareCellDouble grid1 = Grid2DSquareCellDoubleProcessor.aggregate( grid0, resultCellsize, statistic, resultXllcorner, resultYllcorner, jf ); System.out.println( "grid1" ); System.out.println( grid1.toString() ); System.out.println( "Exchanging..." ); File outFile0 = new File( new String( dataDirectory0 + "dem5.asc" ) ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid1, outFile0 ); System.out.println( "Finalising..." ); grid0.clear(); grid1.clear(); } }