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

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.grids.core.OutOfMemoryErrorHandler
      extended by uk.ac.leeds.ccg.andyt.grids.process.Grid2DSquareCellProcessor
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ESRIAsciiGridImporter, GenerateTestData, Grid2DSquareCellProcessorDEM, Grid2DSquareCellProcessorGWS, UtilitiesRuns

public class Grid2DSquareCellProcessor
extends OutOfMemoryErrorHandler

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
 Grid2DSquareCellDoubleChunk64CellMapFactory grid2DSquareCellDoubleChunk64CellMapFactory
          Grid2DSquareCellDoubleChunk64CellMapFactory
 Grid2DSquareCellDoubleChunkArrayFactory grid2DSquareCellDoubleChunkArrayFactory
          Grid2DSquareCellDoubleChunkArrayFactory
 Grid2DSquareCellDoubleChunkAbstractFactory grid2DSquareCellDoubleChunkFactory
          Default Grid2DSquareCellDoubleChunkAbstractFactory
 Grid2DSquareCellDoubleChunkJAIFactory grid2DSquareCellDoubleChunkJAIFactory
          Grid2DSquareCellDoubleChunkJAIFactory
 Grid2DSquareCellDoubleChunkMapFactory grid2DSquareCellDoubleChunkMapFactory
          Grid2DSquareCellDoubleChunkMapFactory
 Grid2DSquareCellDoubleChunkRAFFactory grid2DSquareCellDoubleChunkRAFFactory
          Grid2DSquareCellDoubleChunkRAFFactory
 Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory
          Grid2DSquareCellDoubleFactory
 Grid2DSquareCellIntChunk64CellMapFactory grid2DSquareCellIntChunk64CellMapFactory
          Grid2DSquareCellIntChunk64CellMapFactory
 Grid2DSquareCellIntChunkArrayFactory grid2DSquareCellIntChunkArrayFactory
          Grid2DSquareCellIntChunkArrayFactory
 Grid2DSquareCellIntChunkAbstractFactory grid2DSquareCellIntChunkFactory
          Default Grid2DSquareCellIntChunkAbstractFactory
 Grid2DSquareCellIntChunkJAIFactory grid2DSquareCellIntChunkJAIFactory
          Grid2DSquareCellIntChunkJAIFactory
 Grid2DSquareCellIntChunkMapFactory grid2DSquareCellIntChunkMapFactory
          Grid2DSquareCellIntChunkMapFactory
 Grid2DSquareCellIntChunkRAFFactory grid2DSquareCellIntChunkRAFFactory
          Grid2DSquareCellIntChunkRAFFactory
 Grid2DSquareCellIntFactory grid2DSquareCellIntFactory
          Grid2DSquareCellIntFactory
 java.util.HashSet grid2DSquareCells
          A collection of the Grid2dSquareCellAbstracts being processed
 GridStatisticsAbstract gridStatistics
          GridStatistics1
 GridStatistics0 gridStatistics0
          GridStatistics0
 GridStatistics1 gridStatistics1
          GridStatistics1
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.core.OutOfMemoryErrorHandler
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 appendToLogFile)
          Creates a new instance of Grid2DSquareCellDoubleProcessor.
 
Method Summary
 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(Grid2DSquareCellAbstract grid2DSquareCell, 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(Grid2DSquareCellAbstract grid2DSquareCell, java.lang.String statistic, java.math.BigDecimal[] resultDimensions, Grid2DSquareCellDoubleFactory gridFactory, boolean handleOutOfMemoryError)
          Returns an Grid2DSquareCellDouble at a lower level of resolution than grid.
 double angle(double x1, double y1, double x2, double y2, boolean handleOutOfMemoryError)
          Returns the clockwise angle in radians to the y axis of the line from (x1,y1) to (x2,y2).
 void copyAndSetUpNewLog(java.io.File newLog, boolean handleOutOfMemoryError)
          Copies and sets up a new log.
 double distance(double x1, double y1, double x2, double y2, boolean handleOutOfMemoryError)
          Returns the distance between a pair of coordinates
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(boolean handleOutOfMemoryError)
          Returns a copy of this.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]
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell, double min, double max, boolean handleOutOfMemoryError)
          Returns grid2DSquareCell with the values of cells in the range [min,max] set to its noDataValue.
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell, 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.
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell, Grid2DSquareCellAbstract mask, Grid2DSquareCellAbstractFactory grid2DSquareCellAbstractFactory, boolean handleOutOfMemoryError)
          If grid2DSquareCellAbstractFactory is null then grid2DSquareCell is directly masked and returned, otherwise a new Grid2DSquareCellAbstract result is contructed using grid2DSquareCellAbstractFactory.
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCellToMask, Grid2DSquareCellAbstract grid2DSquareCellMask, GridStatisticsAbstract resultGridStatistics, java.io.File resultDirectory, boolean handleOutOfMemoryError)
          Returns a new Grid2DSquareCellAbstract which is of the same type and chunk stucture as grid2DSquareCellMask.
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell, 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.
 Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid, long startRowIndex, long startColIndex, long endRowIndex, long endColIndex, Grid2DSquareCellAbstractFactory grid2DSquareCellFactory, 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 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.
 void swapToFileGrid2DSquareCellChunk(boolean handleOutOfMemoryError)
          Attempts to swap to file and clear from the cache a chunk in this.grid2DSquareCells
 void swapToFileGrid2DSquareCellChunks()
           
 void swapToFileGrid2DSquareCellChunks(boolean handleOutOfMemoryError)
          Attempts to swap to file and clear from cache seriailsed version of all this.grid2DSquareCells chunks.
 
