uk.ac.leeds.ccg.andyt.grids.process
Class Grid2DSquareCellProcessor

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
      extended by uk.ac.leeds.ccg.andyt.grids.process.Grid2DSquareCellProcessor
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Grid2DSquareCellProcessorDEM, Grid2DSquareCellProcessorGWS

public class Grid2DSquareCellProcessor
extends ErrorHandler

A class holding methods for processing an individual Grid2DSquareCellAbstract or multiple Grid2DSquareCellAbstracts. TODO: Implement a general replace method ( depricate/replace mask methods ).

See Also:
Serialized Form

Field Summary
protected  java.util.HashSet grid2DSquareCells
          A collection of the Grid2dSquareCellAbstracts being processed
protected  java.io.PrintWriter log
          The log for recording progress and information about the processing.
protected  int logIndentation
          The log indentation (how many spaces before a log message line is output).
protected  long startTime
          For storing the start time of the processing.
protected  java.io.File workspace
          The workspace directory for the processing.
 
Fields inherited from class uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
handleOutOfMemoryErrorFalse, handleOutOfMemoryErrorTrue, memoryReserve
 
Constructor Summary
Grid2DSquareCellProcessor()
          Creates a new instance of Grid2DSquareCellDoubleProcessor
Grid2DSquareCellProcessor(java.io.File workspace)
          Creates a new instance of Grid2DSquareCellDoubleProcessor.
Grid2DSquareCellProcessor(java.io.File workspace, boolean append)
          Creates a new instance of Grid2DSquareCellDoubleProcessor.
 
Method Summary
 Grid2DSquareCellDouble add(Grid2DSquareCellDouble grid0, Grid2DSquareCellDouble grid1, boolean data, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          TODO: 1.
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, double value, boolean handleOutOfMemoryError)
          Returns grid with value added to every cell via AbstractGrid2DSquareCellDouble.addToCell(value)
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, double value, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a copy of grid with value added to every cell via AbstractGrid2DSquareCellDouble.addToCell(value)
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, java.io.File file, java.lang.String type, boolean handleOutOfMemoryError)
          Returns grid with values added from a file.
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, Grid2DSquareCellAbstract.CellID[] cellIDs, double value, boolean handleOutOfMemoryError)
          Returns grid with value added to every cell via Grid2DSquareCellDouble.addToCell(value)
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, Grid2DSquareCellDouble gridToAdd, boolean handleOutOfMemoryError)
          Returns grid with values added from gridToAdd
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble, Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd, double weight, boolean handleOutOfMemoryError)
          Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd multiplied by weight.
