Skip to content
Snippets Groups Projects
Commit 32dda8a9 authored by Maria Voigt's avatar Maria Voigt
Browse files

replacing verbose with quiet

parent 31c6d67f
Branches
No related tags found
No related merge requests found
......@@ -35,8 +35,8 @@ option_list <- list (
default=FALSE, help="include aerial transects"),
make_option("--stability", action="store_true", default=FALSE,
help="do stability analysis"),
make_option(c("-v", "--verbose"), dest = "verbose_script", action = "store_true",
default = TRUE, help = "print all intermediate results")
make_option(c("-q", "--quiet"), dest = "quiet_script", action = "store_true",
default = FALSE, help = "don't print all intermediate results")
)
options <- parse_args(OptionParser(option_list=option_list))
......@@ -55,26 +55,26 @@ if (!is.na(options$exclude_year) && !(options$exclude_year %in% exclude_year_pos
stop(paste("exclude year must be between", min(exclude_year_possibilities), "and", max(exclude_year_possibilities)))
}
is_verbose <- options$verbose_script
is_quiet <- options$quiet_script
if(is_verbose){print(paste("Reminder: Include aerial is ", options$include_aerial, ". Please
if(is_quiet){print(paste("Reminder: Include aerial is ", options$include_aerial, ". Please
pay attention that the same is the case for post-processing."))}
# input directory
indir <- options$input_directory
if(is_verbose){print(paste("indir", indir))}
if(is_quiet){print(paste("indir", indir))}
# directory in which output is written
outdir <- options$output_directory
if(is_verbose){print(paste("outdir", outdir))}
if(is_quiet){print(paste("outdir", outdir))}
do_stability <- options$stability
if(is_verbose){print(paste("stability", do_stability))}
if(is_quiet){print(paste("stability", do_stability))}
include_aerial <- options$include_aerial
if(is_verbose){print(paste("include_aerial", include_aerial))}
if(is_quiet){print(paste("include_aerial", include_aerial))}
exclude_year <- options$exclude_year
if(is_verbose){print(paste("exclude year", exclude_year))}
if(is_quiet){print(paste("exclude year", exclude_year))}
......@@ -83,7 +83,7 @@ if(is_verbose){print(paste("exclude year", exclude_year))}
#---------#
indir_fun <- "../functions"
if(is_verbose){print(paste("indir_fun", indir_fun))}
if(is_quiet){print(paste("indir_fun", indir_fun))}
cl <- makeForkCluster(outfile = "")
registerDoParallel(cl)
......@@ -107,16 +107,16 @@ options("scipen" = 100, "digits" = 4)
#---------------#
geography_path <- path.to.current(indir, "geography_observation", "rds")
if(is_verbose){print(paste("geography-path", geography_path))}
if(is_quiet){print(paste("geography-path", geography_path))}
geography <- readRDS(geography_path)
transects_path <- path.to.current(indir, "transects", "rds")
if(is_verbose){print(paste("transect_path", transects_path))}
if(is_quiet){print(paste("transect_path", transects_path))}
transects <- readRDS(transects_path)
predictors_path <- path.to.current(indir, "predictors_observation", "rds")
if(is_verbose){print(paste("predictors-path", predictors_path))}
if(is_quiet){print(paste("predictors-path", predictors_path))}
predictors <- readRDS(predictors_path)
......@@ -129,7 +129,7 @@ predictor_names <- c("year", "temp_mean", "rain_var", "rain_dry", "dom_T_OC",
geography <- dplyr::select(geography, -year)
if(is_verbose){print("how many rows with na in scaled_value")
if(is_quiet){print("how many rows with na in scaled_value")
nrow(predictors[is.na(predictors$scaled_value), ])}
# deleting is.na values here
predictors <- predictors[!is.na(predictors$scaled_value), ]
......@@ -176,7 +176,7 @@ aerial_predictors_obs$nr_nests <- round(exp(4.7297 + 0.9796 *
predictors_obs <- aerial_predictors_obs %>%
dplyr::select(id:length_km, nr_nests, nest_decay, ou_dens, offset_term)
if(is_verbose){ print("This has to be true:")
if(is_quiet){ print("This has to be true:")
unique(names(predictors_obs) == names(other_predictors_obs))}
# HAS TO BE TRUE
predictors_obs <- predictors_obs %>%
......@@ -203,7 +203,7 @@ predictors_obs$y_center <- rowMeans(cbind(predictors_obs$y_start, predictors_obs
predictors_obs$nr_ou_per_km2 <- predictors_obs$nr_nests /
(predictors_obs$length_km * ESW * 2 * predictors_obs$nest_decay * NCS * PNB )
if(is_verbose){print("look at predictors_obs")
if(is_quiet){print("look at predictors_obs")
str(predictors_obs)
summary(predictors_obs)}
......@@ -213,7 +213,7 @@ if (!is.na(exclude_year)){
predictors_excluded_year <- predictors_obs[predictors_obs$unscaled_year == exclude_year, ] }
predictors_obs <- predictors_obs[predictors_obs$unscaled_year != exclude_year, ]
if(is_verbose){ print(paste("3. start making all_model_terms", Sys.time()))}
if(is_quiet){ print(paste("3. start making all_model_terms", Sys.time()))}
# #build models needed for analysis with a function
all_model_terms <- built.all.models(env.cov.names =
......@@ -273,11 +273,11 @@ names(predictor_estimates) <- c("intercept", predictor_names,
# calculate stability of the full model if desired
if(do_stability){
if(is_verbose){print(paste("Start stability calculation", Sys.time()))}
if(is_quiet){print(paste("Start stability calculation", Sys.time()))}
full_model <- paste(
m_terms[all_model_terms[nrow(all_model_terms), ] == 1],
collapse = "+")
if(is_verbose){print(paste("This is the full-model", full_model))}
if(is_quiet){print(paste("This is the full-model", full_model))}
model <- as.formula(
paste("nr_nests ~", full_model, "+ offset(offset_term)"))
......@@ -295,7 +295,7 @@ write.csv(dfbeta_frame, file.path(outdir,
}
# #run models
if(is_verbose){print(paste("8. Start running models", Sys.time()))}
if(is_quiet){print(paste("8. Start running models", Sys.time()))}
if (is.na(exclude_year)){
......@@ -430,4 +430,4 @@ write.csv(summary_mean_coefficients,
save.image(file.path(outdir, paste0("abundance_model_fitting_",
name_suffix,
Sys.Date(), ".RData")))
if(is_verbose){print(paste("11. finished script, finally, at", Sys.time()))}
if(is_quiet){print(paste("11. finished script, finally, at", Sys.time()))}
......@@ -47,8 +47,8 @@ option_list <- list (
type = "integer",
help = "year of the survey years (1994:2015) to predict abundance to",
metavar = "2015"),
make_option(c("-v", "--verbose"), dest = "verbose_script", action = "store_true",
default = TRUE, help = "print all intermediate results")
make_option(c("-q", "--quiet"), dest = "quiet_script", action = "store_true",
default = FALSE, help = "don't print all intermediate results")
)
options <- parse_args(OptionParser(option_list=option_list))
......@@ -84,30 +84,30 @@ if (!(options$year_to_predict %in% year_to_predict_possibilities)) {
}
# is verbose?
is_verbose <- options$verbose_script
# is quiet?
is_quiet <- options$quiet_script
# input directory
indir <- options$input_directory
if(is_verbose){print(paste("indir", indir))}
if(is_quiet){print(paste("indir", indir))}
# input directory
indir_predictors <- options$pred_input_directory
if(is_verbose){print(paste("indir_predictors", indir_predictors))}
if(is_quiet){print(paste("indir_predictors", indir_predictors))}
# directory in which output is written
outdir <- options$output_directory
if(is_verbose){print(paste("outdir", outdir))}
if(is_quiet){print(paste("outdir", outdir))}
year_to_predict <- as.numeric(options$year_to_predict )
if(is_verbose){print(paste("year to predict " , year_to_predict))}
if(is_quiet){print(paste("year to predict " , year_to_predict))}
exclude_year <- as.numeric(options$exclude_year)
if(is_verbose){print(paste("exclude year", exclude_year))}
if(is_quiet){print(paste("exclude year", exclude_year))}
if(is_verbose){print(paste(Sys.time(), "0. start run"))}
if(is_quiet){print(paste(Sys.time(), "0. start run"))}
#------------------------#
# command line arguments #
#------------------------#
......@@ -126,7 +126,7 @@ source(file.path(indir_fun, "generic/path.to.current.R"))
# Load coefficients and weights
abundMod_results_path <- path.to.current(indir, "abundMod_results", "rds" )
if(is_verbose){print(paste("this is abundMod_results_path:", abundMod_results_path))}
if(is_quiet){print(paste("this is abundMod_results_path:", abundMod_results_path))}
abundMod_results <- readRDS(abundMod_results_path)
# exclude the first column, which contains models, exclude the coefficient of the
# autocorellation term and the weighted aic of the model
......@@ -160,19 +160,19 @@ predictor_names <- predictor_names_coeffs[!grepl("I(*)", predictor_names_coeffs)
#----------------------------#
# Load and prepare estimates #
#----------------------------#
if(is_verbose){print(paste("these are predictor names: ", predictor_names))}
if(is_quiet){print(paste("these are predictor names: ", predictor_names))}
predictors_path <- path.to.current(indir_predictors, paste0("predictors_abundance_",
year_to_predict),"rds")
if(is_verbose){print(paste("this is predictors path", predictors_path))}
if(is_quiet){print(paste("this is predictors path", predictors_path))}
predictors <- readRDS(predictors_path) %>%
dplyr::filter(predictor %in% predictor_names) %>%
dcast(id + z_year ~ predictor, value.var = "scaled_value")
predictors$year <- predictors$z_year
predictors$z_year <- NULL
if(is_verbose){str(predictors)}
if(is_quiet){str(predictors)}
if(is_verbose){print(paste("this is nrow predictors", nrow(predictors)))}
if(is_quiet){print(paste("this is nrow predictors", nrow(predictors)))}
#--------------------------#
# PREDICTION FOR each year #
......@@ -196,7 +196,7 @@ names(predictor_estimates) <- c("intercept", predictor_names,
# but takes a bit longer (52s, to 35s for 100 rows)
## PLUS PAY ATTENTION, IF PREDICTIONS NOT SAME NROW--> VALUES GET RECYCLED
if(is_verbose){print(paste("1. start pred_per_cell", Sys.time()))}
if(is_quiet){print(paste("1. start pred_per_cell", Sys.time()))}
pred_per_cell <- foreach(i = 1:nrow(predictor_estimates), .combine = c) %dopar% {
# pred_per_cell <- foreach(i = 1:100, .combine = c) %dopar% {
t_predictor_estimates <- t( predictor_estimates[i, ])
......@@ -207,7 +207,7 @@ pred_estimates_sum <- apply(pred_estimates_wcoeffs, 1, sum)
return(exp(pred_estimates_calc))
}
if(is_verbose){print(paste(Sys.time(), "2. finished dopar loop"))}
if(is_quiet){print(paste(Sys.time(), "2. finished dopar loop"))}
# is this correct -> ????
pred_per_cell <- as.data.frame(cbind(predictors$id, pred_per_cell))
......@@ -252,7 +252,7 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
#-----------------------#
# convert output to map #
#-----------------------#
if(is_verbose){print(paste(Sys.time(), "3. Start making map"))}
if(is_quiet){print(paste(Sys.time(), "3. Start making map"))}
geography_grid_path <- path.to.current(indir_predictors,
paste0("geography_", year_to_predict), "rds")
......@@ -302,4 +302,4 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
if(is_verbose){print(paste(Sys.time(), "4. wrote results and done :-)"))}
if(is_quiet){print(paste(Sys.time(), "4. wrote results and done :-)"))}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment