This function calculate the median distance, mean distance and standard deviation of distance to escape form an extreme event 'as the crow files' (but avoiding NA pixels, which are suppose to represent a place that cannot be crossed) through time for a given gps position or for all pixels.

BEE.calc.escape(
  extreme_events_output,
  start_date = NULL,
  end_date = NULL,
  pixel,
  only_days_EE = FALSE,
  group_by_event = FALSE
)

Arguments

extreme_events_output

: Is the ouput of function BEE.id.extreme_events().

start_date

: Defines the beginning of the timeframe during which you want to analyse distance to escape. If no dates are provided, computation will be done on all days_provided.

end_date

: Defines the endding of the timeframe during which you want to analyse distance to escape. If no dates are provided, computation will be done on all days_provided

pixel

: Is a vector with x,y coordinates or a df of x,y coordinates or "all" if you want to compute distance metrics for all pixels in the raster provided through extreme_events_output.

only_days_EE

: = 'TRUE' if you want to perform calculations using all the days. Use account = 'FALSE' when you want to calculate only for the days when your reference point is experiencing an extreme event. By default, only_days_EE is set on FALSE

group_by_event

: Allows to specify if you want your result by extreme event or for the whole time periode specified. "group_by_event" = TRUE : compute one mean distance per event. "group_by_event" = FALSE : mean distance will be based on distances from all days in the time frame (belonging to an extreme event or not), including all days belonging to this event event if they are a '0' day, TRUE : compute one mean distance accounting only for days that belong to an EE.

Value

A list with one dataframe per pixel. Please make sure to call element of the list by their names and not by their positions.

Note

All distance metrics are limited by the size of the Spatraster your are providing. See function is not developped to work on 4D data (time + 3D).

Examples

# Load data for example: library(BioExtremeEvent)
# reconstruct the output of BEE.id.extreme_event() from data saved in local:
file_name_1 <- system.file(file.path("extdata",
                                     "binarized_corrected_spatraster.tiff"),
                                     package = "BioExtremeEvent")
extreme_event_spatraster <- terra::rast(file_name_1)
file_name_2 <- system.file(file.path("extdata",
                                     "binarized_corrected_df.rds"),
                                     package = "BioExtremeEvent")
extreme_event_list <- readRDS(file_name_2)

extreme_event <- list(extreme_event_spatraster,extreme_event_list)

# create a dataframe with the positions of the studdied sites:
GPS <- data.frame(x = c(3.7659),
                 y = c(43.4287))

#' # Get distance, azimut and pixel coordinates to escape:
library(BioExtremeEvent)

escape <- BioExtremeEvent::BEE.calc.escape(
 extreme_events_output = extreme_event,
 start_date = "2024-05-01",
 end_date = "2024-11-30",
 pixel= GPS,
 only_days_EE = FALSE,
 group_by_event = FALSE
)
#> When several pixels are the 'closest pixel', the one with the smallest 
#>     number/id is kept to compute shortest distance and azimut. Moreover, this 
#>     function uses 'geosphere::distHaversine' to compute distances, it accounts 
#>     for earth rotondity, which is better than euclidian distance, but it 
#>     consider the earth as a sphere, thus near the poles, this methods is less 
#>     percise than geosphere::distVincentyEllipsoid. This is a compromise between
#>     computation speed and precision. The estimate error using distHaversine 
#>     compare to distVincentyEllipsoid is between 1 km and 5 km for a distance of 
#>     300 km in polar area.
#> During the following dates, the raster was fully covered by an EE and it
#>       was no possible to compute a distance to escape or an azimut.2024-11-17, 2024-11-18, 2024-11-19, 2024-11-20