protected  Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble, Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd, long startRowIndex, long startColIndex, long endRowIndex, long endColIndex, java.math.BigDecimal[] dimensionConstraints, double weight, boolean handleOutOfMemoryError)
          Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd (with row index between startRowIndex, endRowIndex and column index between startColIndex, endColIndex) multiplied by weight.
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble, Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd, long startRowIndex, long startColIndex, long endRowIndex, long endColIndex, double weight, boolean handleOutOfMemoryError)
          Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd (with row index between startRowIndex, endRowIndex and column index between startColIndex, endColIndex) multiplied by weight.
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, java.util.HashSet cellIDs, double value, boolean handleOutOfMemoryError)
          Returns grid with value added to all cells with IDs as Integers in cellKeys.
 Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid, java.util.HashSet cellIDs, double value, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a copy of grid with value added to all cells with IDs as Integer keys in cellIDKeys
 Grid2DSquareCellDouble aggregate(Grid2DSquareCellDouble grid, int cellFactor, java.lang.String statistic, int rowOffset, int colOffset, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns an Grid2DSquareCellDouble at a lower level of resolution than grid.
 Grid2DSquareCellDouble aggregate(Grid2DSquareCellDouble grid, java.lang.String statistic, java.math.BigDecimal[] resultDimensions, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns an Grid2DSquareCellDouble at a lower level of resolution than grid.
 void copyAndSetUpNewLog(java.io.File newLog, boolean handleOutOfMemoryError)
          Copies the log
 Grid2DSquareCellDouble distanceToDataValue(Grid2DSquareCellDouble grid0, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble the values of which are the distance to the nearest data value TODO: Optimise as it is currently very slow and inefficient!!!
 Grid2DSquareCellDouble divide(Grid2DSquareCellDouble grid0, Grid2DSquareCellDouble grid1, Grid2DSquareCellDoubleFactory gridFactory, double defaultValue, boolean handleOutOfMemoryError)
           
 void freeMemoryOrThrowError()
          Attempts to: clear the memory reserve, cache a seriailized version of a Chunk of a Grid2DSquareCellAbstract in this.grid2DSquareCells then clear it.
protected  java.util.HashSet getGrid2DSquareCells()
          Returns this.grid2DSquareCells
protected  double[][] getRowProcessData(Grid2DSquareCellDouble grid, double[][] previous, int cellDistance, long row, long col)
          Returns a double[][] based on previous which has been shuffled
protected  double[][] getRowProcessInitialData(Grid2DSquareCellDouble grid, int cellDistance, long row)
          Returns a double[][] of grid values
 long getTime0()
          Returns a copy of this.startTime.
 java.io.File getWorkspace()
          Returns a copy of this.workspace
protected  void initWorkspace(java.io.File workspace)
          Initialises workspace.
 Grid2DSquareCellDouble linearRescale(Grid2DSquareCellDouble grid, double min, double max, boolean handleOutOfMemoryError)
          Returns grid with values linearly rescaled into the range [min,max].
 Grid2DSquareCellDouble linearRescale(Grid2DSquareCellDouble grid, double min, double max, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but with values linearly rescaled into the range [min,max].
 void log(int logIndentation, java.lang.String string, boolean handleOutOfMemoryError)
          Writes string to log file and the console (standard output) indenting string by logIndentation amount of white-space.
 void log(java.lang.String string, boolean handleOutOfMemoryError)
          Writes string to log file and the console (standard output)
 Grid2DSquareCellDouble logRescale(Grid2DSquareCellDouble grid, double min, double max, boolean handleOutOfMemoryError)
          Returns grid with values linearly scaled to range [1.0d,1000000.0d] then logged using Math.log(double) and then linearly scaled into the range [min,max]
 Grid2DSquareCellDouble logRescale(Grid2DSquareCellDouble grid, double min, double max, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but with values linearly scaled to range [1.0d,1000000.0d] then logged using Math.log(double) and then linearly scaled into the range [min,max]
 Grid2DSquareCellDouble mask(Grid2DSquareCellAbstract grid2DSquareCellToMask, Grid2DSquareCellAbstract grid2DSquareCellMask, boolean handleOutOfMemoryError)
          Returns a Grid2DSquareCellAbstract identical to grid2DSquareCellToMask but with cells coincident with grid2DSquareCellMask if their centroids intersect a cell of mask that has a noDataValue.
 Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid, double min, double max, boolean handleOutOfMemoryError)
          Returns grid with the values of cells in the range [min,max] set to its noDataValue.
 Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid, double xmin, double ymin, double xmax, double ymax, boolean handleOutOfMemoryError)
          Returns grid with the value of cells that's centroids intersect the rectangle given by (xmin,ymin,xmax,ymax) set to its noDataValue.
 Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid, Grid2DSquareCellDouble mask, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but masked using mask.
 Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid, long startRowIndex, long startColIndex, long endRowIndex, long endColIndex, boolean handleOutOfMemoryError)
          Returns grid with the value of cells that intersect rectangle given by (startRowIndex,startColIndex,endRowIndex,endColIndex) set to its noDataValue.
 Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid, long startRowIndex, long startColIndex, long endRowIndex, long endColIndex, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but with the value of cells in grid that intersect rectangle given by (startRowIndex,startColIndex,endRowIndex,endColIndex) set to its noDataValue.
 Grid2DSquareCellDouble minus(Grid2DSquareCellDouble grid0, Grid2DSquareCellDouble grid1, boolean data, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          TODO: 1.
 Grid2DSquareCellDouble multiply(Grid2DSquareCellDouble grid0, Grid2DSquareCellDouble grid1, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
           
 Grid2DSquareCellDouble replace(Grid2DSquareCellDouble grid2DSquareCell, long[] cellConstraints, java.math.BigDecimal[] dimensionsConstraints, double minValueInRangeToBeReplaced, double maxValueInRangeToBeReplaced, double valueToInsert, boolean handleOutOfMemoryError)
          Returns a Grid2DSquareCellDouble identical to grid2DSquareCell but with cells with values in range given by (minValueInRangeToBeReplaced, maxValueInRangeToBeReplaced) replaced with valueToInsert, boolean handleOutOfMemoryError ) { coincident with grid2DSquareCellMask if their centroids intersect a cell of mask that has a noDataValue.
 Grid2DSquareCellDouble setValueALittleBitLarger(Grid2DSquareCellDouble grid, java.util.HashSet cellIDs, boolean handleOutOfMemoryError)
          Returns grid with value of cells with keys in cellKeys set to a value a little bit larger.
 Grid2DSquareCellDouble setValueALittleBitLarger(Grid2DSquareCellDouble grid, java.util.HashSet cellIDs, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but with value of cells with keys in cellKeys set to a value a little bit larger.
 Grid2DSquareCellDouble setValueALittleBitSmaller(Grid2DSquareCellDouble grid, java.util.HashSet cellIDKeys, boolean handleOutOfMemoryError)
          Returns grid with value of cells with keys in cellKeys set to a value a little bit smaller.
 Grid2DSquareCellDouble setValueALittleBitSmaller(Grid2DSquareCellDouble grid, java.util.HashSet cellIDs, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellDouble that is a copy of grid, but with value of cells with keys in cellKeys set to a value a little bit smaller.
 void setWorkspace(java.io.File workspace, boolean handleOutOfMemoryError)
          Changes workspace to that passed in if it can be created.
 void setWorkspace(java.io.File workspace, boolean copyLogFile, boolean handleOutOfMemoryError)
          Changes workspace to that passed in if it can be created.
 
Methods inherited from class uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
clearMemoryReserve, initMemoryReserve, initMemoryReserve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startTime

protected long startTime
For storing the start time of the processing.


log

protected java.io.PrintWriter log
The log for recording progress and information about the processing.


logIndentation

protected int logIndentation
The log indentation (how many spaces before a log message line is output).


workspace

protected java.io.File workspace
The workspace directory for the processing.


grid2DSquareCells

protected java.util.HashSet grid2DSquareCells
A collection of the Grid2dSquareCellAbstracts being processed

Constructor Detail

Grid2DSquareCellProcessor

public Grid2DSquareCellProcessor()
Creates a new instance of Grid2DSquareCellDoubleProcessor


Grid2DSquareCellProcessor

public Grid2DSquareCellProcessor(java.io.File workspace)
Creates a new instance of Grid2DSquareCellDoubleProcessor. By default the logs are appended to the end of the log file if it exists. To overwrite the log file use: Grid2DSquareCellDoubleProcessor( workspace, false );

Parameters:
workspace -

Grid2DSquareCellProcessor

public Grid2DSquareCellProcessor(java.io.File workspace,
                                 boolean append)
Creates a new instance of Grid2DSquareCellDoubleProcessor. The log file in workspace will be overwritten if append is false.

Parameters:
workspace -
append -
Method Detail

getTime0

public long getTime0()
Returns a copy of this.startTime.


getWorkspace

public java.io.File getWorkspace()
Returns a copy of this.workspace


getGrid2DSquareCells

protected java.util.HashSet getGrid2DSquareCells()
Returns this.grid2DSquareCells


initWorkspace

protected void initWorkspace(java.io.File workspace)
Initialises workspace. If it already exists then the log file is appended to. Otherwise it is created and the log is set up. If the directory into which workspace is being created is not writable this will fail.

Parameters:
workspace - The workspace to initialise.

freeMemoryOrThrowError

public final void freeMemoryOrThrowError()
Attempts to: clear the memory reserve, cache a seriailized version of a Chunk of a Grid2DSquareCellAbstract in this.grid2DSquareCells then clear it. Then reinitialise the memory reserve. It either succeeds or throws an OutOfMemoryError. TODO: May want more sophistication as to what chunks are cached (what order etc...)


setWorkspace

public void setWorkspace(java.io.File workspace,
                         boolean handleOutOfMemoryError)
Changes workspace to that passed in if it can be created. By default this does not copy the logfile from the existing workspace when it sets up a log in the new location. To do this use: setWorkspace( workspace, true )

Parameters:
workspace - The workspace to change to.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

setWorkspace

public void setWorkspace(java.io.File workspace,
                         boolean copyLogFile,
                         boolean handleOutOfMemoryError)
Changes workspace to that passed in if it can be created. If copyLogFile is true, this copies the logfile from the existing workspace and sets up the log to append in the new location.

Parameters:
workspace - The workspace to change to.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

copyAndSetUpNewLog

public void copyAndSetUpNewLog(java.io.File newLog,
                               boolean handleOutOfMemoryError)
Copies the log

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

log

public void log(java.lang.String string,
                boolean handleOutOfMemoryError)
Writes string to log file and the console (standard output)

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

log

public void log(int logIndentation,
                java.lang.String string,
                boolean handleOutOfMemoryError)
Writes string to log file and the console (standard output) indenting string by logIndentation amount of white-space.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

replace

public Grid2DSquareCellDouble replace(Grid2DSquareCellDouble grid2DSquareCell,
                                      long[] cellConstraints,
                                      java.math.BigDecimal[] dimensionsConstraints,
                                      double minValueInRangeToBeReplaced,
                                      double maxValueInRangeToBeReplaced,
                                      double valueToInsert,
                                      boolean handleOutOfMemoryError)
Returns a Grid2DSquareCellDouble identical to grid2DSquareCell but with cells with values in range given by (minValueInRangeToBeReplaced, maxValueInRangeToBeReplaced) replaced with valueToInsert, boolean handleOutOfMemoryError ) { coincident with grid2DSquareCellMask if their centroids intersect a cell of mask that has a noDataValue.

Parameters:
grid2DSquareCellToReplaceValues - The Grid2DSquareCellDouble to replace cells with value replaceValue.
mask - The Grid2DSquareCellDouble mask.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO:

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellAbstract grid2DSquareCellToMask,
                                   Grid2DSquareCellAbstract grid2DSquareCellMask,
                                   boolean handleOutOfMemoryError)
Returns a Grid2DSquareCellAbstract identical to grid2DSquareCellToMask but with cells coincident with grid2DSquareCellMask if their centroids intersect a cell of mask that has a noDataValue.

Parameters:
grid2DSquareCellToReplaceValues - The Grid2DSquareCellDouble to replace cells with value replaceValue.
mask - The Grid2DSquareCellDouble mask.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO:

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid,
                                   Grid2DSquareCellDouble mask,
                                   Grid2DSquareCellDoubleFactory gridFactory,
                                   boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but masked using mask.

Parameters:
grid - the Grid2DSquareCellDouble to be masked
mask - the Grid2DSquareCellDouble mask
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid,
                                   double min,
                                   double max,
                                   boolean handleOutOfMemoryError)
Returns grid with the values of cells in the range [min,max] set to its noDataValue. (Existing noDataValue cells in grid remain as noDataValue.)

Parameters:
grid - the Grid2DSquareCellDouble to be masked
min - the minimum value in the range
max - the maximum value in the range
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid,
                                   double xmin,
                                   double ymin,
                                   double xmax,
                                   double ymax,
                                   boolean handleOutOfMemoryError)
Returns grid with the value of cells that's centroids intersect the rectangle given by (xmin,ymin,xmax,ymax) set to its noDataValue.

Parameters:
grid - the Grid2DSquareCellDouble to be masked
xmin - the minimum x-coordinate of the masking rectangle
ymin - the minimum y-coordinate of the masking rectangle
xmax - the maximum x-coordinate of the masking rectangle
ymax - the maximum y-coordinate of the masking rectangle
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid,
                                   long startRowIndex,
                                   long startColIndex,
                                   long endRowIndex,
                                   long endColIndex,
                                   boolean handleOutOfMemoryError)
Returns grid with the value of cells that intersect rectangle given by (startRowIndex,startColIndex,endRowIndex,endColIndex) set to its noDataValue.

Parameters:
grid - the Grid2DSquareCellDouble to be masked
startRowIndex - the index of the first row to be masked
startColIndex - the index of the first column to be masked
endRowIndex - the index of the final row to be masked
endColIndex - the index of the final column to be masked
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellDouble mask(Grid2DSquareCellDouble grid,
                                   long startRowIndex,
                                   long startColIndex,
                                   long endRowIndex,
                                   long endColIndex,
                                   Grid2DSquareCellDoubleFactory gridFactory,
                                   boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but with the value of cells in grid that intersect rectangle given by (startRowIndex,startColIndex,endRowIndex,endColIndex) set to its noDataValue.

Parameters:
grid - The Grid2DSquareCellDouble to be masked.
startRowIndex - The index of the first row to be masked.
startColIndex - The index of the first column to be masked.
endRowIndex - The index of the final row to be masked.
endColIndex - The index of the final column to be masked.
gridFactory - The Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

linearRescale

public Grid2DSquareCellDouble linearRescale(Grid2DSquareCellDouble grid,
                                            double min,
                                            double max,
                                            boolean handleOutOfMemoryError)
Returns grid with values linearly rescaled into the range [min,max].

Parameters:
grid - the Grid2DSquareCellDouble to be processed.
min - the minimum value in the rescaled range.
max - the maximum value in the rescaled range.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

linearRescale

public Grid2DSquareCellDouble linearRescale(Grid2DSquareCellDouble grid,
                                            double min,
                                            double max,
                                            Grid2DSquareCellDoubleFactory gridFactory,
                                            boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but with values linearly rescaled into the range [min,max].

Parameters:
grid - the Grid2DSquareCellDouble to be processed.
min - the minimum value in the rescaled range.
max - the maximum value in the rescaled range.
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

logRescale

public Grid2DSquareCellDouble logRescale(Grid2DSquareCellDouble grid,
                                         double min,
                                         double max,
                                         boolean handleOutOfMemoryError)
Returns grid with values linearly scaled to range [1.0d,1000000.0d] then logged using Math.log(double) and then linearly scaled into the range [min,max]

Parameters:
grid - the Grid2DSquareCellDouble to be processed
min - the minimum value in the rescaled range
max - the maximum value in the rescaled range
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

logRescale

public Grid2DSquareCellDouble logRescale(Grid2DSquareCellDouble grid,
                                         double min,
                                         double max,
                                         Grid2DSquareCellDoubleFactory gridFactory,
                                         boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but with values linearly scaled to range [1.0d,1000000.0d] then logged using Math.log(double) and then linearly scaled into the range [min,max]

Parameters:
grid - the Grid2DSquareCellDouble to be processed
min - the minimum value in the rescaled range
max - the maximum value in the rescaled range
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

setValueALittleBitLarger

public Grid2DSquareCellDouble setValueALittleBitLarger(Grid2DSquareCellDouble grid,
                                                       java.util.HashSet cellIDs,
                                                       boolean handleOutOfMemoryError)
Returns grid with value of cells with keys in cellKeys set to a value a little bit larger.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDs -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

setValueALittleBitLarger

public Grid2DSquareCellDouble setValueALittleBitLarger(Grid2DSquareCellDouble grid,
                                                       java.util.HashSet cellIDs,
                                                       Grid2DSquareCellDoubleFactory gridFactory,
                                                       boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but with value of cells with keys in cellKeys set to a value a little bit larger.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDs -
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

setValueALittleBitSmaller

public Grid2DSquareCellDouble setValueALittleBitSmaller(Grid2DSquareCellDouble grid,
                                                        java.util.HashSet cellIDKeys,
                                                        boolean handleOutOfMemoryError)
Returns grid with value of cells with keys in cellKeys set to a value a little bit smaller.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDKeys -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

setValueALittleBitSmaller

public Grid2DSquareCellDouble setValueALittleBitSmaller(Grid2DSquareCellDouble grid,
                                                        java.util.HashSet cellIDs,
                                                        Grid2DSquareCellDoubleFactory gridFactory,
                                                        boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble that is a copy of grid, but with value of cells with keys in cellKeys set to a value a little bit smaller.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDs -
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        java.util.HashSet cellIDs,
                                        double value,
                                        boolean handleOutOfMemoryError)
Returns grid with value added to all cells with IDs as Integers in cellKeys.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDs -
value - the value to be added
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        java.util.HashSet cellIDs,
                                        double value,
                                        Grid2DSquareCellDoubleFactory gridFactory,
                                        boolean handleOutOfMemoryError)
Returns a copy of grid with value added to all cells with IDs as Integer keys in cellIDKeys

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellIDs -
value - the value to be added
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        double value,
                                        boolean handleOutOfMemoryError)
Returns grid with value added to every cell via AbstractGrid2DSquareCellDouble.addToCell(value)

Parameters:
grid - the Grid2DSquareCellDouble to be processed
value - the value to be added
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        Grid2DSquareCellAbstract.CellID[] cellIDs,
                                        double value,
                                        boolean handleOutOfMemoryError)
Returns grid with value added to every cell via Grid2DSquareCellDouble.addToCell(value)

Parameters:
grid - the Grid2DSquareCellDouble to be processed
value - the value to be added
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        double value,
                                        Grid2DSquareCellDoubleFactory gridFactory,
                                        boolean handleOutOfMemoryError)
Returns a copy of grid with value added to every cell via AbstractGrid2DSquareCellDouble.addToCell(value)

Parameters:
grid - the Grid2DSquareCellDouble to be processed
value - the value to be added
gridFactory - the Grid2DSquareCellDoubleFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        Grid2DSquareCellDouble gridToAdd,
                                        boolean handleOutOfMemoryError)
Returns grid with values added from gridToAdd

Parameters:
grid - the Grid2DSquareCellDouble to be processed
gridToAdd - the Grid2DSquareCellDouble from which values are added
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble,
                                        Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd,
                                        double weight,
                                        boolean handleOutOfMemoryError)
Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd multiplied by weight.

