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 //regionUnivariateStatistics1(); //simple(); //regionUnivariateStatistics2(); compare3(); //globalCompare(); //geometricDensity(); System.out.println( "Processing complete in " + Utilities.time( System.currentTimeMillis() - time ) ); } public void simple() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String dataDirectory0 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9701/" ); String dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9296/" ); String fileName0 = "acc9701.asc"; String fileName1 = "acc9296.asc"; AbstractGrid2DSquareCellDouble minus; if ( true ) { AbstractGrid2DSquareCellDouble grid0 = jf.createGrid2DSquareCellDouble( new File( dataDirectory0, fileName0 ) ); AbstractGrid2DSquareCellDouble grid1 = jf.createGrid2DSquareCellDouble( new File( dataDirectory1, fileName1 ) ); minus = Grid2DSquareCellDoubleProcessor.minus( grid0, grid1, true, jf ); } System.gc(); Vector statistics = new Vector(); statistics.add( new String( "NWSum" ) ); double weightFactor = 1.0d; double weightIntersect = 1.0d; double distance = 400.0d; Vector regionUnivariateStatistics = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( minus, statistics, distance, weightIntersect, weightFactor ); System.out.println( ( ( AbstractGrid2DSquareCellDouble ) regionUnivariateStatistics.elementAt( 0 ) ).toString() ); } 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 = Grid2DSquareCellDoubleProcessorGWS.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 regionUnivariateStatistics1() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String dataDirectory0 = "d:/andyt/projects/phd/data/arc/leeds/grids/20/temp/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 regionUnivariateStatistics = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( grid0, statistics, distance, weightIntersect, weightFactor, jf ); AbstractGrid2DSquareCellDouble result = null; File outFile0 = null; new File( dataDirectory0, inFileName0 + ".asc" ); for ( int k = 0; k < regionUnivariateStatistics.size(); k ++ ) { result = ( ( AbstractGrid2DSquareCellDouble ) regionUnivariateStatistics.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 regionUnivariateStatistics2() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String dataDirectory0 = null; String inFileName0 = null; // kernel paramters double weightFactor = 1.0d; double weightIntersect = 1.0d; double distance; // statistics Vector statistics = new Vector(); //statistics.add( new String( "Sum" ) ); statistics.add( new String( "WSum" ) ); statistics.add( new String( "NWSum" ) ); statistics.add( new String( "WSumN" ) ); statistics.add( new String( "WMean1" ) ); statistics.add( new String( "WMean2" ) ); statistics.add( new String( "NWMean" ) ); statistics.add( new String( "WMeanN" ) ); //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 = 12; j < 13; 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"; String inFileName00 = null; File inFile0 = null; File outFile0 = null; AbstractGrid2DSquareCellDouble grid0 = null ; Vector regionUnivariateStatistics = null; for ( int i = 1; 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 ); grid0.setName( inFileName00 ); distance = grid0.getCellsize() * 20.0d; System.out.println( "Calculating " + grid0.getName() + " " + allstatistics + " ..." ); // Process regionUnivariateStatistics = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( grid0, statistics, distance, weightIntersect, weightFactor, jf ); System.out.println( "Number of GWS returned " + regionUnivariateStatistics.size() ); // Exchange AbstractGrid2DSquareCellDouble grid = null; for ( int k = 0; k < regionUnivariateStatistics.size(); k ++ ) { grid = ( ( AbstractGrid2DSquareCellDouble ) regionUnivariateStatistics.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 + "_" + 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 + "_" + grid.getName() + "_" + distance + "_" + weightIntersect + "_" + weightFactor + ".png" ) ); //System.out.println( "Exchanging to " + outFile0 ); //Grid2DSquareCellDoubleExchange.toImage( grid, outFile0, "PNG" ); grid.clear(); } System.out.println( "Calculation complete. Time taken for processing so far " + Utilities.time( System.currentTimeMillis() - time ) ); } grid0.clear(); } } public void compare1(){ // Set gridFactory Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); //Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); //Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFactory( dataDirectory1 ); //Grid2DSquareCellDoubleChunkFactory cf = new Grid2DSquareCellDoubleChunkFactory( dataDirectory1 ); AbstractGrid2DSquareCellDoubleFactory gridFactory = jf; // Set directories String dataDirectory0 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9701/" ); String dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9296/" ); String fileName0 = "acc9701"; String fileName1 = "acc9296"; String dataDirectory2 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/diff/9296_9701/" ); for ( int j = 0; j < 1; j ++ ) { // Set statistics Vector statistics = new Vector(); if ( j == 0 ) { statistics.add( new String( "WSum" ) ); } if ( j == 1 ) { statistics.add( new String( "NWSum" ) ); } if ( j == 2 ) { statistics.add( new String( "WSumN" ) ); } if ( j == 3 ) { statistics.add( new String( "WMean1" ) ); } if ( j == 4 ) { statistics.add( new String( "WMean2" ) ); } if ( j == 5 ) { statistics.add( new String( "WMeanN" ) ); } if ( j == 6 ) { statistics.add( new String( "NWMean" ) ); } // Set kernel paramters double weightFactor = 1.0d; double weightIntersect = 1.0d; double distance; String fileName00 = null; String fileName11 = null; for ( int i = 2; i < 3; i ++ ) { if ( i == 0 ) { fileName00 = fileName0; fileName11 = fileName1; } if ( i == 1 ) { fileName00 = fileName0 + "n"; fileName11 = fileName1 + "n"; } if ( i == 2 ) { fileName00 = fileName0 + "z"; fileName11 = fileName1 + "z"; } // Prepare Input AbstractGrid2DSquareCellDouble gws0 = null; if ( true ) { AbstractGrid2DSquareCellDouble grid0 = gridFactory.createGrid2DSquareCellDouble( new File( dataDirectory0, fileName00 + ".asc" ) ); grid0.setName( fileName00 ); // Set kernel paramters distance = grid0.getCellsize() * 20.0d; Vector gws = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( grid0, statistics, distance, weightIntersect, weightFactor ); gws0 = ( AbstractGrid2DSquareCellDouble ) gws.elementAt( 0 ); } System.gc(); AbstractGrid2DSquareCellDouble gws1 = null; if ( true ) { AbstractGrid2DSquareCellDouble grid1 = gridFactory.createGrid2DSquareCellDouble( new File( dataDirectory1, fileName11 + ".asc" ) ); grid1.setName( fileName11 ); // Set kernel paramters distance = grid1.getCellsize() * 20.0d; Vector gws = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( grid1, statistics, distance, weightIntersect, weightFactor ); gws1 = ( AbstractGrid2DSquareCellDouble ) gws.elementAt( 0 ); } System.gc(); // Calculate minus if ( false ) { AbstractGrid2DSquareCellDouble minus = Grid2DSquareCellDoubleProcessor.minus( gws0, gws1, true, gridFactory ); // Exchange Grid2DSquareCellDoubleExchange.toAsciiFile( minus, new File( dataDirectory2, minus.getName() + ".asc" ) ); } System.gc(); // Calculate divide if ( true ) { double defaultValue = -1.0d; AbstractGrid2DSquareCellDouble divide = Grid2DSquareCellDoubleProcessor.divide( gws0, gws1, gridFactory, defaultValue ); // Exchange Grid2DSquareCellDoubleExchange.toAsciiFile( divide, new File( dataDirectory2, divide.getName() + ".asc" ) ); } System.gc(); } } } public void compare2(){ // Set gridFactory Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); //Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); //Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFactory( dataDirectory1 ); //Grid2DSquareCellDoubleChunkFactory cf = new Grid2DSquareCellDoubleChunkFactory( dataDirectory1 ); AbstractGrid2DSquareCellDoubleFactory gridFactory = jf; // Set directories String dataDirectory0 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9701/" ); String dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9296/" ); String fileName0 = "acc9701"; String fileName1 = "acc9296"; String dataDirectory2 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/diff/9296_9701/" ); // Set statistics Vector statistics = new Vector(); statistics.add( new String( "NWSum" ) ); statistics.add( new String( "wSumN" ) ); // Set kernel paramters double weightFactor = 1.0d; double weightIntersect = 1.0d; double distance; String fileName00 = null; String fileName11 = null; for ( int i = 0; i < 3; i ++ ) { if ( i == 0 ) { fileName00 = fileName0; fileName11 = fileName1; } if ( i == 1 ) { fileName00 = fileName0 + "n"; fileName11 = fileName1 + "n"; } if ( i == 2 ) { fileName00 = fileName0 + "z"; fileName11 = fileName1 + "z"; } // Prepare Input AbstractGrid2DSquareCellDouble minus = null; if ( true ) { AbstractGrid2DSquareCellDouble grid0 = gridFactory.createGrid2DSquareCellDouble( new File( dataDirectory0, fileName00 + ".asc" ) ); grid0.setName( fileName00 ); AbstractGrid2DSquareCellDouble grid1 = gridFactory.createGrid2DSquareCellDouble( new File( dataDirectory1, fileName11 + ".asc" ) ); grid1.setName( fileName11 ); // Set kernel paramters distance = grid0.getCellsize() * 20.0d; // Calculate minus = Grid2DSquareCellDoubleProcessor.minus( grid0, grid1, true, gridFactory ); } System.gc(); // GWS System.out.println("regionUnivariateStatistics"); Vector regionUnivariateStatistics = Grid2DSquareCellDoubleProcessorGWS.regionUnivariateStatistics( minus, statistics, distance, weightIntersect, weightFactor ); // Exchange for ( int k = 0; k < regionUnivariateStatistics.size(); k ++ ) { AbstractGrid2DSquareCellDouble result = ( AbstractGrid2DSquareCellDouble ) regionUnivariateStatistics.elementAt( k ); Grid2DSquareCellDoubleExchange.toAsciiFile( result, new File( dataDirectory2, result.getName() + ".asc" ) ); } } } public void compare3(){ Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); AbstractGrid2DSquareCellDoubleFactory gridFactory = jf; String dataDirectory0 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9701/" ); String dataDirectory1 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/acc/acc9296/" ); String dataDirectory2 = new String( "d:/andyt/projects/phd/data/arc/leeds/grids/20/diff/9296_9701/" ); File file0 = null; File file1 = null; String stat = null; for ( int i = 0; i < 7; i ++ ) { Vector statistics = new Vector(); if ( i == 0 ) { stat = new String( "WSum" ); statistics.add( stat ); } if ( i == 1 ) { stat = new String( "NWSum" ); statistics.add( stat ); } if ( i == 2 ) { stat = new String( "WSumN" ); statistics.add( stat ); } if ( i == 3 ) { stat = new String( "WMean1" ); statistics.add( stat ); } if ( i == 4 ) { stat = new String( "WMean2" ); statistics.add( stat ); } if ( i == 5 ) { stat = new String( "WMeanN" ); statistics.add( stat ); } if ( i == 6 ) { stat = new String( "NWMean" ); statistics.add( stat ); } for ( int j = 0; j < 3; j ++ ) { if( j == 0 ) { file0 = new File( dataDirectory0, "acc9701_" + stat + "_acc9701_400.0_1.0_1.0.asc" ); file1 = new File( dataDirectory1, "acc9296_" + stat + "_acc9296_400.0_1.0_1.0.asc" );} if( j == 1 ) { file0 = new File( dataDirectory0, "acc9701n_" + stat + "_acc9701n_400.0_1.0_1.0.asc" ); file1 = new File( dataDirectory1, "acc9296n_" + stat + "_acc9296n_400.0_1.0_1.0.asc" );} if( j == 2 ) { file0 = new File( dataDirectory0, "acc9701z_" + stat + "_acc9701z_400.0_1.0_1.0.asc" ); file1 = new File( dataDirectory1, "acc9296z_" + stat + "_acc9296z_400.0_1.0_1.0.asc" );} AbstractGrid2DSquareCellDouble grid0 = gridFactory.createGrid2DSquareCellDouble( file0 ); grid0.setName( file0.getName() ); AbstractGrid2DSquareCellDouble grid1 = gridFactory.createGrid2DSquareCellDouble( file1 ); grid1.setName( file1.getName() ); AbstractGrid2DSquareCellDouble minus = Grid2DSquareCellDoubleProcessor.minus( grid0, grid1, true, gridFactory ); AbstractGrid2DSquareCellDouble divide = Grid2DSquareCellDoubleProcessor.divide( grid0, grid1, gridFactory, -1.0d ); Grid2DSquareCellDoubleExchange.toAsciiFile( minus, new File( dataDirectory2, minus.getName() + ".asc" ) ); Grid2DSquareCellDoubleExchange.toAsciiFile( divide, new File( dataDirectory2, divide.getName() + ".asc" ) ); } } } public void globalCompare(){ } 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(); } }