To facilitate writing julian code, we have overloaded a number of methods from Base. These methods should remove the need to interact with the grid field directly, and also allow to set and get values using the geographic coordinates (as opposed to the grid positions).

## From Base

Base.convertFunction
Base.convert(::Type{SimpleSDMResponse}, layer::T) where {T <: SimpleSDMPredictor}

Returns a response with the same grid and bounding box as the predictor.

source
Base.convert(::Type{SimpleSDMPredictor}, layer::T) where {T <: SimpleSDMResponse}

Returns a predictor with the same grid and bounding box as the response.

source
Base.convert(::Type{T}, layer::TL) where {T <: Number, TL <: SimpleSDMLayer}

Returns a copy of the layer with the same type (response or predictor), but the element type has been changed to T (which must be a number). This function is extremely useful (required, in fact) for plotting, as the nothing values are changed to NaN in the heatmaps.

source
Base.convert(::Type{Matrix}, layer::T) where {T <: SimpleSDMLayer}

Returns the grid as an array.

source
Base.copyFunction
Base.copy(l::T) where {T <: SimpleSDMLayer}

Returns a new copy of the layer, which has the same type.

source
Base.collectFunction
Base.collect(l::T) where {T <: SimpleSDMLayer}

Returns the non-nothing values of a layer.

source
Base.eltypeFunction
Base.eltype(layer::SimpleSDMLayer{T}) where {T}

Returns the type of the values stored in the grid, where the Nothing type is omitted.

source
Base.sizeFunction
Base.size(layer::T) where {T <: SimpleSDMLayer}

Returns the size of the grid.

source
Base.size(layer::T, i...) where {T <: SimpleSDMLayer}

Returns the size of the grid alongside a dimension.

source
Base.strideFunction
Base.stride(layer::T; dims::Union{Nothing,Integer}=nothing) where {T <: SimpleSDMLayer}

Returns the stride, i.e. half the length, of cell dimensions, possibly alongside a side of the grid. The first position is the length of the longitude cells, the second the latitude.

source
Base.getindexFunction

Extracts a value from a layer by its grid position.

source
Base.getindex(layer::T, i::R, j::R) where {T <: SimpleSDMLayer, R <: UnitRange}

Extracts a series of positions in a layer, and returns a layer corresponding to the result. This is essentially a way to rapidly crop a layer to a given subset of its extent. The i and j arguments are UnitRanges (of Integer).

The layer returned by this function will have the same type as the layer passed as its argument, but this can be changed using convert. Note that this function performs additional checks to ensure that the range is not empty, and to also ensure that it does not overflows from the size of the layer.

source
Base.getindex(layer::T, longitude::K, latitude::K) where {T <: SimpleSDMLayer, K <: AbstractFloat}

Extracts the value of a layer at a given latitude and longitude. If values outside the range are requested, will return nothing.

source
Base.getindex(layer::T; left=nothing, right=nothing, top=nothing, bottom=nothing) where {T <: SimpleSDMLayer, K <: Union{Nothing,AbstractFloat}}

Returns a subset of the argument layer, where the new limits are given by left, right, top, and bottom. Up to three of these can be omitted, and if so these limits will not be affected.

source
Base.getindex(layer::T, n::NT) where {T <: SimpleSDMLayer, NT <: NamedTuple}

Returns a subset of the argument layer, where the new limits are given in a NamedTuple by left, right, top, and bottom, in any order. Up to three of these can be omitted, and if so these limits will not be affected.

source
Base.getindex(layer1::T1, layer2::T2) where {T1 <: SimpleSDMLayer, T2 <: SimpleSDMLayer}

Extract a layer based on a second layer. Note that the two layers must be compatible, which is to say they must have the same stride and the bounding coordinates of layer2 must be contained in layer1.

source
Base.getindex(p::T, occurrence::GBIF.GBIFRecord) where {T <: SimpleSDMLayer}

Extracts the value of a layer at a given position for a GBIFRecord. If the GBIFRecord has no latitude or longitude, this will return nothing.

source
Base.getindex(layer::T, records::GBIF.GBIFRecords) where {T <: SimpleSDMLayer}

Returns the values of a layer at all occurrences in a GBIFRecords collection.

source
Base.getindex(layer::T, records::Vector{GBIF.GBIFRecord}) where {T <: SimpleSDMLayer}

Returns the values of a layer at all occurrences in a GBIFRecord array.

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

Returns the values of a layer at all occurrences 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
Base.setindex!Function
 Base.setindex!(layer::SimpleSDMResponse{T}, v::T, i...) where {T}

Changes the value of a cell, or a range of cells, as indicated by their grid positions.

source
Base.setindex!(layer::T, v, lon::Float64, lat::Float64) where {T <: SimpleSDMResponse}

Changes the values of the cell including the point at the requested latitude and longitude.

source
Base.setindex!(layer::T, v, record::GBIFRecord) where {T <: SimpleSDMResponse}

Changes the values of the cell including the point at the requested latitude and longitude. Be careful, this function will not update a cell that has nothing.

