Skip to content

Commit

Permalink
v0.0.2 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejMottl authored Apr 6, 2023
1 parent 4158a77 commit 9358aab
Show file tree
Hide file tree
Showing 32 changed files with 794 additions and 451 deletions.
196 changes: 86 additions & 110 deletions R/00_Config_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,114 @@
#
#
# O. Mottl, S. Flantua, K. Bhatta, V. Felde, A. Seddon
# 2021
# 2023
#
#----------------------------------------------------------#

# Configuration script with the variables that should be consistent throughout
# the whole repo. It loads packages, defines important variables,
# authorises the user, and saves config file.
# authorises the user, and saves the config file.
# Points that require the user’s attention are flagged by "[USER]" - flag,
# meaning that these are criteria that need to be checked by the user

# Version of the Workflow
workflow_version <-
"0.0.1"
"0.0.2"

# set the current environment
# Set the current environment
current_env <- environment()

#----------------------------------------------------------#
# 1. Load packages -----
#----------------------------------------------------------#

if
(
!exists("update_repo_packages", envir = current_env)
if (
isFALSE(
exists("already_synch", envir = current_env)
)
) {
update_repo_packages <- TRUE
already_synch <- FALSE
}

if
(
update_repo_packages == TRUE
if (
isFALSE(already_synch)
) {
library(here)
# Synchronise the package versions
renv::restore(
lockfile = here::here("renv/library_list.lock")
)
already_synch <- TRUE

# install RFossilpol from github
if
(
!exists("already_installed_RFossilpol", envir = current_env)
) {
already_installed_RFossilpol <- FALSE
}

if
(
already_installed_RFossilpol == FALSE
) {
devtools::install_github("HOPE-UIB-BIO/R-Fossilpol-package",
quiet = FALSE,
upgrade = FALSE
)
already_installed_RFossilpol <- TRUE
}

if
(
!exists("already_synch", envir = current_env)
) {
already_synch <- FALSE
}

if
(
already_synch == FALSE) {
library(here)
# synchronise the package versions
renv::restore(lockfile = here::here("renv/library_list.lock"))
already_synch <- TRUE

# save snapshot of package versions
# renv::snapshot(lockfile = "renv/library_list.lock") # do only for update
}
# Save snapshot of package versions
# renv::snapshot(lockfile = "renv/library_list.lock") # do only for update
}

# define packages
# Define packages
package_list <-
c(
"devtools",
"Bchron",
"RFossilpol",
"RUtilpol",
"here",
"tidyverse"
)

# load all packages
# Attach all packages
sapply(package_list, library, character.only = TRUE)


#----------------------------------------------------------#
# 2. Define space -----
# 2. Current date and working directory -----
#----------------------------------------------------------#

current_date <- Sys.Date()

# project directory is set up by 'here' package, Adjust if needed
# Project directory is set up by the {here} package, Adjust if needed
current_dir <- here::here()

# Define the directory (external) for storing big data files
# Default is in the current project
data_storage_path <- current_dir # [USER]

# Create all essential folders
RFossilpol::util_make_datastorage_folders(
dir = data_storage_path # [config_criteria]
)

#----------------------------------------------------------#
# 3. Load functions -----
#----------------------------------------------------------#

# get vector of general functions
# Get a vector of general functions
fun_list <-
list.files(
path = "R/Functions/",
pattern = "*.R",
recursive = TRUE
)

# source them
# Load the function into the global environment
sapply(
paste0("R/Functions/", fun_list, sep = ""),
source
)


#----------------------------------------------------------#
# 4. Define the directories (for big files) -----
#----------------------------------------------------------#

# Define the directory (external) for storing big data files
# Default is in the current project
data_storage_path <- current_dir # [USER]

# create all essential folders
RFossilpol::util_make_datastorage_folders(
dir = data_storage_path # [config_criteria]
)


#--------------------------------------------------#
# 4.1 Project dataset database -----
# 4. Project dataset database -----
#--------------------------------------------------#

# check the presence of dataset database and create it if necessary
if
(
FALSE ==
# Check the presence of a dataset database and create it if necessary
if (
isFALSE(
"project_dataset_database.rds" %in%
list.files(
paste0(
data_storage_path, # [config_criteria]
"/Data/Personal_database_storage"
)
)
)
) {
project_dataset_database <-
RFossilpol:::proj_db_class()
Expand Down Expand Up @@ -179,7 +145,7 @@ dataset_type <- "pollen"
# Selected variable element (proxy)
sel_var_element <- "pollen"

# geographical limitation of data
# Set geographical boundaries
long_min <- -180 # [USER]
long_max <- 180 # [USER]
lat_min <- -90 # [USER]
Expand All @@ -189,8 +155,8 @@ alt_max <- NA # [USER]

neotoma_new_download <- TRUE

# define access to private datasets
private_data <- FALSE # [USER]
# Define access to datasets from other sources than Neotoma
use_other_datasource <- FALSE # [USER]
detect_duplicates <- TRUE # [USER]

# Include/exclude age modelling in run
Expand Down Expand Up @@ -225,22 +191,23 @@ chron_order <-
# 5.5. Age depth models -----
#--------------------------------------------------#

# Chronology needs to have at least X control points
# Chronology needs to have at least X control points [example: X=2]
min_n_of_control_points <- 2 # [USER]

# If thickness of control point is missing, assign X cm
# If the thickness of a control point is missing, assign X cm [example: X=1]
default_thickness <- 1 # [USER]

# If age error of control point is missing, assign X yr
# If the age error of a control point is missing, assign X yr [example: X=100]
default_error <- 100 # [USER]

# maximum accepted age error of chron.control point
# Maximum accepted age error of chron.control point [example: X=3000]
max_age_error <- 3000 # [USER]

# depth at which "Guess" is accepted as chronology control point
# Depth at which "Guess" is accepted as a chronology control
# point [example: X=10]
guess_depth <- 10 # [USER]

# bchron settings
# Bchron settings
number_of_cores <- parallel::detectCores() - 1
batch_size <- number_of_cores * 3
set_seed <- 1234
Expand All @@ -252,92 +219,101 @@ iteration_multiplier <- 5 # [USER]


#--------------------------------------------------#
# 5.6. Level filtering criteria -----
# 5.6. Filtering criteria -----
#--------------------------------------------------#

# criteria to filter out levels and sequences
# Criteria to filter out stratigraphic levels and pollen records

#----------------------------------------#

# Pollen sums
filter_by_pollen_sum <- TRUE # [USER]

# each level at least X individual pollen gains
# Each stratigraphic level of at least X individual pollen gains [example: X=0]
min_n_grains <- 0 # [USER]
# ideal number of counts
# Ideal number of counts
target_n_grains <- 100 # [USER]
# threshold of number of samples with ideal counts
# Threshold of number of samples with ideal counts
percentage_samples <- 0 # [USER]

#----------------------------------------#

# Age limits
# Note that the actual ages have to specified per region, defined during the
# process of Workflow
# Note that the actual ages have to be specified per region, defined during
# the process of Workflow
filter_by_age_limit <- TRUE # [USER]

#----------------------------------------#

# Maximum extrapolation
filter_by_extrapolation <- TRUE # [USER]

# how much age can be extrapolated beyond the oldest chronology control point
# How much age can be extrapolated beyond the oldest chronology control point?
maximum_age_extrapolation <- Inf # [USER]

#----------------------------------------#

# Beyond period of interest
# Note that the actual ages have to specified per region, defined during the
# process of Workflow
# Beyond the period of interest
# Note that the actual ages have to be specified per region, defined during
# the process of Workflow
filter_by_interest_region <- TRUE # [USER]

#----------------------------------------#

# Number of levels
# Number of stratigraphic levels
filter_by_number_of_levels <- TRUE # [USER]

# at least X number levels within period of interest
# At least X number of stratigraphic levels within the period
# of interest [example: X=3]
min_n_levels <- 3

#----------------------------------------#

# Additional setting

# Should 95th age quantile be used for data filtration?
# This will result in more stable data assembly between different result
# of AD modelling BUT require additional data preparation before analytical
# part
# Should the 95th age quantile be used for data filtration?
# If FALSE (default), the estimated age will be used for all checks about the
# age of a stratigraphic level. However, if TRUE, then the 95th age quantile
# will be used.
# This will result in more stable data assembly between different results
# of age-depth modelling BUT require additional data preparation before
# the analytical part.
use_age_quantiles <- FALSE # [USER]

# Should all data filtration omit one additional level in the old period?
# This will result of "bookend" level, which can help to provide anchor
# information after the period of interest
# Should all data filtration omit one additional stratigraphic level in
# the old period?
# If TRUE, all filtering will proceed normally but one additional "bookend"
# stratigraphic level will be always kept.
# A "bookend" stratigraphic level is a subsequential stratigraphic level
# older than the oldest stratigraphic level that passed the filtration.
# A "bookend" can help provide anchor information older than the period of
# interest.
use_bookend_level <- FALSE # [USER]


#----------------------------------------------------------#
# 7. Graphical option -----
# 6. Set graphical options -----
#----------------------------------------------------------#

# set ggplot output
# Set ggplot output
ggplot2::theme_set(
ggplot2::theme_classic()
)

# define general
# Define general
text_size <- 16 # [USER]
line_size <- 0.1 # [USER]
point_size <- 3 # [USER]

# define output sizes
# Define output sizes
image_width <- 30 # [USER]
image_height <- 15 # [USER]
image_units <- "cm" # [USER]
image_dpi <- 300 # [USER]

# define pallets
# Define pallets

# define common colours
# Define common colours


#----------------------------------------------------------#
Expand Down
Loading

0 comments on commit 9358aab

Please sign in to comment.