package misc; /** * 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; public class GenerateTestData { public GenerateTestData(){} AbstractGrid2DSquareCellDoubleFactory gridFactory; public static void main(String[] args) throws java.io.IOException { GenerateTestData g = new GenerateTestData(); g.run(); } public void run() { System.out.println( "Initialising..." ); long time = System.currentTimeMillis(); int ngrids = 5; int nrows = 100; int ncols = 100; AbstractGrid2DSquareCellDouble[] grids = set1( ngrids, nrows, ncols); for ( int i = 0 ; i < ngrids ; i ++ ) { System.out.println( grids[ i ].toString() ); File file = new File ( "d:/andyt/src/grids/data", "set1_" + i + "_" + nrows + "_" + ncols + ".asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grids[ i ], file ); file = new File ( "d:/andyt/src/grids/data", "set1_" + i + "_" + nrows + "_" + ncols + ".png" ); Grid2DSquareCellDoubleExchange.toImage( grids[ i ], file, "png" ); } System.out.println( "Processing complete in " + Utilities.time( System.currentTimeMillis() - time ) ); } public AbstractGrid2DSquareCellDouble[] set1( int ngrids, int nrows, int ncols ) { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); AbstractGrid2DSquareCellDouble[] grids = new AbstractGrid2DSquareCellDouble[ ngrids ]; for ( int i = 0 ; i < ngrids ; i ++ ) { grids[ i ] = jf.createGrid2DSquareCellDouble( nrows, ncols ); } // grids[ 0 ] for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grids[ 0 ].setCell( i, j, Math.random() ); } } // grids[ 1 ] should show some +ve correlation with grids[ 0 ] for large enough nrows and ncols for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grids[ 1 ].setCell( i, j, grids[ 0 ].getCell( i, j ) + Math.random() ); } } // grids[ 2 ] should be highly +vely correlated with grids[ 0 ] for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grids[ 2 ].setCell( i, j, ( 10.0d * grids[ 0 ].getCell( i, j ) ) + Math.random() ); } } // grids[ 3 ] should show some -ve correlation with grids[ 0 ] for large enough nrows and ncols for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grids[ 3 ].setCell( i, j, Math.random() - grids[ 0 ].getCell( i, j ) ); } } // grids[ 4 ] should be highly -vely correlated with grids[ 0 ] for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grids[ 4 ].setCell( i, j, Math.random() - ( 10.0d * grids[ 0 ].getCell( i, j ) ) ); } } return grids; } }