# 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.latitudesFunction
latitudes(layer::T) where {T <: SimpleSDMLayer}

Returns an iterator with the latitudes of the SDM layer passed as its argument. This returns the latitude at the center of each cell in the grid.

source
latitudes(records::GBIFRecords)

Returns the non-missing latitudes.

source
SimpleSDMLayers.longitudesFunction
longitudes(layer::T) where {T <: SimpleSDMLayer}

Returns an iterator with the longitudes of the SDM layer passed as its argument. This returns the longitudes at the center of each cell in the grid.

source
longitudes(records::GBIFRecords)

Returns the non-missing longitudes.

source
SimpleSDMLayers.clipFunction
clip(layer::T, records::GBIF.GBIFRecords)

Returns a clipped version (with a 10% margin) around all occurences in a GBIFRecords collection.

source
clip(layer::T, df::DataFrames.DataFrame; latitude = :latitude, longitude = :longitude) where {T <: SimpleSDMLayer}

Returns a clipped version (with a 10% margin) around all occurences in a DataFrame. Note that the function looks for columns named :latitude and :longitude by default, but these can be changed using the latitude and longitude arguments.

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
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. Note that the function looks for columns named :latitude and :longitude by default, but these can be changed using the latitude and longitude arguments.

source
SimpleSDMLayers.rescale!Function
rescale!(layer::TI, template::TJ) where {TI <: SimpleSDMLayer, TJ <: SimpleSDMLayer}

Changes the values of the layer given as its first argument, so that it has the same range as the values of the layer given as its second argument. Modification is done in-place.

source
rescale!(layer::TI, t::Tuple{T,T}) where {TI <: SimpleSDMLayer, T <: Number}

Changes the values of the layer given as its first argument, so that it has the same range as the values given as a tuple of values. Modification is done in-place.

source
rescale!(layer::T, p::Vector{Real}) where {T <: SimpleSDMLayer}

Rescale the values of a layer so that they match with the quantiles given in p. Internally, this uses the Statistics.quantile function.

source
SimpleSDMLayers.rescaleFunction
rescale(layer::TI, template::TJ) where {TI <: SimpleSDMLayer, TJ <: SimpleSDMLayer}

Copying version of rescale!.

source
rescale(layer::TI, t::Tuple{T,T}) where {TI <: SimpleSDMLayer, T <: Number}

Copying version of rescale!.

source
rescale(layer::T, p::Vector{Real}) where {T <: SimpleSDMLayer}

Copying version of rescale!.

source
SimpleSDMLayers.mosaicFunction
mosaic(f::TF, layers::Vector{T}) where {TF <: Function, T <: SimpleSDMLayer}

Joins a series of possibly overlapping layers by applying the function f to the values that occupy the same cells. Note that the function f should return a single value and accept an vector as input. Functions like Statistics.mean, etc, work well.

Using mosaic with maximum is equivalent to raster::merge from the R package raster.

source