Skip to content

Commit

Permalink
climateWithObs
Browse files Browse the repository at this point in the history
Adding this parameter to restrict the climate space to where calibration data are available
  • Loading branch information
mchevalier2 committed Nov 23, 2023
1 parent 0a4c037 commit 52f81ac
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RoxygenNote: 7.2.3
Imports:
clipr,
DBI,
data.table,
methods,
openxlsx,
plot3D,
Expand Down
16 changes: 15 additions & 1 deletion R/crest.get_modern_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ crest.get_modern_data <- function( pse, taxaType, climate,
basins = NA, sectors = NA,
realms = NA, biomes = NA, ecoregions = NA,
minGridCells = 20,
climateWithObs = FALSE,
elev_min = NA, elev_max = NA, elev_range = NA,
year_min = 1900, year_max = 2021, nodate = TRUE,
type_of_obs = c(1, 2, 3, 8, 9),
Expand Down Expand Up @@ -363,6 +364,7 @@ crest.get_modern_data <- function( pse, taxaType, climate,
year_min=year_min, year_max=year_max, nodate=nodate,
type_of_obs=type_of_obs,
selectedTaxa = selectedTaxa,
climateWithObs=climateWithObs,
dbname=dbname
)
crest$misc[['taxa_notes']] <- taxa_notes
Expand Down Expand Up @@ -615,10 +617,22 @@ crest.get_modern_data <- function( pse, taxaType, climate,
}

crest$modelling$climate_space <- crest$modelling$climate_space[order(crest$modelling$climate_space$longitude, crest$modelling$climate_space$latitude), ]
crest$modelling$crest <- crest$modelling$biome_space[order(crest$modelling$biome_space$longitude, crest$modelling$biome_space$latitude), ]
crest$modelling$biome_space <- crest$modelling$biome_space[order(crest$modelling$biome_space$longitude, crest$modelling$biome_space$latitude), ]

}

if(climateWithObs) {
df <- lapply(crest$modelling$distributions, function(x) return(unique(x[, c('longitude', 'latitude')])))
df <- as.data.frame(unique(data.table::rbindlist(df)))
df <- paste(df[, 'longitude'], df[, 'latitude'], sep='_')

cs_idx <- paste(crest$modelling$climate_space[, 'longitude'], crest$modelling$climate_space[, 'latitude'], sep='_')
crest$modelling$climate_space <- crest$modelling$climate_space[cs_idx %in% df, ]

cs_idx <- paste(crest$modelling$biome_space[, 'longitude'], crest$modelling$biome_space[, 'latitude'], sep='_')
crest$modelling$biome_space <- crest$modelling$biome_space[cs_idx %in% df, ]
}

if (ai.sqrt & 'ai' %in% crest$parameters$climate) {
crest$modelling$climate_space[, "ai"] <- sqrt(crest$modelling$climate_space[, "ai"])
for (tax in crest$inputs$taxa.name) {
Expand Down
6 changes: 6 additions & 0 deletions R/crestObj.init.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
#' @param climateSpaceWeighting.type A correction factor for the clame space
#' weighting correction to limit the edge effects. Either 'linear'
#' (default), 'sqrt' or 'log'.
#' @param climateWithObs A boolean to indicate whether all climate values from
#' the calibration dataset be included (\code{FALSE}, default) or only the
#' climate values that corresponds to proxy observations (\code{TRUE}).
#' Only useful in if the climate space weighting is activated.
#' @param presenceThreshold All values above that threshold will be used in the
#' reconstruction (e.g. if set at 1, all percentages below 1 will be set
#' to 0 and the associated presences discarded). Default is 0.
Expand Down Expand Up @@ -96,6 +100,7 @@ crestObj <- function(taxa.name, taxaType, climate,
geoWeighting = TRUE,
climateSpaceWeighting = TRUE,
climateSpaceWeighting.type = 'linear',
climateWithObs = FALSE,
selectedTaxa = NA,
distributions = NA,
presenceThreshold = 0,
Expand Down Expand Up @@ -154,6 +159,7 @@ crestObj <- function(taxa.name, taxaType, climate,
geoWeighting = geoWeighting,
climateSpaceWeighting = climateSpaceWeighting,
climateSpaceWeighting.type = climateSpaceWeighting.type,
climateWithObs = climateWithObs,
presenceThreshold = presenceThreshold,
uncertainties = uncertainties
)
Expand Down
3 changes: 3 additions & 0 deletions R/crestObj.print.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ print.crestObj <- function(x, as=x$misc$stage, ...) {
cat(paste0('* x Weighting of the climate space ........... ',x$parameters$climateSpaceWeighting, '\n'))
cat(paste0("* Using a ",x$parameters$climateSpaceWeighting.type," correction\n"))
}
if(!is.na(x$parameters$climateSpaceWeighting)) {
cat(paste0('* x Restriction to climate with observations . ',x$parameters$climateWithObs, '\n'))
}
cat(paste0('* x Shape of the PDFs ........................ ',x$parameters$climate[1], ': ', x$parameters$shape[x$parameters$climate[1], 1], '\n'))
for(clim in x$parameters$climate[-1]) {
cat(paste0('* ', paste(rep('_', nchar('Shape of the PDFs ........................')), collapse=''), ' ',clim, ': ', x$parameters$shape[clim, 1], '\n'))
Expand Down
3 changes: 2 additions & 1 deletion R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ export <- function( x, dataname = x$misc$site_info$site_name,
df <- rbind(df, c(NA, paste0('Climate Space Weighting: ', ifelse(x$parameters$climateSpaceWeighting, 'Yes', 'No')), NA, NA, NA))
if (x$parameters$climateSpaceWeighting) df <- rbind(df, c(NA, paste0(' - Using correction: ', x$parameters$climateSpaceWeighting.type), NA, NA, NA))
if (x$parameters$climateSpaceWeighting) df <- rbind(df, c(NA, paste0(' - Bin width: ', x$parameters$bin_width[clim, ]), NA, NA, NA))
df <- rbind(df, c(NA, paste0('Restricting climate space to grid cells with observation: ', ifelse(x$parameters$climateWithObs, 'Yes', 'No')), NA, NA, NA))
df <- rbind(df, c(NA, paste0('Species weighted by abundance: ', ifelse(x$parameters$geoWeighting, 'Yes', 'No')), NA, NA, NA))
df <- rbind(df, c(NA, paste0('Shape of the spcies pdfs: ', x$parameters$shape[clim, ]), NA, NA, NA))
df <- rbind(df, c(NA, paste0('Shape of the species pdfs: ', x$parameters$shape[clim, ]), NA, NA, NA))
df <- rbind(df, c(NA, paste0('Number of points: ', x$parameters$npoints), NA, NA, NA))
df <- rbind(df, rep(NA, 5))
df <- rbind(df, rep(NA, 5))
Expand Down
Binary file modified crestr_1.3.0.9000.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions man/crest.get_modern_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/crestObj.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52f81ac

Please sign in to comment.