CoarseGrid
This class encapsulates a lowerresolution grid and makes it visible as a higherresolution grid. Only exact subsampling by a constant factor per dimension is supported.
This class is useful when combining information of grids of different sizes. This is often the case for chemotaxis, where we let diffusion occur on a lower resolution grid to speed things up. This class then allows you to obtain chemokine information from the low resolution chemokine grid using coordinates from the linked, higher resolution model grid.
Example:
let CPM = require( "path/to/build" )
// Define a grid with float values for chemokine values, and set the middle pixel
let chemogrid = new CPM.Grid2D( [50,50], [true,true], "Float32" )
chemogrid.setpix( [99,99], 100 )
// Make a coarse grid at 5x as high resolution, which is then 500x500 pixels.
let coarsegrid = new CPM.CoarseGrid( chemogrid, 5 )
// Use interpolation. Pixels close to the midpoint won't have the exact same
// value of either 100 or 0, but something inbetween.
let p1 = [250,250], p2 = [250,251]
console.log( "p1 : " + coarsegrid.pixt(p1) + ", p2 : " + coarsegrid.pixt(p2) )
// p1 : 100, p2 : 80
// Or draw it to see this. Compare these two:
let Cim1 = new CPM.Canvas( coarsegrid )
Cim1.drawField()
let Cim2 = new CPM.Canvas( chemogrid, {zoom:5} )
Cim2.drawField()
Constructor Summary
Public Constructor  
public 
constructor(grid: Grid2D, upscale: number) The constructor of class CoarseGrid takes a low resolution grid as input and a factor 'upscale', which is how much bigger the dimensions of the high resolution grid are (must be a constant factor). 
Member Summary
Public Members  
public 
Size of the new grid in all dimensions. 

public 
The original, lowresolution grid. 
Private Members  
private 
The upscale factor (a positive integer number). 
Method Summary
Public Methods  
public 
addValue(p: ArrayCoordinate, value: number) This method takes as input a coordinate on the bigger grid, and 'adds' additional value to it by adding the proper amount to the corresponding positions on the low resolution grid. 

public 
pixt(p: ArrayCoordinate): number The pixt method takes as input a coordinate on the bigger grid, and maps it to the corresponding value on the resized small grid via bilinear interpolation. 
Inherited Summary
From class Grid  
private get 
_pixels: Uint16Array  Float32Array: * Return the array this._pixelArray, which should be set in the grid subclass. 

private set 
_pixels(pixels: Uint16Array  Float32Array) Set or update the private this._pixelArray. 

public 
datatype: * 

public 
field_size array of field size in each dimension. 

public 
Array coordinates to the middle pixel on the grid. 

public 
Number of dimensions of the grid. 

public 
Should the borders of the grid be linked, so that a cell moving out on the left reappears on the right? Warning: setting to false can give artifacts if done incorrectly. 

private 
_pixelArray: * Array with values for each pixel stored at the position of its IndexCoordinate. 

private 
For storing a copy of all pixel values; eg for synchronous updating of some sort. 

public 
Apply a function to all pixel values on the grid. 

public 
Method to check if a given ArrayCoordinate falls within the bounds of this grid. 

public 
Method to correct an ArrayCoordinate outside the grid dimensions when the grid is wrapped (torus = true). 

public 
Perform a diffusion step on the grid, updating the values of all pixels according to Fick's second law of diffusion. 

public 
Method to compute the gradient at location p on the grid (location given in array coordinates). 

public 
gradienti(i: IndexCoordinate): number[] Template method to compute the gradient at location i on the grid (location given in index coordinates). 

public abstract 
Method for conversion from an IndexCoordinate to an ArrayCoordinate. 

public 
Method to compute the laplacian at location p on the grid (location given in array coordinates). 

public 
Method to compute the laplacian at location i on the grid (location given in index coordinates). 

public 
multiplyBy(r: number) Multiply all pixel values on the grid with a constant factor r. 

public 
neigh(p: ArrayCoordinate, torus: boolean[]): ArrayCoordinate[] The neigh method returns the neighborhood of a pixel p. 

public abstract 
* neighNeumanni(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] A method to compute the Neumann neighborhood should be implemented in the Grid subclass if the laplacian (see below) is used. 

public abstract 
neighi(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] Method returning the (Moore) neighborhood of a pixel based on its IndexCoordinate. 

public abstract 
Method for conversion from an ArrayCoordinate to an IndexCoordinate. 

public abstract 
This iterator returns locations and values of all nonzero pixels. 

public 
This method preallocates an array of the correct datatype to make a copy of the current pixel values. 

public abstract 
* pixelsi(): IndexCoordinate This iterator returns locations all pixels including background. 

public 
pixt(p: ArrayCoordinate): number The pixt method finds the current value of a pixel p on the grid. 

public 
pixti(i: IndexCoordinate): number The pixti method finds the current value of a pixel i on the grid. 

public 
setpix(p: ArrayCoordinate, t: number) The setpix method changes the value of a pixel p on the grid to t. 

public 
setpixi(i: IndexCoordinate, t: number) The setpixi method changes the value of a pixel i on the grid to t. 

private 
_isValidValue(t: number, tol: number): void Check if a value is valid on this type of grid. 
From class Grid2D  
public 
datatype: * 

private 
Array with values for each pixel stored at the position of its IndexCoordinate. 

public 
gradienti(i: IndexCoordinate): number[] Method to compute the gradient at location i on the grid (location given as an IndexCoordinate). 

public 
Method for conversion from an IndexCoordinate to an ArrayCoordinate. 

public 
* neighNeumanni(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] Return array of IndexCoordinate of von Neumann4 neighbor pixels of the pixel at coordinate i. 

public 
neighi(i: IndexCoordinate, torus: boolean[]): IndexCoordinate[] Return array of IndexCoordinate of Moore8 neighbor pixels of the pixel at coordinate i. 

public 
Method for conversion from an ArrayCoordinate to an IndexCoordinate. 

public 
This iterator returns locations and values of all nonzero pixels. 

public 
* pixelsi(): IndexCoordinate This iterator returns locations and values of all pixels. 
Public Constructors
public constructor(grid: Grid2D, upscale: number) source
The constructor of class CoarseGrid takes a low resolution grid as input and a factor 'upscale', which is how much bigger the dimensions of the high resolution grid are (must be a constant factor).
Override:
Grid2D#constructorPublic Members
Private Members
Public Methods
public addValue(p: ArrayCoordinate, value: number) source
This method takes as input a coordinate on the bigger grid, and 'adds' additional value to it by adding the proper amount to the corresponding positions on the low resolution grid.
Params:
Name  Type  Attribute  Description 
p  ArrayCoordinate  array coordinates on the high resolution grid. 

value  number  value that should be added to this position. 
public pixt(p: ArrayCoordinate): number source
The pixt method takes as input a coordinate on the bigger grid, and maps it to the corresponding value on the resized small grid via bilinear interpolation. This prevents artefacts from the lower resolution of the second grid: the [upscale x upscale] pixels that map to the same pixel in the low resolution grid do not get the same value.
Override:
Grid#pixtParams:
Name  Type  Attribute  Description 
p  ArrayCoordinate  array coordinates on the high resolution grid. 