Parameters:
grid2DSquareCellDouble - The Grid2DSquareCellDouble to be processed.
grid2DSquareCellDoubleToAdd - The Grid2DSquareCellDouble from which values are added.
weight - The value grid2DSquareCellDoubleToAdd values are multiplied by.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble,
                                        Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd,
                                        long startRowIndex,
                                        long startColIndex,
                                        long endRowIndex,
                                        long endColIndex,
                                        double weight,
                                        boolean handleOutOfMemoryError)
Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd (with row index between startRowIndex, endRowIndex and column index between startColIndex, endColIndex) multiplied by weight.

Parameters:
grid2DSquareCellDouble - The Grid2DSquareCellDouble to be processed.
grid2DSquareCellDoubleToAdd - The Grid2DSquareCellDouble from which values are added.
startRowIndex - The index of the first row from which grid2DSquareCellDoubleToAdd values are added.
startColIndex - the index of the first column from which grid2DSquareCellDoubleToAdd values are added.
endRowIndex - the index of the final row from which grid2DSquareCellDoubleToAdd values are added.
endColIndex - the index of the final column from which grid2DSquareCellDoubleToAdd values are added.
weight - The value grid2DSquareCellDoubleToAdd values are multiplied by.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

addToGrid

protected Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid2DSquareCellDouble,
                                           Grid2DSquareCellDouble grid2DSquareCellDoubleToAdd,
                                           long startRowIndex,
                                           long startColIndex,
                                           long endRowIndex,
                                           long endColIndex,
                                           java.math.BigDecimal[] dimensionConstraints,
                                           double weight,
                                           boolean handleOutOfMemoryError)
