An interface for occurrence data
The OccurrencesInterface package provides a lightweight representation of species occurrence data. It is meant to be implemented by other packages that want to be interoperable with the SpeciesDistributionToolkit package, which uses this interface for functions like plotting, masking, and value extraction from occurrence data.
Types that other packages should use
The interface relies on two abstract types:
OccurrencesInterface.AbstractOccurrence Type
AbstractOccurrenceOther types describing a single observation should be sub-types of this. Occurrences are always defined as a single observation of a single species.
OccurrencesInterface.AbstractOccurrenceCollection Type
AbstractOccurrenceCollectionOther types describing multiple observations can be sub-types of this. Occurrences collections are a way to collect multiple observations of arbitrarily many species.
Concrete types shipping with the package
In order to wrap user-provided data, regardless of its type, the package offers two concrete types:
OccurrencesInterface.Occurrence Type
OccurrenceThis is a sub-type of AbstractOccurrence, with the following types:
what- species name, defaults to""presence- a boolean to mark the presence of the species, defaults totruewhere- a tuple giving the location as longitude,latitude in WGS84, ormissing, defaults tomissingwhen- aDateTimegiving the date of observation, ormissing, defaults tomissing
When the interface is properly implemented for any type that is a sub-type of AbstractOccurrence, there is an Occurrence object can be created directly with e.g. Occurrence(observation). There is, similarly, an automatically implemented convert method.
OccurrencesInterface.Occurrences Type
OccurrencesThis is a sub-type of AbstractOccurrenceCollection. No default value.
The interface
In order to implement the interface, packages must implement the following methods for their type that is a subtype of AbstractOccurrence or AbstractOccurrenceCollection. None of these methods are optional. Most of these can be implemented as one-liners.
OccurrencesInterface.elements Function
elements(::T) where {T<:AbstractOccurrenceCollection}Returns the elements contained in an abstract collection of occurrences – this must be something that can be iterated. The default value, when unimplemented, is nothing.
OccurrencesInterface.entity Function
entity(o::Occurrence)Returns the entity (species name) for an occurrence event.
entity(::AbstractOccurrence)Default method for any abstract occurrence type for the entity operation. Unless overloaded, this returns nothing.
entity(::AbstractOccurrenceCollection)Default method for any abstract occurrence collection type for the entity operation. Unless overloaded, this returns an array of entity on all elements of the argument.
OccurrencesInterface.place Function
place(o::Occurrence)Returns the place of the occurrence event, either as a tuple of float in the longitude, latitude format, or as missing. The CRS is assumed to be WGS84 with no option to change it. This follows the GeoJSON specification.
place(::AbstractOccurrence)Default method for any abstract occurrence type for the place operation. Unless overloaded, this returns nothing.
place(::AbstractOccurrenceCollection)Default method for any abstract occurrence collection type for the place operation. Unless overloaded, this returns an array of place on all elements of the argument.
OccurrencesInterface.date Function
date(o::Occurrence)Returns the date (technically a DateTime object) documenting the time of occurrence event. Can be missing if not known.
date(::AbstractOccurrence)Default method for any abstract occurrence type for the date operation. Unless overloaded, this returns nothing.
date(::AbstractOccurrenceCollection)Default method for any abstract occurrence collection type for the date operation. Unless overloaded, this returns an array of date on all elements of the argument.
OccurrencesInterface.presence Function
presence(o::Occurrence)Returns a Bool for the occurrence status, where true is the presence of the entity and false is the (pseudo)absence.
presence(::AbstractOccurrence)Default method for any abstract occurrence type for the presence operation. Unless overloaded, this returns nothing.
presence(::AbstractOccurrenceCollection)Default method for any abstract occurrence collection type for the presence operation. Unless overloaded, this returns an array of presence on all elements of the argument.
Additional methods
OccurrencesInterface.presences Function
presences(c::T) where {T<:AbstractOccurrenceCollection}Returns an Occurrences where only the occurrences in the initial collection for which presence evaluates to true are kept.
OccurrencesInterface.absences Function
absences(c::T) where {T<:AbstractOccurrenceCollection}Returns an Occurrences where only the occurrences in the initial collection for which presence evaluates to false are kept.
The Tables.jl interface
The Occurrences type is a data source for the Tables.jl interface.