# Other operations

SimpleSDMLayers.coarsenFunction
coarsen(L::LT, f::FT, d::Tuple{IT,IT}) where {LT <: SimpleSDMLayer, FT <: Function, IT <: Integer}

This function will aggregate a layer by merging cells. The function f passed as its second argument is expected to take an array as input, and return a single value of any type (but it is sort of a social contract here that this will be a number of some sort, and if it is not, that you really know what you're doing).

The size of the cells to aggregate is given by the tuple, so that (2,2) will make groups of two cells vertically and two cells horizontally, for a total of four cells. By default, the cells containing nothing will be ignored, so that f is only applied to non-nothing values.

In cases where the number of cells to aggregate is not matching with the size of the grid, and ArgumentError will be thrown. Note that there is no expectation that the two values in d will be the same.

source
SimpleSDMLayers.slidingwindowFunction
slidingwindow(L::LT, f::FT, d::IT) where {LT <: SimpleSDMLayer, FT <: Function, IT <: Number}

This function will replace the value at any cell by applying the function f to the array of cells values that are within a distance d (in kilometers) from the focal cell. This is, for example, useful to use an average to smooth out the layers. The distance is estimated using the haversine distance, assuming that the radius of the Earth is 6371.0 km. This means that the size of the window will vary a little bit across latitudes, but this is far better than using a number of cells, which would have dramatic consequences near the poles.

It always returns a SimpleSDMResponse, and the cells containing nothing will also not contain a value in the output. This is different from the behavior of coarsen, which tends to expand the area of the layer in which we have data.

This function is currently relatively slow. Performance improvements will arrive at some point.

source
SimpleSDMLayers.maskFunction
mask(l1::T1, l2::T2) where {T1 <: SimpleSDMLayer, T2 <: SimpleSDMLayer}

Returns a copy of the second layer in which the positions for which the first layer is zero (of the appropriate type) or nothing are set to nothing. This is mostly useful in cases where you have a Bool layer.

source
mask(layer::SimpleSDMLayer, records::GBIF.GBIFRecords, element_type::Type=Bool)

Create a new layer storing information about the presence of occurrences in the cells, either counting (numeric types) or presence-absence-ing (boolean types) them.

source