gen_bin_grid: Generate bin grid for viewing

View source: R/bin_funcs.R

gen_bin_gridR Documentation

Generate bin grid for viewing

Description

(ONLY FOR VISUALIZATION - DO NOT USE FOR STATS) This generates a matrix or raster of bin numbers for the selected extent and resolution. User can then assign bin data values to the grid based on their bin number. The result is an APPROXIMATE Plate-Carée (Equidistant Cylindrical) projection of the bin data.

Usage

gen_bin_grid(
  resolution = "4",
  ext = c(xmn = -147, xmx = -41, ymn = 39, ymx = 86),
  rast = TRUE,
  max_bins = 5e+07
)

Arguments

resolution

String indicating spatial resolution, see ?gen_nrows for list of accepted strings.

ext

Named vector containing the boundaries of the resulting grid (xmn, xmx, ymn, ymx).

rast

TRUE/FALSE, should the resulting bin matrix be converted to raster?

max_bins

Maximum grid size (total number of pixels) that can be generated between the selected latitudes. This is to prevent overloading memory with the higher-resolution grids (e.g. 250m, 1km)

Details

This regular 2D grid based on bin numbers is formed like so:

For the selected spatial resolution, the number of latitudinal rows is calculated, and the number of matrix columns is double that value (this is the number of bins in the row at the equator). The number of unique bins per row is then calculated (e.g. 3 at the pole, 9 in the row below it, ...). Since the binning scheme aims to make each bin approximately equal area on the globe, this means that for each row, the unique bins take up an equal number of pixels. E.g. if your grid is 9000 pixels wide and you have 3000 unique bins in a row, each bin in that row should be repeated 3 times. Note: It's not an exact Plate-Carée projection because if the number of bins in a row is not a factor of the number of pixels across the row (i.e. the bins can't be spaced evenly across the row), instead of allowing fractions of bins across some pixels, this function simply forces it to the nearest integer for code simplicity and speed. For example if a row has 2 bins and needs to spread them evenly over 5 pixels, in a Plate-Carée projection they should each spread over 2.5 pixels, but in this function, one of the bins would repeat twice and the other would repeat three times.

LATITUDE AND LONGITUDE ARE AT THE CENTER OF THE BIN.

Value

Global raster containing bin numbers.


BIO-RSG/oceancolouR documentation built on April 25, 2024, 12:28 p.m.