source
Base.similarFunction
Base.similar(layer::T, ::Type{TC}) where {TC <: Any, T <: SimpleSDMLayer}

Returns a SimpleSDMResponse of the same dimensions as the original layer, with nothing in the same positions. The rest of the values are replaced by the output of zero(TC), which implies that there must be a way to get a zero for the type. If not, the same result can always be achieved through the use of copy, manual update, and convert.

source
Base.similar(layer::T) where {T <: SimpleSDMLayer}

Returns a SimpleSDMResponse of the same dimensions as the original layer, with nothing in the same positions. The rest of the values are replaced by the output of zero(element_type), which implies that there must be a way to get a zero for the type. If not, the same result can always be achieved through the use of copy, manual update, and convert.

source
Base.replaceFunction
Base.replace(layer::T, old_new::Pair...) where {T <: SimpleSDMResponse}

Replaces the elements of layer according to a series of pairs. Returns a copy.

source
Base.replace(layer::T, old_new::Pair...) where {T <: SimpleSDMPredictor}

Replaces the elements of layer according to a series of pairs. Copies the layer as a response before.

source
Base.replace!Function
Base.replace!(layer::T, old_new::Pair...) where {T <: SimpleSDMLayer}

Replaces the elements of layer according to a series of pairs. In place. Only possible for SimpleSDMResponse elements (which are mutable) and will throw an error if called on a SimpleSDMPredictor element (which is not mutable).

source
Base.sumFunction
Base.sum(l::SimpleSDMResponse{T}) where {T <: Number}

Applies sum (from Base) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.sum(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies sum (from Base) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.maximumFunction
Base.maximum(l::SimpleSDMResponse{T}) where {T <: Number}

Applies maximum (from Base) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.maximum(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies maximum (from Base) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.minimumFunction
Base.minimum(l::SimpleSDMResponse{T}) where {T <: Number}

Applies minimum (from Base) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.minimum(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies minimum (from Base) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.extremaFunction
Base.extrema(l::SimpleSDMResponse{T}) where {T <: Number}

Applies extrema (from Base) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.extrema(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies extrema (from Base) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Base.maxFunction
Base.max(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies max (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that max is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.minFunction
Base.min(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies min (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that min is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.:+Function
Base.+(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies + (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that + is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.:-Function
Base.-(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies - (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that - is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.:*Function
Base.*(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies * (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that * is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.:/Function
Base./(l1::SimpleSDMLayer, l2::SimpleSDMLayer)

Applies / (from Base) to every pair of cells from two SimpleSDMLayers and returns the result as a new SimpleSDMResponse layer. Note that / is only applied to the pairs without a nothing element, and returns nothing for the pairs with one. This function has been automatically generated.

source
Base.:==Function
==(layer1::SimpleSDMLayer, layer2::SimpleSDMLayer)

Tests whether two SimpleSDMLayer elements are equal. The layers are equal if all their fields (grid, left, right, bottom, top) are equal, as verified with == (e.g., layer1.grid == layer2.grid).

source
Base.isequalFunction
isequal(layer1::SimpleSDMLayer, layer2::SimpleSDMLayer)

Tests whether two SimpleSDMLayer elements are equal. The layers are equal if all their fields (grid, left, right, bottom, top) are equal, as verified with isequal (e.g., isequal(layer1.grid, layer2.grid)).

source

## From Statistics

Statistics.meanFunction
Statistics.mean(l::SimpleSDMResponse{T}) where {T <: Number}

Applies mean (from Statistics) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.mean(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies mean (from Statistics) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.mean(layers::Array{T}) where {T <: SimpleSDMLayer}

Applies mean (from Statistics) to the elements in corresponding positions from the different layers (similar to mean(a::Array{Matrix})) and returns the result as a new SimpleSDMResponse layer. Note that mean is only applied to the positions without a nothing element and returns nothing for the pairs with one. This function has been automatically generated.

source
Statistics.medianFunction
Statistics.median(l::SimpleSDMResponse{T}) where {T <: Number}

Applies median (from Statistics) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.median(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies median (from Statistics) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.stdFunction
Statistics.std(l::SimpleSDMResponse{T}) where {T <: Number}

Applies std (from Statistics) to an object of type SimpleSDMResponse. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.std(l::SimpleSDMPredictor{T}) where {T <: Number}

Applies std (from Statistics) to an object of type SimpleSDMPredictor. This function has been automatically generated. Note that this function is only applied to the non-nothing elements of the layer, and has no method to work on the dims keyword; the grid itself can be extracted with convert(Matrix, l).

source
Statistics.std(layers::Array{T}) where {T <: SimpleSDMLayer}

Applies std (from Statistics) to the elements in corresponding positions from the different layers (similar to mean(a::Array{Matrix})) and returns the result as a new SimpleSDMResponse layer. Note that std is only applied to the positions without a nothing element and returns nothing for the pairs with one. This function has been automatically generated.

source
Statistics.quantileFunction
quantile(layer::T, p) where {T <: SimpleSDMLayer}

Returns the quantiles of layer at p, using Statistics.quantile.

source