#' @importFrom lubridate make_date
#' @export
urls_filter <- function(files, mip_era = "CMIP6", period = NULL, ...){
DATE_MAX <- "2101-01-01" # for rcp
scenario <- get_scenario(files[1])
is_rcp <- grepl("rcp|RCP|ssp|SSP", scenario)
# filter ensembles
inds <- seq_along(files)
ensembles <- extract_ensemble(files)
if (mip_era == "CMIP5") {
if (!grepl("historicalMisc|misc|Misc", scenario)) {
nchar = 6
ind <- which(substr(ensembles, 1, nchar) == substr("r1i1p1f1", 1, nchar))
inds <- inds[ind]
files <- files[ind]
}
} else if (mip_era == "CMIP6") {
nchar = 6 # r1i1p1f1, or r1i1p1
ind <- which(substr(ensembles, 1, nchar) == substr("r1i1p1f1", 1, nchar))
inds <- inds[ind]
files <- files[ind]
}
if (is_rcp) period <- c(2006, 2100)
dfile <- CMIP5Files_filter(files, duration = NULL, period = period, verbose = 1)
# if (is_rcp) dfile <- dfile[ensemble == "r1i1p1", ]
# if (is_rcp || grepl(scenario, "piControl|picontrol"))
if (is_rcp) {
# this part is not used
dfile_full <- CMIP5Files_filter(files, duration = NULL, verbose = 0)
d_22 <- dfile_full[start >= DATE_MAX, ]
cat(sprintf('[m] %s files out of 21th century ... \n', num_bad(nrow(d_22))))
if (nrow(d_22) > 0) {
ds <- CMIP5Files_summary(d_22)
print(head(ds))
}
}
ok(sprintf('[ok] %s duplicated file removed.\n', length(files) - nrow(dfile)))
dfile
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.