HexSim Accessories & Programs
This color palette file can be imported into XnView's "Edit palette" tool. When displaying source-sink maps, it can be advantageous to use a color scheme that clearly distinguishes sources from sinks. This Red-Yellow color scheme does so by joining two dissimilar color gradients. Neutral sites (those with hexagon scores close to zero) will be shown in black. Sources will be shown using a gradient that shifts from green to yellow. Sinks will be shown using a gradient that shifts from blue to red. These color gradients here are nonlinear, and thus lump the worst sinks and best sources together visually. The Red-Yellow color scheme is shown below.
This zip file contains nine bitmaps that may be useful for getting started with HexSim. These BMP files can be opened with HexSim's Generate Hexmap tool (available under the HexSim menu). Several of the bitmap files come with a companion text file that indicates what the different image colors represent, and who to credit for the construction of the map. The four files labeled Jackson Pollock were made from images of this artist's work that can be found online. These bitmaps no longer look much like the original paintings because the images were reduced to just a handful of unique colors. These four Jackson Pollock images are intended to invoke the concept of spatial pattern without representing any actual place.
This PDF file contains 8 pages of useful information about hexagons and hexagon grids. This information was all captured from a website that apparently no longer exists, and the author of this material is unknown (else attribution would be given). Note that HexSim's hexagons are oriented differently than those described in this file.
For fun, here is a link to an entertaining YouTube video that discusses the importance of hexagons in nature: Hexagons are the Bestagons
Example Model Code
This HexSim model provides a simple example showing how survival and reproductive rates might be varied based on individual resource allocation. To accomplish this with minimal complexity, we use a one parameter interpolation function. This equation has the form:
y = 1 - (1 - x) ^ alpha
Where x represents the resources available to an individual, alpha is the survival or reproduction exponent, and y is used as an interpolation coefficient. The x-term must be limited to [0-1], thus it actually refers to the fraction of the species' maximum resource need acquired by any one individual. Intended values for alpha are the set of non-negative real numbers. Given these constraints, y will range between [0-1]. We use y to assign vital rates falling between user-defined min and max values.
Examples of the curves generated by this function are shown at the right.
The interpolation process is governed by a collection of Global Parameters, with the default values being displayed in the image at the right. These variables have the following interpretations:
HexSim Movement events provide an option for drawing path lengths from a lognormal distribution. But if users wish to carefully examine the resulting distribution of path lengths, it is more convenient to make those assignments directly via accumulators. The accumulator values can then be written out using a Data Probe. However, while the Accumulator Expression updater function includes a standard normal distribution (GasDev), it doesn't include a lognormal distribution. This model shows how to map random numbers obtained from a standard normal distribution onto a lognormal distribution.
In addition, this model allows users to establish dispersal minimum and maximum values. When lognormally-distributed random draws fall outside the proscribed range, they are rejected and another selection is made. This work is performed within an iterating Event Group.
More generally, Data Lookup events make it possible for users to incorporate any arbitrary distribution into a HexSim simulation. First, a large collection of random draws from the desired distribution must be assembled into a CSV file, outside of HexSim. Then whenever needed, a Data Lookup event can access this file, assigning individuals values drawn from the table at random.
Stand-alone C-Language Programs
Some of these construct HexSim input data, while others manipulate simulation output. The code is all written in the C programming language, and may be immediately compiled and run within a Unix / Linux environment like Cygwin. These programs are provided with no assurance that they are free from design or coding errors.
This program converts a categorical patch map into a non-categorical patch map. It does this by assigning a unique ID to every patch in the input patch map. In the context of this program, a distinct patch is a collection of pixels that (a) have the same value, and are (b) not adjacent to any other nonzero pixels of the same value. Distinct output patches can result from input patches that are isolated by zero-valued hexagons, or from adjacent hexagon clusters, when the clusters have different scores.
HexSim users will frequently employ patch maps for process sampling at scales larger than an atomic hexagon. For example, occupancy rates or source-sink values can be gathered on a patch-by-patch basis if simulated individuals consistently identify which patch they are in. However, when patches are bisected by barriers, these sampling schemes will produce meaningless results. This program reads a patch map (stored as a CSV file) and a HexSim Barrier Map (a HBF file), and generates a new map in which every patch bisected by a barrier is divided up into multiple separate patches. Doing this manually is completely impractical for all but the smallest landscapes.
When the barriers_divide_patches program is used to a break patches along barriers, small patch fragments will often be generated. This program can be used to remove these small fragments by aggregating adjacent patches that are not completely separated by a barrier. Users specify a patch map (stored as a CSV file), a HexSim Barrier Map (a HBF file), and a maximum patch area that cannot be exceeded during the aggregation process. The program generates a new patch map in which some or all of the small patch fragments are incorporated into other adjacent patches.
This program rescores the nonzero hexagons in a hexmap. It does this by grouping them into bins, with the number of bins being supplied by the user on the command line. The program attempts to keep the number of hexagons in each bin constant, but it can not do this perfectly. Note that the program can't be used with hexmaps containing negative scores, and it will abort if passed such a file. However, it is OK to use the program with hexmaps that have real-numbered scores.
This program is primarily useful for improving the contrast in dispersal flux hexmaps. In such cases, the original dispersal flux hexmap would typically be binned, and then converted into an 8-bit raster image in which each bin is assigned a unique color. If this conversion to raster is performed by HexSim, the maximum number of nonzero colors will be 100. Otherwise, the number of colors (including zeros) could be as large as 256. However, the program does not limit the number of bins.
This program reads a Hexmap (stored as a CSV file), and writes a new Hexmap (also a CSV file) that contains a smooth gradient of integer values intended to be used by Dispersal's Walk Up Gradient algorithm.
The input Hexmap must be composed strictly of hexagons scored 0, 1, or 2. The smoothed image will ignore the zero-valued input hexagons. The input hexagons scored 1 define the region to be smoothed. The input hexagons scored 2 are the starting sites. The starting sites will be assigned the largest values in the output map (each starting site will have the same final value). Each smoothed hexagon will be assigned a value equal to this maximum minus the steps it's removed from the nearest starting site. Starting sites that are not adjacent to hexagons scored 1 will have no affect on the output, but such values also do not create problems for the algorithm.
The program is passed an existing hexmap (in CSV format), plus the grid dimensions (number of rows, min-cols, and max-cols).
This program is used to create a CSV file that can be imported into HexSim as a Hexmap. The new Hexmap will be comprised of a collection of rectangular blocks. A number of command-line options are described in the file header. An analogous tool exists within the HexSimCommandLine tool, which is bundled with HexSim, and documented in the User's Guide under Utilities / Command Line Options.
This program is used to create a CSV file that can be imported into HexSim as a Hexmap. The new Hexmap will be comprised of a collection of hexagon-shaped patches. A number of command-line options are described in the file header. An analogous tool exists within the HexSimCommandLine tool, which is bundled with HexSim, and documented in the User's Guide under Utilities / Command Line Options.
HexSim users will often find it useful to represent some simulation output as frequency plots (histograms). Graphing packages use bar plots to display frequency data, but when the number of bins becomes large, point or line plots can become a nice alternative to bar plots. This program generates a frequency table from a file of data values. Users must pass the program the bin size and data file (in that order). The data file must be a single column of numbers, with no header. The program's output will contain three separate columns giving the midpoint of each bin, the number of records in each bin, and the percent of the data found in each bin.
This program reads a HexSim CSV patch map, and creates a HexSim HBF barrier map. The resulting barrier map will include a barrier located along the edge of every patch present in the patch map. The program must be passed the patch map name, followed by the number of rows, minimum columns, and maximum columns. Results are written to the standard output.
This program can be used to clip a Hexmap data file using a Hexmap mask. Both files must be in CSV format. A common use-case for this program will be to clip a patch map using a collection of nonzero hexagons extracted from a habitat map.
This program converts a hexmap in CSV format into a Sun rasterfile. Sun rasterfiles are typically associated with a ".sun" or ".ras" extension. The free application XnView (www.xnview.com) can read a Sun rasterfile and convert it into a more modern format. The Sun rasterfile format is used here for coding simplicity.
This program repairs HexSim barrier files. First, it will remove any negative signs from barrier categories. Next, the program will remove any barrier segments at the workspace edge. Then, it will remove any barriers that are only one segment in length. It will also remove barrier spurs that are just one edge long. Lastly, the program will remove barrier loops surrounding a single hexagon. Loops are only altered if there are 0, 1, or 2 connections to them. An illustration of the barrier repair process can be seen here.
This program builds a dispersal flux hexmap identical to the one constructed by the HexSim Tally of the same name. There is, however, a significant difference between the two routines. HexSim's Dispersal Flux Tally builds separate hexmaps for each population. This routine builds a single dispersal flux hexmap that combines the data from all populations.
This program reads a collection of HexSim Hexmap (*.hxn) files. For each hexagon, the program computes the mean value taken over the collection, and then it writes a new Hexmap that records these means. The number of Hexmaps in the collection does not need to be specified -- this program may be passed an argument such as '*.hxn'. The output hexmaps will be in CSV format.
This program reads a collection of HexSim Hexmap (*.hxn) files. For each hexagon, the program computes the maximum value taken over the collection, and then it writes a new Hexmap that records these means. The number of Hexmaps in the collection does not need to be specified -- this program may be passed an argument such as '*.hxn'. The output hexmaps will be in CSV format.
This program reads a collection of HexSim Hexmap (*.hxn) files. Each of these files is first converted into a binary (0 vs 1) map. If a hexagon's score exceeds zero, it is set to one. Otherwise, it is set to zero. Next, for each hexagon, the program computes the mean value taken over the collection, and then it writes a new Hexmap that records these means. The number of Hexmaps in the collection does not need to be specified -- this program may be passed an argument such as '*.hxn'. The output hexmaps will be in CSV format.
This program reads a patch map, a productivity report, and a count-based projection matrix report. The program writes a CSV output table that contains patch-by-patch data. It also writes 5 separate CSV files that can be imported into HexSim as Hexmaps. The productivity and projection matrix reports must have been stratified by the same location-based trait.
The program will skip the productivity report if the filename given for it on the command line is the dash character "-". Similarly, the program will skip the projection report if the filename given for it on the command line is the dash character "-". The collection of output files generated by the program will be smaller if an input file is not provided.
This file summarizes patch-by-patch data, and includes the following information:
Births-Deaths ; Non-Migrants ; Emigrants ; Immigrants ; Emigrants-Immigrants.
This file displays the number of individuals that moved between each pair of patches, with direction explicitly addressed. Fluxes of zero individuals are not printed.
This output is a Hexmap in CSV format. This file contains observed source-sink values, measured as the number of births minus deaths. This data is tabulated per-patch.
This output is a Hexmap in CSV format. This file contains observed source-sink values, measured as the number of emigrants minus immigrants. This data is tabulated per-patch.
This output is a Hexmap in CSV format. This file contains observed number of emigrants. This data is tabulated per-patch.
This output is a Hexmap in CSV format. This file contains observed number of immigrants. This data is tabulated per-patch.
This output is a Hexmap in CSV format. This file contains observed number of non-migrants. Non-migrants are the individuals represented by the matrix diagonal. These individuals were in the same patch in two adjacent time steps. This data is tabulated per-patch.
This program reads a HexSim Hexmap (HXN) file, and converts the content to a comma-separated variable format. This type of conversion can be performed efficiently within HexSim, but if the content of many Hexmaps need to be processed at the same time, then using an external routine like this can greatly reduce the effort involved. And this code could be modified to read multiple Hexmaps and merge their content into a single custom image. The resulting CSV file could then be imported into HexSim, or converted to a raster file using the Display Spatial Data tool.
This program reads a barrier map, and it then writes a hexmap in CSV format. The output file will identify any hexagons that are completely surrounded by barriers. This is useful for finding locations where use of the barrier map will trap dispersers into a single hexagon. Once these locations have been identified, then the barrier map can be edited to correct these issues.
This program converts a CSV file with patch-by-patch count data into a CSV file that can be imported into HexSim as a Hexmap. The program must be passed CSV version of a patch map, and a 2-column file with patch counts data corresponding to the same collection of patches. The patch count data might represent productivity values or occupancy rates, etc. Both input files are assumed to have single-line headers.
Patch maps composed of ordered arrays of patches can be difficult to visualize because adjacent patches end up being displayed using identical or nearly-identical colors. This program will randomize the patch IDs, so that the map will be easier to visualize. The patch map used must be stored in CSV format.
This program will generate the sum or mean values, taken over all individuals, for Data Probe event output files. This is useful because Data Probe event output includes a separate row for each individual, and users will often want to summarize this information for each time step. Since the number of individuals will typically change each time step (and replicate), computing these sums and means in a spreadsheet can be awkward. To use the program, users need only pass the Data Probe output CSV file, and one of the strings: 'sum' or 'mean'.
This program will generate a few useful statistics from a concatenation of HexSim Census event output files. Users will often run multiple replicates of the same simulation, and then want to obtain means, or other metrics from the collection of replicates. This program simplifies that task. First, users must collect the Census event output files into one CSV file containing a single header line. The Unix 'cat' command is ideal for this (but it will produce a file with multiple header lines). The concatenated file is passed to the program along with the number of the column that the statistics should be generated for (the first column is numbered 1, not 0). The program will write out the minimum, mean, maximum, number of zeros, and P(0) values for each time step, corresponding to the selected data column. P(0) here refers to the probability of extinction.
When patch maps are altered (e.g. clipped to a mask file), the total number of patches can change. This program will renumber such a patch map, to ensure that the patch IDs are sequential. The Hexmap used must be stored in CSV format.