Returns a Grid2DSquareCellDouble with values of grid2DSquareCellDouble added with values from grid2DSquareCellDoubleToAdd (with row index between startRowIndex, endRowIndex and column index between startColIndex, endColIndex) multiplied by weight.

Parameters:
grid2DSquareCellDouble - The Grid2DSquareCellDouble to be processed.
grid2DSquareCellDoubleToAdd - The Grid2DSquareCellDouble from which values are added.
startRowIndex - The index of the first row from which grid2DSquareCellDoubleToAdd values are added.
startColIndex - the index of the first column from which grid2DSquareCellDoubleToAdd values are added.
endRowIndex - the index of the final row from which grid2DSquareCellDoubleToAdd values are added.
endColIndex - the index of the final column from which grid2DSquareCellDoubleToAdd values are added.
dimensionContraints -
weight - The value grid2DSquareCellDoubleToAdd values are multiplied by.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: Check that reasonable answers are returned for intersections and aggregations.

addToGrid

public Grid2DSquareCellDouble addToGrid(Grid2DSquareCellDouble grid,
                                        java.io.File file,
                                        java.lang.String type,
                                        boolean handleOutOfMemoryError)
Returns grid with values added from a file.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
file - the file contining values to be added.
type - the type of file. Supported types include "xyv", "xy", "idxy" )
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