Methods inherited from class uk.ac.leeds.ccg.andyt.grids.core.OutOfMemoryErrorHandler
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

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


grid2DSquareCellIntChunkFactory

public Grid2DSquareCellIntChunkAbstractFactory grid2DSquareCellIntChunkFactory
Default Grid2DSquareCellIntChunkAbstractFactory


grid2DSquareCellIntChunk64CellMapFactory

public Grid2DSquareCellIntChunk64CellMapFactory grid2DSquareCellIntChunk64CellMapFactory
Grid2DSquareCellIntChunk64CellMapFactory


grid2DSquareCellIntChunkArrayFactory

public Grid2DSquareCellIntChunkArrayFactory grid2DSquareCellIntChunkArrayFactory
Grid2DSquareCellIntChunkArrayFactory


grid2DSquareCellIntChunkJAIFactory

public Grid2DSquareCellIntChunkJAIFactory grid2DSquareCellIntChunkJAIFactory
Grid2DSquareCellIntChunkJAIFactory


grid2DSquareCellIntChunkMapFactory

public Grid2DSquareCellIntChunkMapFactory grid2DSquareCellIntChunkMapFactory
Grid2DSquareCellIntChunkMapFactory


grid2DSquareCellIntChunkRAFFactory

public Grid2DSquareCellIntChunkRAFFactory grid2DSquareCellIntChunkRAFFactory
Grid2DSquareCellIntChunkRAFFactory


grid2DSquareCellIntFactory

public Grid2DSquareCellIntFactory grid2DSquareCellIntFactory
Grid2DSquareCellIntFactory


grid2DSquareCellDoubleChunkFactory

public Grid2DSquareCellDoubleChunkAbstractFactory grid2DSquareCellDoubleChunkFactory
Default Grid2DSquareCellDoubleChunkAbstractFactory


grid2DSquareCellDoubleChunk64CellMapFactory

public Grid2DSquareCellDoubleChunk64CellMapFactory grid2DSquareCellDoubleChunk64CellMapFactory
Grid2DSquareCellDoubleChunk64CellMapFactory


grid2DSquareCellDoubleChunkArrayFactory

public Grid2DSquareCellDoubleChunkArrayFactory grid2DSquareCellDoubleChunkArrayFactory
Grid2DSquareCellDoubleChunkArrayFactory


grid2DSquareCellDoubleChunkJAIFactory

public Grid2DSquareCellDoubleChunkJAIFactory grid2DSquareCellDoubleChunkJAIFactory
Grid2DSquareCellDoubleChunkJAIFactory


grid2DSquareCellDoubleChunkMapFactory

public Grid2DSquareCellDoubleChunkMapFactory grid2DSquareCellDoubleChunkMapFactory
Grid2DSquareCellDoubleChunkMapFactory


grid2DSquareCellDoubleChunkRAFFactory

public Grid2DSquareCellDoubleChunkRAFFactory grid2DSquareCellDoubleChunkRAFFactory
Grid2DSquareCellDoubleChunkRAFFactory


grid2DSquareCellDoubleFactory

public Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory
Grid2DSquareCellDoubleFactory


gridStatistics0

public GridStatistics0 gridStatistics0
GridStatistics0


gridStatistics1

public GridStatistics1 gridStatistics1
GridStatistics1


gridStatistics

public GridStatisticsAbstract gridStatistics
GridStatistics1

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 appendToLogFile)
Creates a new instance of Grid2DSquareCellDoubleProcessor. The log file in workspace will be overwritten if appendToLogFile is false.

