automat.maxN.spbysp: #' Create a dataframe containing maxN values for the studied...

View source: R/5_maxN_values_studied_species_functions.R

automat.maxN.spbyspR Documentation

#' Create a dataframe containing maxN values for the studied species and #' the three poses #' #' This function computes a dataframes containing maxN,SmaxN, maxN_row, #' for a given set of species and the three poses. This function uses #' parallelisation. #' #' @param species_set a vector containing the latin name of the studied species #' given with no space but underscore "_" between Genera and Species names #' #' @param abund_list a list gathering the abundance dataframes of the different #' Poses (dataframes with cameras = columns and time = rows) #' #' @param dist_df a numerical dataframe containing the distance between each #' pair of camera. There are as many rows as there are cameras and there are #' as many columns as there are cameras, thus the dataframe is symmetrical #' and the diagonal is filled with 0. Rows names and columns names #' must be cameras names. BE CAREFUL that the cameras are #' the same and in the same order in the dist_df and in the abund_df! #' #' @param fish_speed a numerical value refering to the maximal speed of the #' studied species. Speed must be given in meters per second. If the #' computation of maxN values should not take into account fish speed (that is #' to say if the camera pooling is done at the second level), #' fish_speed = NULL #' #' @param os a chacaretr string refering to the operating system used as the #' parallelisation process differs following the os. can either be "windows" or #' "linux". (mac not done) #' #' @return a dataframe with five columns: maxN,SmaxN, maxN_row, #' Species_nm, Poses #' #' @importFrom magrittr %>% #' #' @export #'

Description

#' Create a dataframe containing maxN values for the studied species and #' the three poses #' #' This function computes a dataframes containing maxN,SmaxN, maxN_row, #' for a given set of species and the three poses. This function uses #' parallelisation. #' #' @param species_set a vector containing the latin name of the studied species #' given with no space but underscore "_" between Genera and Species names #' #' @param abund_list a list gathering the abundance dataframes of the different #' Poses (dataframes with cameras = columns and time = rows) #' #' @param dist_df a numerical dataframe containing the distance between each #' pair of camera. There are as many rows as there are cameras and there are #' as many columns as there are cameras, thus the dataframe is symmetrical #' and the diagonal is filled with 0. Rows names and columns names #' must be cameras names. BE CAREFUL that the cameras are #' the same and in the same order in the dist_df and in the abund_df! #' #' @param fish_speed a numerical value refering to the maximal speed of the #' studied species. Speed must be given in meters per second. If the #' computation of maxN values should not take into account fish speed (that is #' to say if the camera pooling is done at the second level), #' fish_speed = NULL #' #' @param os a chacaretr string refering to the operating system used as the #' parallelisation process differs following the os. can either be "windows" or #' "linux". (mac not done) #' #' @return a dataframe with five columns: maxN,SmaxN, maxN_row, #' Species_nm, Poses #' #' @importFrom magrittr %>% #' #' @export #'

Usage

automat.maxN.spbysp(species_nm, abund_list, dist_df, fish_speed, os, nb_cores)

Arguments

species_nm

a caracter string containing the latin name of the studied species given with no space but underscore "_" between Genera and Species names

abund_list

a list gathering the abundance dataframes of the different Poses (dataframes with cameras = columns and time = rows)

dist_df

a numerical dataframe containing the distance between each pair of camera. There are as many rows as there are cameras and there are as many columns as there are cameras, thus the dataframe is symmetrical and the diagonal is filled with 0. Rows names and columns names must be cameras names. BE CAREFUL that the cameras are the same and in the same order in the dist_df and in the abund_df!

fish_speed

a numerical value refering to the maximal speed of the studied species. Speed must be given in meters per second. If the computation of maxN values should not take into account fish speed (that is to say if the camera pooling is done at the second level), fish_speed = NULL

@param os a chacaretr string refering to the operating system used as the parallelisation process differs following the os. can either be "windows" or "linux". (mac not done)

@param nb_cores is a nuemric value refering to the number of cores on which the process should be parallelised (do not need more than 3 cores as 3 poses)

Value

a dataframe with five columns: maxN,SmaxN, maxN_row, Species_nm, Poses

create a dataframe which will contain all data:

maxN_all <- as.data.frame(matrix(ncol = 5, nrow = 1)) colnames(maxN_all) <- c("species_nm", "pose_nb", "maxN", "SmaxN", "SmaxN_timestep")

returns the number of available hardware threads, and if it is FALSE, returns the number of physical cores:

no_cores <- parallel::detectCores(logical = TRUE)

allocate this nb of available cores to R:

cl <- parallel::makeCluster(no_cores-1) doParallel::registerDoParallel(cl)

restrict the abund_list to the studied species:

clean_abund_list <- abund_listwhich(names(abund_list) %in% species_set)

remove NA rows:

maxN_all <- maxN_allwhich(! is.na(maxN_all$species_nm)),

Close Cluster:

stopCluster(cl)


CmlMagneville/SmaxNanalysis documentation built on Jan. 28, 2024, 11:20 p.m.