/** * Example use of uk.ac.leeds.ccg.andyt.gws.core * Copyright (C) 2005 Andy Turner, CCG, University of Leeds, UK. * * 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. */ package uk.ac.leeds.ccg.andyt.gws.examples; // java dependencies import java.io.*; import java.math.BigDecimal; import java.util.*; import java.awt.geom.*; // uk.ac.leeds.ccg.andyt.grids dependencies import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDouble; import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDoubleFactory; import uk.ac.leeds.ccg.andyt.grids.exchange.ESRIAsciiGridExporter; // uk.ac.leeds.ccg.andyt.gws dependencies import uk.ac.leeds.ccg.andyt.gws.utilities.Utilities; import uk.ac.leeds.ccg.andyt.gws.core.AdaptiveGWS; /** * TODO: * docs */ public class AdaptiveGWSRuns { long time; /** Creates a new instance of GWSRunner */ public AdaptiveGWSRuns() { } /** * @param args the command line arguments */ public static void main(String[] args) { AdaptiveGWSRuns r = new AdaptiveGWSRuns(); r.run(); } public void run() { System.out.println( "Initialising ..." ); time = System.currentTimeMillis(); runAdaptive1(); //System.out.println( "Processing complete in " + uk.ac.leeds.ccg.andyt.grids.Utilities.time( System.currentTimeMillis() - time ) ); //time = System.currentTimeMillis(); //runAdaptive2(); //System.out.println( "Processing complete in " + uk.ac.leeds.ccg.andyt.grids.Utilities.time( System.currentTimeMillis() - time ) ); time = System.currentTimeMillis(); //runAdaptive4(); System.out.println( "Processing complete in " + uk.ac.leeds.ccg.andyt.grids.utilities.Utilities.time( System.currentTimeMillis() - time ) ); } public void runAdaptive1() { AdaptiveGWS adaptiveGWS = new AdaptiveGWS(); String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/AdaptiveKernel0"; // Initialisation Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory = new Grid2DSquareCellDoubleFactory(); BigDecimal[] dimensions = new BigDecimal[ 5 ]; // Cellsize dimensions[ 0 ] = new BigDecimal( "20" ); double cellsize = dimensions[ 0 ].doubleValue(); double noDataValue = -9999.0d; // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // long nrows = 2375L; // long ncols = 2685L; // dimensions[ 1 ] = new BigDecimal( "403200" ); // dimensions[ 2 ] = new BigDecimal( "412600" ); // // Leeds City Centre // String region = "lcc"; // long nrows = 200L; // long ncols = 250L; // dimensions[ 1 ] = new BigDecimal( "428000" ); // dimensions[ 2 ] = new BigDecimal( "432000" ); // Test String region = "test"; long nrows = 60L; long ncols = 50L; dimensions[ 1 ] = new BigDecimal( "428000" ); dimensions[ 2 ] = new BigDecimal( "432000" ); BigDecimal nrowsBigDecimal = new BigDecimal( nrows ); BigDecimal ncolsBigDecimal = new BigDecimal( ncols ); dimensions[ 3 ] = dimensions[ 1 ].add( dimensions[ 0 ].multiply( ncolsBigDecimal ) ); dimensions[ 4 ] = dimensions[ 2 ].add( dimensions[ 0 ].multiply( nrowsBigDecimal ) ); // Generate input Grid2DSquareCellDouble grid2DSquareCellDouble = grid2DSquareCellDoubleFactory.createGrid2DSquareCellDouble( nrows, ncols, dimensions, noDataValue ); // Restrict study area // double width = cellsize * ( double ) ncols; // double height = cellsize * ( double ) nrows; // double buffer = 10000.0d; // double xmin = xllcorner - buffer; // double ymin = yllcorner - buffer; // double xmax = xllcorner + width + buffer; // double ymax = yllcorner + height + buffer; //System.out.println( "xmin " + xmin + ", xmax " + xmax + ", ymin " + ymin + ", ymax " + ymax ); File output = null; File input = null; double weightIntersect = 1.0d; double weightFactor = 1.0d; double setDistance = cellsize * 30.0d; int precision = 100; double sumAdaptiveKernelWeights = 10000.0d; int numberOfPointsFactor = 2; //int numberOfPoints = 10; String time0 = "92to96"; String time1 = "97to01"; for ( int numberOfPoints = 20; numberOfPoints < 180; numberOfPoints *= 2 ) { for ( int i = 0; i < 2; i ++ ) { Point2D.Double[] t0Points = null; if ( i == 0 ) { t0Points = Utilities.loadData( new File( dataDirectory, "92Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "93Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "94Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "95Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "96Fatalxy.csv" ) ); output = new File( outDataDirectory, "Fatal_9296_" + numberOfPoints + ".asc" ); } if ( i == 1 ) { t0Points = Utilities.loadData( new File( dataDirectory, "97Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "98Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "99Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "00Fatalxy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "01Fatalxy.csv" ) ); output = new File( outDataDirectory, "Fatal_9701_" + numberOfPoints + ".asc" ); } Grid2DSquareCellDouble adaptiveKernelWeights = adaptiveGWS.getAdaptiveKernelWeights( t0Points, grid2DSquareCellDoubleFactory, grid2DSquareCellDouble, numberOfPoints, numberOfPointsFactor, weightIntersect, weightFactor, sumAdaptiveKernelWeights, precision, setDistance ); System.out.println( adaptiveKernelWeights.toString() ); new ESRIAsciiGridExporter().toAsciiFile( adaptiveKernelWeights, output ); } } } public void runAdaptive2() { AdaptiveGWS adaptiveGWS = new AdaptiveGWS(); String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/AdaptiveKernel0"; Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory = new Grid2DSquareCellDoubleFactory(); BigDecimal[] dimensions = new BigDecimal[ 5 ]; // Cellsize dimensions[ 0 ] = new BigDecimal( "20" ); double cellsize = dimensions[ 0 ].doubleValue(); double noDataValue = -9999.0d; // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // long nrows = 2375L; // long ncols = 2685L; // dimensions[ 1 ] = new BigDecimal( "403200" ); // dimensions[ 2 ] = new BigDecimal( "412600" ); // // Leeds City Centre // String region = "lcc"; // long nrows = 200L; // long ncols = 250L; // dimensions[ 1 ] = new BigDecimal( "428000" ); // dimensions[ 2 ] = new BigDecimal( "432000" ); // Test String region = "test"; long nrows = 60L; long ncols = 50L; dimensions[ 1 ] = new BigDecimal( "428000" ); dimensions[ 2 ] = new BigDecimal( "432000" ); BigDecimal nrowsBigDecimal = new BigDecimal( nrows ); BigDecimal ncolsBigDecimal = new BigDecimal( ncols ); dimensions[ 3 ] = dimensions[ 1 ].add( dimensions[ 0 ].multiply( ncolsBigDecimal ) ); dimensions[ 4 ] = dimensions[ 2 ].add( dimensions[ 0 ].multiply( nrowsBigDecimal ) ); Grid2DSquareCellDouble grid2DSquareCellDouble = grid2DSquareCellDoubleFactory.createGrid2DSquareCellDouble( nrows, ncols, dimensions ); // Restrict study area // double width = cellsize * ( double ) ncols; // double height = cellsize * ( double ) nrows; // double buffer = 1000.0d; // double xmin = xllcorner - buffer; // double ymin = yllcorner - buffer; // double xmax = xllcorner + width + buffer; // double ymax = yllcorner + height + buffer; // Load data String time0 = "92to96"; String time1 = "97to01"; Point2D.Double[] t0Points = Utilities.loadData( new File( dataDirectory, "acc" + time0 + "xy.csv" ), dimensions ); Point2D.Double[] t1Points = Utilities.loadData( new File( dataDirectory, "acc" + time1 + "xy.csv" ), dimensions ); // Main processing double weightIntersect = 1.0d; double weightFactor = 1.0d; double sumAdaptiveKernelWeights = 10000.0d; int precision = 50; int numberOfPointsFactor = 3; int numberOfPoints = 10; double setDistance = cellsize * 30.0d; //double setDistance = cellsize * 10.0d; Grid2DSquareCellDouble[] adaptiveKernelWeights = adaptiveGWS.getAdaptiveKernelWeights( t0Points, t1Points, grid2DSquareCellDoubleFactory, grid2DSquareCellDouble, numberOfPoints, numberOfPointsFactor, setDistance, weightIntersect, weightFactor, sumAdaptiveKernelWeights, precision ); // Exchange File t0PointsOutput = new File( outDataDirectory, "t" + time0 + "" + region + "" + numberOfPoints + "_2.asc" ); File t1PointsOutput = new File( outDataDirectory, "t" + time1 + "" + region + "" + numberOfPoints + "_2.asc" ); System.out.println( adaptiveKernelWeights[ 0 ].toString() ); System.out.println( adaptiveKernelWeights[ 1 ].toString() ); new ESRIAsciiGridExporter().toAsciiFile( adaptiveKernelWeights[ 0 ], t0PointsOutput ); new ESRIAsciiGridExporter().toAsciiFile( adaptiveKernelWeights[ 1 ], t1PointsOutput ); } // public void runAdaptive3() { // AdaptiveGWS adaptiveGWS = new AdaptiveGWS(); // String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; // String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/AdaptiveKernel0"; // // Initialisation // Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); // Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); // // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // int nrows = 2375; // int ncols = 2685; // double xllcorner = 403200.0d; // double yllcorner = 412600.0d; // /*// Leeds City Centre // String region = "lcc"; // int nrows = 200; // int ncols = 250; // double xllcorner = 428000.0d; // double yllcorner = 432000.0d; // // Test // String region = "test"; // int nrows = 60; // int ncols = 50; // double xllcorner = 428000.0d; // double yllcorner = 432000.0d; // */// Generate input // double cellsize = 20.0d; // double noDataValue = -9999.0d; // AbstractGrid2DSquareCellDouble grid = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue, 1 ); // // Restrict study area // double width = cellsize * ( double ) ncols; // double height = cellsize * ( double ) nrows; // double buffer = 10000.0d; // double xmin = xllcorner - buffer; // double ymin = yllcorner - buffer; // double xmax = xllcorner + width + buffer; // double ymax = yllcorner + height + buffer; // // Load data // String time0 = ""; // String time1 = ""; // //String time0 = "92to96"; // //String time1 = "97to01"; // for ( int times = 0; times < 9; times ++ ) { // if ( times == 0 ) { time0 = "92"; time1 = "93"; } // if ( times == 1 ) { time0 = "93"; time1 = "94"; } // if ( times == 2 ) { time0 = "94"; time1 = "95"; } // if ( times == 3 ) { time0 = "95"; time1 = "96"; } // if ( times == 4 ) { time0 = "96"; time1 = "97"; } // if ( times == 5 ) { time0 = "97"; time1 = "98"; } // if ( times == 6 ) { time0 = "98"; time1 = "99"; } // if ( times == 7 ) { time0 = "99"; time1 = "00"; } // if ( times == 8 ) { time0 = "00"; time1 = "01"; } // if ( times == 9 ) { time0 = "92to96"; time1 = "97to01"; } // //Point2D.Double[] t0Points = adaptiveGWS.loadData( new File( dataDirectory, "acc" + time0 + "xy.csv" ), xmin, ymin, xmax, ymax ); // Point2D.Double[] t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( new File( dataDirectory, "" + time0 + "Fatalxy.csv" ) ); // //adaptiveGWS.addPoints(t0Pointst0Points. // //Point2D.Double[] t1Points = adaptiveGWS.loadData( new File( dataDirectory, "acc" + time1 + "xy.csv" ), xmin, ymin, xmax, ymax ); // Point2D.Double[] t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( new File( dataDirectory, "" + time1 + "Fatalxy.csv" ) ); // // Main processing // int divisions = 8; // double weightIntersect = 1.0d; // double weightFactor = 1.0d; // double sumAdaptiveKernelWeights = 10000.0d; // int precision = 50; // int numberOfPointsFactor = 3; // double setDistance = cellsize * 30.0d; // //double setDistance = cellsize * 10.0d; // //int numberOfPoints = 20; // File output = null; // for ( int numberOfPoints = 10; numberOfPoints < 20; numberOfPoints *= 2 ) { // // Compute // AbstractGrid2DSquareCellDouble[] adaptiveKernelWeights = adaptiveGWS.getAdaptiveKernelWeights( divisions, t0Points, t1Points, jf, grid, numberOfPoints, numberOfPointsFactor, setDistance, weightIntersect, weightFactor, sumAdaptiveKernelWeights, precision ); // // Exchange // adaptiveKernelWeights[ 0 ].setName( time0 ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time0 + "_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time0 + "_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( adaptiveKernelWeights[ 0 ].toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( adaptiveKernelWeights[ 0 ], output ); // adaptiveKernelWeights[ 1 ].setName( time1 ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time1 + "_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time1 + "_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( adaptiveKernelWeights[ 1 ].toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( adaptiveKernelWeights[ 1 ], output ); // // Do difference and division // if ( true ) { // try { // AbstractGrid2DSquareCellDouble div = Grid2DSquareCellDoubleProcessor.divide( adaptiveKernelWeights[ 0 ], adaptiveKernelWeights[ 1 ], jf, noDataValue ); // div.setName( "div" ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_divide_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_divide_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( div.toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( div, output ); // } catch ( java.lang.OutOfMemoryError e ) { // System.out.println( e ); // } // } // System.gc(); // if ( true ) { // try { // AbstractGrid2DSquareCellDouble minus = Grid2DSquareCellDoubleProcessor.minus( adaptiveKernelWeights[ 0 ], adaptiveKernelWeights[ 1 ], true, jf ); // minus.setName( "minus" ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_minus_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_minus_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( minus.toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( minus, output ); // } catch ( java.lang.OutOfMemoryError e ) { // System.out.println( e ); // } // } // System.gc(); // } // } // } // // // public void runAdaptive4() { // String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; // String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/AdaptiveKernel0"; // // // Initialisation // AdaptiveGWS adaptiveGWS = new AdaptiveGWS(); // Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); // Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); // // // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // int nrows = 2375; // int ncols = 2685; // double xllcorner = 403200.0d; // double yllcorner = 412600.0d; // /*// Leeds City Centre // String region = "lcc"; // int nrows = 200; // int ncols = 250; // double xllcorner = 428000.0d; // double yllcorner = 432000.0d; // // Test // String region = "test"; // int nrows = 60; // int ncols = 50; // double xllcorner = 428000.0d; // double yllcorner = 432000.0d; // */ // // // Generate input grid // double cellsize = 20.0d; // double noDataValue = -9999.0d; // AbstractGrid2DSquareCellDouble grid = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue, 1 ); // // // Load data // // Point2D.Double[] t0Points = null; // t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( new File( dataDirectory, "92Fatalxy.csv" ) ); // t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t0Points, new File( dataDirectory, "93Fatalxy.csv" ) ); // t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t0Points, new File( dataDirectory, "94Fatalxy.csv" ) ); // t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t0Points, new File( dataDirectory, "95Fatalxy.csv" ) ); // t0Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t0Points, new File( dataDirectory, "96Fatalxy.csv" ) ); // // Point2D.Double[] t1Points = null; // t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( new File( dataDirectory, "97Fatalxy.csv" ) ); // t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t1Points, new File( dataDirectory, "98Fatalxy.csv" ) ); // t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t1Points, new File( dataDirectory, "99Fatalxy.csv" ) ); // t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t1Points, new File( dataDirectory, "00Fatalxy.csv" ) ); // t1Points = uk.ac.leeds.ccg.andyt.gws.Utilities.loadData( t1Points, new File( dataDirectory, "01Fatalxy.csv" ) ); // // // Main processing // String time0 = "9296"; // String time1 = "9701"; // int divisions = 8; // double weightIntersect = 1.0d; // double weightFactor = 1.0d; // double sumAdaptiveKernelWeights = 10000.0d; // int precision = 50; // int numberOfPointsFactor = 3; // double setDistance = cellsize * 30.0d; // File output = null; // for ( int numberOfPoints = 10; numberOfPoints < 50; numberOfPoints *= 2 ) { // // Compute // AbstractGrid2DSquareCellDouble[] adaptiveKernelWeights = adaptiveGWS.getAdaptiveKernelWeights( divisions, t0Points, t1Points, jf, grid, numberOfPoints, numberOfPointsFactor, setDistance, weightIntersect, weightFactor, sumAdaptiveKernelWeights, precision ); // // Exchange // adaptiveKernelWeights[ 0 ].setName( time0 ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time0 + "_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time0 + "_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( adaptiveKernelWeights[ 0 ].toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( adaptiveKernelWeights[ 0 ], output ); // adaptiveKernelWeights[ 1 ].setName( time1 ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time1 + "_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_" + time1 + "_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( adaptiveKernelWeights[ 1 ].toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( adaptiveKernelWeights[ 1 ], output ); // // Do difference and division // if ( true ) { // try { // AbstractGrid2DSquareCellDouble div = Grid2DSquareCellDoubleProcessor.divide( adaptiveKernelWeights[ 0 ], adaptiveKernelWeights[ 1 ], jf, noDataValue ); // div.setName( "div" ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_divide_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_divide_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( div.toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( div, output ); // } catch ( java.lang.OutOfMemoryError e ) { // System.out.println( e ); // } // } // System.gc(); // if ( true ) { // try { // AbstractGrid2DSquareCellDouble minus = Grid2DSquareCellDoubleProcessor.minus( adaptiveKernelWeights[ 0 ], adaptiveKernelWeights[ 1 ], true, jf ); // minus.setName( "minus" ); // //output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_minus_" + region + "" + numberOfPoints + "_3.asc" ); // output = new File( outDataDirectory, "t" + time0 + "" + time1 + "_minus_" + region + "" + numberOfPoints + "Fatal_3.asc" ); // System.out.println( minus.toString() ); // Grid2DSquareCellDoubleExchange.toAsciiFile( minus, output ); // } catch ( java.lang.OutOfMemoryError e ) { // System.out.println( e ); // } // } // System.gc(); // } // } }