Parameters:
workspace -
appendToLogFile -
Method Detail

getTime0

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


getWorkspace

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


getGrid2DSquareCells

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


swapToFileGrid2DSquareCellChunk

public final void swapToFileGrid2DSquareCellChunk(boolean handleOutOfMemoryError)
Attempts to swap to file and clear from the cache a chunk in this.grid2DSquareCells

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

swapToFileGrid2DSquareCellChunks

public final void swapToFileGrid2DSquareCellChunks(boolean handleOutOfMemoryError)
Attempts to swap to file and clear from cache seriailsed version of all this.grid2DSquareCells chunks.

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

swapToFileGrid2DSquareCellChunks

public final void swapToFileGrid2DSquareCellChunks()

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 swap 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 swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

copyAndSetUpNewLog

public void copyAndSetUpNewLog(java.io.File newLog,
                               boolean handleOutOfMemoryError)
                        throws java.io.IOException
Copies and sets up a new log.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.
Throws:
java.io.IOException

log

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

Parameters:
string - The message to log.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap 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:
logIndentation - The indentation of string.
string - The message to log.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

distance

public final double distance(double x1,
                             double y1,
                             double x2,
                             double y2,
                             boolean handleOutOfMemoryError)
Returns the distance between a pair of coordinates

Parameters:
x1 - - the x coordinte of one point
y1 - - the y coordinte of one point
x2 - - the x coordinte of another point
y2 - - the y coordinte of another point
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

angle

public final double angle(double x1,
                          double y1,
                          double x2,
                          double y2,
                          boolean handleOutOfMemoryError)
Returns the clockwise angle in radians to the y axis of the line from (x1,y1) to (x2,y2).

Parameters:
x1 - - the x coordinte of one point
y1 - - the y coordinte of one point
x2 - - the x coordinte of another point
y2 - - the y coordinte of another point
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCellToMask,
                                     Grid2DSquareCellAbstract grid2DSquareCellMask,
                                     GridStatisticsAbstract resultGridStatistics,
                                     java.io.File resultDirectory,
                                     boolean handleOutOfMemoryError)
Returns a new Grid2DSquareCellAbstract which is of the same type and chunk stucture as grid2DSquareCellMask.

Parameters:
grid2DSquareCellToMask - The Grid2DSquareCellAbstract that is copied for masking.
grid2DSquareCellMask - The Grid2DSquareCellAbstract to use as a mask.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. Warning!!! The grid2DSquareCellToMask and grid2DSquareCellMask are assumed to be coincident and have the same origin.

mask

public Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell,
                                     Grid2DSquareCellAbstract mask,
                                     Grid2DSquareCellAbstractFactory grid2DSquareCellAbstractFactory,
                                     boolean handleOutOfMemoryError)
If grid2DSquareCellAbstractFactory is null then grid2DSquareCell is directly masked and returned, otherwise a new Grid2DSquareCellAbstract result is contructed using grid2DSquareCellAbstractFactory. Essentially this is a copy of grid2DSquareCell, masked using mask. Masking involves setting result cell values to it's noDataValue if the cells are conicident with mask cells with mask.noDataValue value. Warning: If returned Grid2DSquareCellAbstract is not same class as grid2DSquareCell some generalisation may have occured in addition to masking.

Parameters:
grid2DSquareCell - The Grid2DSquareCellAbstract to be masked.
mask - The Grid2DSquareCellAbstract mask.
grid2DSquareCellAbstractFactory - the Grid2DSquareCellAbstractFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

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

Parameters:
grid2DSquareCell - 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 swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell,
                                     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:
grid2DSquareCell - the Grid2DSquareCellAbstract 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 swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid2DSquareCell,
                                     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:
grid2DSquareCell - 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 swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

mask

public Grid2DSquareCellAbstract mask(Grid2DSquareCellAbstract grid,
                                     long startRowIndex,
                                     long startColIndex,
                                     long endRowIndex,
                                     long endColIndex,
                                     Grid2DSquareCellAbstractFactory grid2DSquareCellFactory,
                                     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.
grid2DSquareCellFactory - The Grid2DSquareCellAbstractFactory used to generate result.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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 swap 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.
dimensionConstraints -
weight - The value grid2DSquareCellDoubleToAdd values are multiplied by.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then swap 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 swap operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

aggregate

public Grid2DSquareCellDouble aggregate(Grid2DSquareCellAbstract grid2DSquareCell,
                                        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:
grid2DSquareCell - 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 swap 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(Grid2DSquareCellAbstract grid2DSquareCell,
                                        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:
grid2DSquareCell - 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 swap 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.

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