minus

public Grid2DSquareCellDouble minus(Grid2DSquareCellDouble grid0,
                                    Grid2DSquareCellDouble grid1,
                                    boolean data,
                                    Grid2DSquareCellDoubleFactory gridFactory,
                                    boolean handleOutOfMemoryError)
TODO: 1. Documentiation 2. Change so Grid2DSquareCellDouble are Grid2DSquareCellAbstract Returns a Grid2DSquareCellDouble that's values are those of grid0 minus grid1.

Parameters:
data - controls if result is produced even if one of the inputs is a NoData value
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

add

public Grid2DSquareCellDouble add(Grid2DSquareCellDouble grid0,
                                  Grid2DSquareCellDouble grid1,
                                  boolean data,
                                  Grid2DSquareCellDoubleFactory gridFactory,
                                  boolean handleOutOfMemoryError)
TODO: 1. Documentiation 2. Change so Grid2DSquareCellDouble are Grid2DSquareCellAbstract

Parameters:
data - controls if result is produced even if one of the inputs is a NoData value
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.
See Also:
addToGrid(Grid2DSquareCellDouble,Grid2DSquareCellDouble,boolean)

multiply

public Grid2DSquareCellDouble multiply(Grid2DSquareCellDouble grid0,
                                       Grid2DSquareCellDouble grid1,
                                       Grid2DSquareCellDoubleFactory gridFactory,
                                       boolean handleOutOfMemoryError)
Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: 1. Documentiation 2. Change so Grid2DSquareCellDouble are Grid2DSquareCellAbstract

