Class GeoGridModel
java.lang.Object
com.eco.bio7.compile.Model
com.eco.bio7.simulation.Simulation
com.eco.bio7.simulation.GridModel
com.eco.bio7.simulation.GeoGridModel
A simulation on a georeferenced grid (a geospatial model, e.g., a wildfire
on a terrain, a runoff or a species dispersal): the grid and its data layers
are read with GDAL in Bio7 (rasters and vectors in any format of GDAL, e.g.,
GeoTIFF, GeoPackage, Shapefile, GeoJSON) and resampled or rasterized to the
cells. The cells have states (as a
GridModel) and the model can show
a layer of values with a color map (showValues(double[], double, double, String...)).
The data is loaded in load() (once, before the first init):
protected void load() {
grid("data/geo/dem.tif", 200); // the grid: the extent and the coordinate system of the raster, 200 columns
addLayer("elevation", raster("data/geo/dem.tif")); // a raster on the cells (bilinear)
addLayer("lakes", vector("data/geo/lakes.geojson", 1)); // vectors on the cells (1 inside, 0 outside)
}
init() and step() use the layers with layer(String) (a copy for each
setup, the model can change it). Relative paths are found in the project of
the model.
The HTML export embeds the loaded layers (the page needs no GDAL) and shows the grid on a map (OpenStreetMap and other base maps, online). load() is not exported: compile and run the model in Bio7 before the export.
-
Nested Class Summary
Nested classes/interfaces inherited from class Simulation
Simulation.DerivativesModifier and TypeClassDescriptionstatic interfaceThe derivatives of a system of differential equations: dy/dt = f(t, y). -
Field Summary
FieldsModifier and TypeFieldDescriptiondoubleThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up).doubleThe size of a cell on the ground in meters (approximately, at the center of the grid).doubleThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up).The coordinate system of the grid (WKT).doubleThe geographic bounds of the grid (WGS84 degrees).doubleThe geographic bounds of the grid (WGS84 degrees).doubleThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up).doubleThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up).doubleThe geographic bounds of the grid (WGS84 degrees).doubleThe geographic bounds of the grid (WGS84 degrees).Fields inherited from class GridModel
agents, cells, height, next, width, wrapModifier and TypeFieldDescriptionThe agents on the grid (turtles on the patches, seeGridAgent), drawn on top of the grid; Setup removes them.int[]The states of the cells (index y * width + x).intThe size of the grid (cells).int[]The next states (written with setNext, exchanged with swap()).intThe size of the grid (cells).booleantrue: the grid is a torus (the neighbors wrap at the borders), false: outside cells are 0.Fields inherited from class Simulation
arrangeViews, DEFAULT_SEED, tModifier and TypeFieldDescriptionbooleantrue (default): the first setup arranges the views in the Custom perspective of Bio7: the display of the model (ImageJ, the 3D view or the WorldWind globe) on the right, its options (e.g., Options3D) top left and the settings left.static final intThe seed of the random numbers (set it in init() with seed(...)).intThe number of the time steps since the setup. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds a layer (e.g., of raster or vector) for init() and step().protected voidattribution(String text) The sources of the data (shown on the map of the HTML export, e.g., "Elevation: SRTM"): the attribution which the licenses of the data require (the export embeds the data in the page).intcolAt(double lon, double lat) The column of the cell at the longitude and latitude (WGS84), -1 outside.protected voiddisplay()Displays the model (ImageJ image or 3D view).The loaded data for the HTML export: the grid, the bounds and the layers.doublegradient(double[] layer, int x, int y) The gradient (rise / run, e.g., 0.1 = 10 %) of a layer (e.g., the elevation in meters) at the cell (central differences, the borders are repeated).protected voidDefines the grid by a raster: its extent and coordinate system, the number of the columns (the rows from the aspect of the raster).doublelat(int y) The latitude of the center of the row (WGS84).double[]The layer (a copy of the loaded data for this setup, index y * width + x), null if unknown.protected abstract voidload()Loads the grid and the layers with GDAL (in Bio7, once before the first init; not exported: the page gets the loaded layers).doublelon(int x) The longitude of the center of the column (WGS84).protected voidPrepares the display before init() (called in the thread of the user interface).protected double[]The first band of a raster on the cells (bilinear resampling, no data: NaN).protected double[]A band of a raster on the cells (reprojected to the grid if needed).introwAt(double lon, double lat) The row of the cell at the longitude and latitude (WGS84), -1 outside.protected voidShows the grid also on the WorldWind globe of Bio7 (call it in load(); the WorldWind perspective is opened and the globe flies to the area).voidShows the states with the palette (the default).voidshowValues(double[] values, double min, double max, String... colors) Shows the values (e.g., a layer or a field of the model) with a color map instead of the states.doubleslopeDegrees(double[] layer, int x, int y) The slope of a layer at the cell in degrees.doublevalue(double[] layer, int x, int y) The value of a layer at the cell (the nearest cell at the borders).protected double[]Vectors (points, lines, polygons) on the cells: the value inside, 0 outside.protected double[]Vectors on the cells with the value of an attribute (a number field), 0 outside.Methods inherited from class GridModel
addAgent, agentDistance, agentsAt, agentsNear, count, count4, countAgentsAt, countNeighbors, face, forward, get, getDrawing, getImage, moveTo, palette, removeAgent, set, setNext, size, swapModifier and TypeMethodDescription<A extends GridAgent>
AaddAgent(A agent) Adds an agent (e.g., an own subclass of GridAgent) and returns it.doubleagentDistance(GridAgent a, GridAgent b) The distance of two agents in cells (the shortest way on a torus).agentsAt(int x, int y) The agents in the cell (x, y).agentsNear(GridAgent agent, double radius) The other agents within the radius (cells) of the agent.intcount(int state) The number of the cells with the state.intcount4(int x, int y, int state) The number of the 4 neighbors (left, right, up, down: von Neumann neighborhood) with the state.intcountAgentsAt(int x, int y) The number of the agents in the cell (x, y).intcountNeighbors(int x, int y, int state) The number of the 8 neighbors (Moore neighborhood) with the state.voidTurns the agent to the position (cells; the shortest way on a torus).voidMoves the agent in its heading (0 up, clockwise): on a torus (wrap) or it stops at the edge.intget(int x, int y) The state of a cell (wraps at the borders with wrap = true, else 0 outside).List<com.eco.bio7.simulation.Shape> The shapes of the step and (on top) the agents.ij.ImagePlusgetImage()The ImageJ image of the grid (null before the first display).voidMoves the agent to the position (cells; on a torus or limited to the grid).voidThe colors of the states 0, 1, 2, ...voidremoveAgent(GridAgent agent) Removes an agent.voidset(int x, int y, int state) Sets the state of a cell (now).voidsetNext(int x, int y, int state) Sets the next state of a cell (visible after swap()).voidsize(int w, int h) Creates a grid of w * h cells (all 0).voidswap()Exchanges the cells and the next states (after all cells got their next state).Methods inherited from class Simulation
chance, chart, chart, chartBars, chartXY, clamp, click, correlation, cosDeg, determinant, distance, distance3, dot, drag, drawBox, drawCircle, drawCircle, drawImage, drawImage, drawLine, drawLine, drawLine3, drawPath, drawPath, drawPath3, drawPillar, drawPoint3, drawPolygon, drawPolygon, drawPolygon3, drawRect, drawRect, drawSphere, drawText, drawText, fractalNoise, getCharts, getImageFiles, getModelFiles, getSeries, getStartSeed, headingOf, init, inverse, isStopped, key, lerp, linearRegression, loadImage, loadModel, logistic, logisticGrowth, mapRange, matMul, matVec, max, mean, mean, median, min, noise, norm, normalCdf, normalPdf, quantile, random, random, randomAt, randomAt, randomBinomial, randomElement, randomExponential, randomGaussian, randomGaussian, randomInt, randomInt, randomPoisson, randomWeighted, record, rk4, run, sd, seed, setStartSeed, settings, setup, shuffle, sinDeg, solve, sq, startAfterCreation, step, stop, sum, sum, transpose, variance, wrapAroundModifier and TypeMethodDescriptionbooleanchance(double p) true with the probability p (e.g., chance(0.1): in 10 % of the calls).voidA value of a series of the first chart (one value per step; the Charts view of Bio7 and the HTML page).voidA value of a series of another chart with a title (a second, third, ...voidA bar chart with a title: the labels and the values (replaced in each call, e.g., a histogram).voidA point (x, y) of a series of an XY chart with a title (e.g., a phase plot of two populations).static doubleclamp(double value, double min, double max) The value limited to [min, max].voidclick(double x, double y) A click of the mouse in the view of the model (override it): for a grid the position in cells (the cell((int) x, (int) y), y from the top as in get(x, y)), for an agent model the point on the floor of the box.static doublecorrelation(double[] x, double[] y) The correlation coefficient of Pearson.static doublecosDeg(double deg) The cosine of an angle in degrees (the same digits in Bio7 and in the browser, e.g., for a movement in the heading).static doubledeterminant(double[][] a) The determinant of a matrix.static doubledistance(double x1, double y1, double x2, double y2) The distance of two points in 2D.static doubledistance3(double x1, double y1, double z1, double x2, double y2, double z2) The distance of two points in 3D.static doubledot(double[] a, double[] b) The dot product of two vectors.voiddrag(double x, double y) A drag of the mouse in the view of the model (override it), e.g., to paint cells: called for the position where the drag started and for each further position (a grid: each new cell).voidA box in 3D (an agent model): the corner x, y, z (the lowest values), the width (x), the height (y) and the depth (z, upwards) as in box(...); fill: the color of the sides, stroke: the color of the edges (null: none), e.g., a house or a tower.voiddrawCircle(double x, double y, double radius, String fill, String stroke) A circle (a geospatial agent model: the radius in km).voiddrawCircle(double x, double y, double radius, String fill, String stroke, double z) A circle at the height z above the floor (an agent model).voidAn image (loaded with loadImage) centered at x, y: the size (the larger side, in cells of a grid, in pixels on a map or the globe) and the angle in degrees (clockwise, e.g., the heading of an animal).voidAn image at the height z above the floor (an agent model: the lower edge of the image, standing).voidA line (the width in pixels).voidA line at the height z above the floor (an agent model).voiddrawLine3(double x1, double y1, double z1, double x2, double y2, double z2, String color, double width) A line in 3D (an agent model: x, y, z of the box).voidA line through the points (e.g., the track of an agent).voidA line through the points at the height z above the floor (an agent model).voidA line through the points in 3D (an agent model; the width in pixels), e.g., a flight path.voiddrawPillar(double x, double y, double radius, double height, String color) A pillar in 3D (an agent model: a vertical cylinder from the floor at x, y of the box with the radius and the height, e.g., an obstacle; color: e.g., "#9aa6b8").voiddrawPoint3(double x, double y, double z, double size, String color) A point in 3D (an agent model): a small sphere with the diameter size, e.g., a marker.voiddrawPolygon(double[] xs, double[] ys, String fill, String stroke) A polygon (the fill and the color of the line, null: none; e.g., a pasture or a territory).voiddrawPolygon(double[] xs, double[] ys, String fill, String stroke, double z) A polygon at the height z above the floor (an agent model).voiddrawPolygon3(double[] xs, double[] ys, double[] zs, String fill, String stroke) A flat polygon in 3D (an agent model; the points should lie in a plane): the fill and the color of the outline (null: none), e.g., a roof or a ramp.voidA rectangle (x, y: the upper left corner of a grid).voidA rectangle at the height z above the floor (an agent model).voiddrawSphere(double x, double y, double z, double radius, String fill) A sphere in 3D (an agent model): the center and the radius, e.g., a balloon or a tree crown.voidA text (the size in cells of a grid, in pixels on a map or the globe).voidA text at the height z above the floor (an agent model, e.g., a label above an object).static doublefractalNoise(double x, double y, int octaves) A fractal noise (0 - 1): the sum of octaves of noise (finer details with more octaves).List<com.eco.bio7.simulation.ChartData> Copies of all charts (the first chart has the title "").The images loaded with loadImage (the name and the file).The 3D models loaded with loadModel (the name and the file).The values of the series of the first chart (name: [step, value] pairs).intThe seed of the setup (default 42; the field Seed of the settings in Bio7).static doubleheadingOf(double dx, double dy) The heading of a movement (dx, dy) in degrees: 0 the direction of y, clockwise (as the angle of drawImage and the heading of the agents).abstract voidinit()Creates the start state (called by the Setup button and after the compilation).static double[][]inverse(double[][] a) The inverse matrix (NaN if the matrix is singular).booleanTrue if stop() was called in the last step (or in init()).voidA key pressed in the view of the model (override it): a character ("a", "A", "1", " ") or the name of a special key ("ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter", "Escape", "Backspace", "Delete", "Tab"; the names of the key of JavaScript).static doublelerp(double a, double b, double t) The linear interpolation between a and b (t = 0: a, t = 1: b).static double[]linearRegression(double[] x, double[] y) The linear regression y = a + b x: the intercept a, the slope b and the coefficient of determination r².voidLoads an image (PNG with transparency, JPEG) for drawImage and the agents (agent.image = name).voidLoads a 3D model (glTF: .glb or .gltf, also animated; Wavefront OBJ with the materials and textures of its .mtl file, y up; STL, binary or ASCII, z up) for the agents (agent.model = name, agent.animation = the name of an animation) and placeModel.static doublelogistic(double x) The logistic function 1 / (1 + e^-x) (e.g., a smooth switch from 0 to 1).static doublelogisticGrowth(double n, double r, double k) The logistic growth of a population per time unit: r * n * (1 - n / k).static doublemapRange(double value, double inMin, double inMax, double outMin, double outMax) The value of the range [inMin, inMax] in the range [outMin, outMax] (linear).static double[][]matMul(double[][] a, double[][] b) The product of two matrices (rows of columns).static double[]matVec(double[][] a, double[] v) The product of a matrix and a vector (e.g., a Leslie matrix and the age classes).static doublemax(double[] values) The maximum of the values (-Infinity if empty).static doublemean(double[] values) The mean of the values (0 if empty).static doublemean(int[] values) The mean of the values (0 if empty).static doublemedian(double[] values) The median of the values.static doublemin(double[] values) The minimum of the values (Infinity if empty).static doublenoise(double x, double y) A smooth noise (0 - 1) at x, y (value noise: e.g., a landscape, the grass of a pasture; the same in the browser).static doublenorm(double[] a) The length of a vector.static doublenormalCdf(double x, double mean, double sd) The distribution function of the normal distribution (an accuracy of about 1e-7).static doublenormalPdf(double x, double mean, double sd) The density of the normal distribution.static doublequantile(double[] values, double p) The quantile p (0 - 1) of the values (linear interpolation of the sorted values).doublerandom()A random number in [0, 1) (the same numbers in Java and in the HTML export).doublerandom(double min, double max) A random number in [min, max).doublerandomAt(int index) A random number in [0, 1) for an index (e.g., of a cell or an agent) in this time step: computed from the seed, the time step and the index (no common sequence), so it can be used in parallel threads (e.g., IntStream.range(0, height).parallel().forEach(...)) and gives the same numbers in any order of the threads, in Java and in JavaScript.doublerandomAt(int index, int k) A random number in [0, 1) for an index and a number k of the draw (several numbers for one index in a step).intrandomBinomial(int n, double p) A random number of successes of n trials with the probability p.<T> TrandomElement(List<T> list) A random element of the list (null if empty).doublerandomExponential(double rate) An exponentially distributed random number (e.g., a waiting time) with the rate.doubleA normally distributed random number (mean 0, standard deviation 1).doublerandomGaussian(double mean, double sd) A normally distributed random number with the mean and the standard deviation.intrandomInt(int n) A random integer in [0, n).intrandomInt(int min, int max) A random integer in [min, max) (min included, max excluded).intrandomPoisson(double lambda) A Poisson distributed random integer (e.g., the number of events) with the mean lambda.intrandomWeighted(double[] weights) A random index chosen with the weights (e.g., a cell with more grass is chosen more often), -1 if all are 0.voidRecords a value of the current step for an Experiment (a column of its table, besides the values of the line charts).static double[]rk4(Simulation.Derivatives f, double t, double[] y, double dt) One step of the Runge-Kutta method (4th order) for dy/dt = f(t, y), e.g., a Lotka-Volterra model:voidrun()The main method which is called from the calculation thread!static doublesd(double[] values) The standard deviation of the values.voidseed(int seed) Sets the seed of the random numbers (e.g., in init()).voidsetStartSeed(int seed) Sets the seed of the next setup (the field Seed of the settings).org.eclipse.swt.widgets.Compositesettings(org.eclipse.swt.widgets.Composite parent) An own panel for the settings in Bio7 (null: the settings of the Param fields and Action methods are created).voidsetup()The setup method to initialize values etc.!voidShuffles the list randomly (e.g., the agents for a random order of the updates).static doublesinDeg(double deg) The sine of an angle in degrees (the same digits in Bio7 and in the browser).static double[]solve(double[][] a, double[] b) The solution x of A x = b (Gaussian elimination with partial pivoting; NaN if A is singular).static doublesq(double value) The square of the value.voidStarts the model after its creation by the compiler of Bio7: the setup in the thread of the user interface.abstract voidstep()One time step (called by the Play/Pause button).voidstop()Ends the simulation after this step, e.g.,if (infected == 0) stop();in step(): Bio7 pauses the simulation (Play continues it), the HTML page stops, an Experiment ends the run (its last step is recorded).static doublesum(double[] values) The sum of the values.static doublesum(int[] values) The sum of the values.static double[][]transpose(double[][] a) The transposed matrix.static doublevariance(double[] values) The variance of the values (n - 1, 0 for less than two values).static doublewrapAround(double value, double size) The value on a torus of the size (e.g., wrapAround(-1, 100) = 99).Methods inherited from class Model
close, draw, getGLProfile, run, run, setup, setupModifier and TypeMethodDescriptionvoidclose()A method to allow closing operations with a compiled Model class called,e.g., from the CustomView implementation.voiddraw(Graphics2D g) The draw method for the Points panel with the Graphics context to draw directly on the panel with available Java routines!The OpenGL profile of the 3D view for this model, e.g., GLProfile.GL4 or GLProfile.GL3 (the names of com.jogamp.opengl.GLProfile).voidrun(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut) The main OpenGL method with the OpenGL context as parameters!voidrun(com.jogamp.opengl.GLAutoDrawable drawable) The main OpenGL method with the drawable of the 3D view (see getGLProfile).voidsetup(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut) The setup OpenGL method with the OpenGL context as parameters!voidsetup(com.jogamp.opengl.GLAutoDrawable drawable) The setup OpenGL method with the drawable of the 3D view (see getGLProfile), e.g., to create shaders and buffers.
-
Field Details
-
originX
public double originXThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up). -
originY
public double originYThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up). -
cellWidth
public double cellWidthThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up). -
cellHeight
public double cellHeightThe projected coordinates of the upper left corner of the grid and the size of a cell (cellHeight is negative for north up). -
cellSizeMeters
public double cellSizeMetersThe size of a cell on the ground in meters (approximately, at the center of the grid). -
south
public double southThe geographic bounds of the grid (WGS84 degrees). -
west
public double westThe geographic bounds of the grid (WGS84 degrees). -
north
public double northThe geographic bounds of the grid (WGS84 degrees). -
east
public double eastThe geographic bounds of the grid (WGS84 degrees). -
crs
The coordinate system of the grid (WKT).
-
-
Constructor Details
-
GeoGridModel
public GeoGridModel()
-
-
Method Details
-
load
protected abstract void load()Loads the grid and the layers with GDAL (in Bio7, once before the first init; not exported: the page gets the loaded layers). Callgrid(String, int)first, thenaddLayer(String, double[])withraster(String)orvector(String, double). -
grid
Defines the grid by a raster: its extent and coordinate system, the number of the columns (the rows from the aspect of the raster). -
raster
The first band of a raster on the cells (bilinear resampling, no data: NaN). -
raster
-
vector
Vectors (points, lines, polygons) on the cells: the value inside, 0 outside. -
vector
-
attribution
The sources of the data (shown on the map of the HTML export, e.g., "Elevation: SRTM"): the attribution which the licenses of the data require (the export embeds the data in the page). Call it in load(); without it the names of the files are shown. -
addLayer
Adds a layer (e.g., of raster or vector) for init() and step(). -
showOnGlobe
protected void showOnGlobe()Shows the grid also on the WorldWind globe of Bio7 (call it in load(); the WorldWind perspective is opened and the globe flies to the area). The colors with an alpha (#rrggbbaa) show the globe below the grid. -
prepareDisplay
protected void prepareDisplay()Description copied from class:SimulationPrepares the display before init() (called in the thread of the user interface).- Overrides:
prepareDisplayin classGridModel
-
layer
The layer (a copy of the loaded data for this setup, index y * width + x), null if unknown. -
showValues
Shows the values (e.g., a layer or a field of the model) with a color map instead of the states. -
showStates
public void showStates()Shows the states with the palette (the default). -
colAt
public int colAt(double lon, double lat) The column of the cell at the longitude and latitude (WGS84), -1 outside. -
rowAt
public int rowAt(double lon, double lat) The row of the cell at the longitude and latitude (WGS84), -1 outside. -
lon
public double lon(int x) The longitude of the center of the column (WGS84). -
lat
public double lat(int y) The latitude of the center of the row (WGS84). -
gradient
public double gradient(double[] layer, int x, int y) The gradient (rise / run, e.g., 0.1 = 10 %) of a layer (e.g., the elevation in meters) at the cell (central differences, the borders are repeated). -
slopeDegrees
public double slopeDegrees(double[] layer, int x, int y) The slope of a layer at the cell in degrees. -
value
public double value(double[] layer, int x, int y) The value of a layer at the cell (the nearest cell at the borders). -
display
protected void display()Description copied from class:SimulationDisplays the model (ImageJ image or 3D view). -
exportData
-