divide

public Grid2DSquareCellDouble divide(Grid2DSquareCellDouble grid0,
                                     Grid2DSquareCellDouble grid1,
                                     Grid2DSquareCellDoubleFactory gridFactory,
                                     double defaultValue,
                                     boolean handleOutOfMemoryError)
Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: 1. Documentiation 2. Change so Grid2DSquareCellDouble are Grid2DSquareCellAbstract

aggregate

public Grid2DSquareCellDouble aggregate(Grid2DSquareCellDouble grid,
                                        int cellFactor,
                                        java.lang.String statistic,
                                        int rowOffset,
                                        int colOffset,
                                        Grid2DSquareCellDoubleFactory gridFactory,
                                        boolean handleOutOfMemoryError)
Returns an Grid2DSquareCellDouble at a lower level of resolution than grid. The result values are either the sum, mean, max or min of values in grid depending on statistic.

Parameters:
grid - the Grid2DSquareCellDouble to be processed
cellFactor - the number of times wider/higher the aggregated grid cells are to be
statistic - "sum", "mean", "max", or "min" depending on what aggregate of values are wanted
rowOffset - the number of rows above or below the origin of grid where the aggregation is to start. > 0 result yllcorner will be above grid yllcorner < 0 result yllcorner will be below grid yllcorner
colOffset - the number of columns above or below the origin of grid where the aggregation is to start. > 0 result xllcorner will be right of grid xllcorner < 0 result xllcorner will be left of grid xllcorner
gridFactory - the Abstract2DSquareCellDoubleFactory used to create result and temporary AbstractGrid2DSquareCellDoubles.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. NB. In the calculation of the sum and the mean if there is a cell in grid which has a data value then the result which incorporates that cell has a data value. For this result cell, any of the cells in grid which have noDataValues their value is taken as that of the average of its nearest cells with a value. In the calculation of the max and the min noDataValues are simply ignored. Formerly noDataValues were treated as the average of values within a result cell. TODO: implement median, mode and variance aggregations.

aggregate

public Grid2DSquareCellDouble aggregate(Grid2DSquareCellDouble grid,
                                        java.lang.String statistic,
                                        java.math.BigDecimal[] resultDimensions,
                                        Grid2DSquareCellDoubleFactory gridFactory,
                                        boolean handleOutOfMemoryError)
Returns an Grid2DSquareCellDouble at a lower level of resolution than grid. The result values are either the sum, mean, max or min of values in grid depending on statistic.

Parameters:
grid - The Grid2DSquareCellDouble to be processed
statistic - "sum", "mean", "max", or "min" depending on what aggregate of values are wanted
resultDimensions -
gridFactory - The Abstract2DSquareCellDoubleFactory used to create grids
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. Use this aggregate method if result is to have a new spatial frame. NB. In the calculation of the sum and the mean if there is a cell in grid which has a data value then the result which incorporates that cell has a data value. For this result cell, any of the cells in grid which have noDataValues their value is taken as that of the average of its nearest cells with a value. In the calculation of the max and the min noDataValues are simply ignored. Formerly noDataValues were treated as the average of values within a result cell. TODO: implement median, mode and variance aggregations.

distanceToDataValue

public Grid2DSquareCellDouble distanceToDataValue(Grid2DSquareCellDouble grid0,
                                                  Grid2DSquareCellDoubleFactory gridFactory,
                                                  boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellDouble the values of which are the distance to the nearest data value TODO: Optimise as it is currently very slow and inefficient!!!

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getRowProcessInitialData

protected double[][] getRowProcessInitialData(Grid2DSquareCellDouble grid,
                                              int cellDistance,
                                              long row)
Returns a double[][] of grid values


getRowProcessData

protected double[][] getRowProcessData(Grid2DSquareCellDouble grid,
                                       double[][] previous,
                                       int cellDistance,
                                       long row,
                                       long col)
Returns a double[][] based on previous which has been shuffled

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.