Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
manuscript_code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maria Voigt
manuscript_code
Commits
6df35c73
Commit
6df35c73
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
fixing all the is_quiet to is_verbose and verbose_script
parent
78045345
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/model_fitting/abundance_model.R
+19
-19
19 additions, 19 deletions
src/model_fitting/abundance_model.R
src/prediction/abundance_prediction.R
+16
-16
16 additions, 16 deletions
src/prediction/abundance_prediction.R
with
35 additions
and
35 deletions
src/model_fitting/abundance_model.R
+
19
−
19
View file @
6df35c73
...
@@ -60,26 +60,26 @@ if (!is.na(options$exclude_year) && !(options$exclude_year %in% exclude_year_pos
...
@@ -60,26 +60,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
)))
stop
(
paste
(
"exclude year must be between"
,
min
(
exclude_year_possibilities
),
"and"
,
max
(
exclude_year_possibilities
)))
}
}
is_
quiet
<-
options
$
quiet
_script
is_
verbose
<-
options
$
verbose
_script
if
(
is_
quiet
){
print
(
paste
(
"Reminder: Include aerial is "
,
options
$
include_aerial
,
". Please
if
(
is_
verbose
){
print
(
paste
(
"Reminder: Include aerial is "
,
options
$
include_aerial
,
". Please
pay attention that the same is the case for post-processing."
))}
pay attention that the same is the case for post-processing."
))}
# input directory
# input directory
indir
<-
options
$
input_directory
indir
<-
options
$
input_directory
if
(
is_
quiet
){
print
(
paste
(
"indir"
,
indir
))}
if
(
is_
verbose
){
print
(
paste
(
"indir"
,
indir
))}
# directory in which output is written
# directory in which output is written
outdir
<-
options
$
output_directory
outdir
<-
options
$
output_directory
if
(
is_
quiet
){
print
(
paste
(
"outdir"
,
outdir
))}
if
(
is_
verbose
){
print
(
paste
(
"outdir"
,
outdir
))}
do_stability
<-
options
$
stability
do_stability
<-
options
$
stability
if
(
is_
quiet
){
print
(
paste
(
"stability"
,
do_stability
))}
if
(
is_
verbose
){
print
(
paste
(
"stability"
,
do_stability
))}
include_aerial
<-
options
$
include_aerial
include_aerial
<-
options
$
include_aerial
if
(
is_
quiet
){
print
(
paste
(
"include_aerial"
,
include_aerial
))}
if
(
is_
verbose
){
print
(
paste
(
"include_aerial"
,
include_aerial
))}
exclude_year
<-
options
$
exclude_year
exclude_year
<-
options
$
exclude_year
if
(
is_
quiet
){
print
(
paste
(
"exclude year"
,
exclude_year
))}
if
(
is_
verbose
){
print
(
paste
(
"exclude year"
,
exclude_year
))}
...
@@ -88,7 +88,7 @@ if(is_quiet){print(paste("exclude year", exclude_year))}
...
@@ -88,7 +88,7 @@ if(is_quiet){print(paste("exclude year", exclude_year))}
#---------#
#---------#
indir_fun
<-
"../functions"
indir_fun
<-
"../functions"
if
(
is_
quiet
){
print
(
paste
(
"indir_fun"
,
indir_fun
))}
if
(
is_
verbose
){
print
(
paste
(
"indir_fun"
,
indir_fun
))}
cl
<-
makeForkCluster
(
outfile
=
""
)
cl
<-
makeForkCluster
(
outfile
=
""
)
registerDoParallel
(
cl
)
registerDoParallel
(
cl
)
...
@@ -112,16 +112,16 @@ options("scipen" = 100, "digits" = 4)
...
@@ -112,16 +112,16 @@ options("scipen" = 100, "digits" = 4)
#---------------#
#---------------#
geography_path
<-
path.to.current
(
indir
,
"geography_observation"
,
"rds"
)
geography_path
<-
path.to.current
(
indir
,
"geography_observation"
,
"rds"
)
if
(
is_
quiet
){
print
(
paste
(
"geography-path"
,
geography_path
))}
if
(
is_
verbose
){
print
(
paste
(
"geography-path"
,
geography_path
))}
geography
<-
readRDS
(
geography_path
)
geography
<-
readRDS
(
geography_path
)
transects_path
<-
path.to.current
(
indir
,
"transects"
,
"rds"
)
transects_path
<-
path.to.current
(
indir
,
"transects"
,
"rds"
)
if
(
is_
quiet
){
print
(
paste
(
"transect_path"
,
transects_path
))}
if
(
is_
verbose
){
print
(
paste
(
"transect_path"
,
transects_path
))}
transects
<-
readRDS
(
transects_path
)
transects
<-
readRDS
(
transects_path
)
predictors_path
<-
path.to.current
(
indir
,
"predictors_observation"
,
"rds"
)
predictors_path
<-
path.to.current
(
indir
,
"predictors_observation"
,
"rds"
)
if
(
is_
quiet
){
print
(
paste
(
"predictors-path"
,
predictors_path
))}
if
(
is_
verbose
){
print
(
paste
(
"predictors-path"
,
predictors_path
))}
predictors
<-
readRDS
(
predictors_path
)
predictors
<-
readRDS
(
predictors_path
)
...
@@ -134,7 +134,7 @@ predictor_names <- c("year", "temp_mean", "rain_var", "rain_dry", "dom_T_OC",
...
@@ -134,7 +134,7 @@ predictor_names <- c("year", "temp_mean", "rain_var", "rain_dry", "dom_T_OC",
geography
<-
dplyr
::
select
(
geography
,
-
year
)
geography
<-
dplyr
::
select
(
geography
,
-
year
)
if
(
is_
quiet
){
print
(
"how many rows with na in scaled_value"
)
if
(
is_
verbose
){
print
(
"how many rows with na in scaled_value"
)
nrow
(
predictors
[
is.na
(
predictors
$
scaled_value
),
])}
nrow
(
predictors
[
is.na
(
predictors
$
scaled_value
),
])}
# deleting is.na values here
# deleting is.na values here
predictors
<-
predictors
[
!
is.na
(
predictors
$
scaled_value
),
]
predictors
<-
predictors
[
!
is.na
(
predictors
$
scaled_value
),
]
...
@@ -181,7 +181,7 @@ aerial_predictors_obs$nr_nests <- round(exp(4.7297 + 0.9796 *
...
@@ -181,7 +181,7 @@ aerial_predictors_obs$nr_nests <- round(exp(4.7297 + 0.9796 *
predictors_obs
<-
aerial_predictors_obs
%>%
predictors_obs
<-
aerial_predictors_obs
%>%
dplyr
::
select
(
id
:
length_km
,
nr_nests
,
nest_decay
,
ou_dens
,
offset_term
)
dplyr
::
select
(
id
:
length_km
,
nr_nests
,
nest_decay
,
ou_dens
,
offset_term
)
if
(
is_
quiet
){
print
(
"This has to be true:"
)
if
(
is_
verbose
){
print
(
"This has to be true:"
)
unique
(
names
(
predictors_obs
)
==
names
(
other_predictors_obs
))}
unique
(
names
(
predictors_obs
)
==
names
(
other_predictors_obs
))}
# HAS TO BE TRUE
# HAS TO BE TRUE
predictors_obs
<-
predictors_obs
%>%
predictors_obs
<-
predictors_obs
%>%
...
@@ -208,7 +208,7 @@ predictors_obs$y_center <- rowMeans(cbind(predictors_obs$y_start, predictors_obs
...
@@ -208,7 +208,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
$
nr_ou_per_km2
<-
predictors_obs
$
nr_nests
/
(
predictors_obs
$
length_km
*
ESW
*
2
*
predictors_obs
$
nest_decay
*
NCS
*
PNB
)
(
predictors_obs
$
length_km
*
ESW
*
2
*
predictors_obs
$
nest_decay
*
NCS
*
PNB
)
if
(
is_
quiet
){
print
(
"look at predictors_obs"
)
if
(
is_
verbose
){
print
(
"look at predictors_obs"
)
str
(
predictors_obs
)
str
(
predictors_obs
)
summary
(
predictors_obs
)}
summary
(
predictors_obs
)}
...
@@ -218,7 +218,7 @@ if (!is.na(exclude_year)){
...
@@ -218,7 +218,7 @@ if (!is.na(exclude_year)){
predictors_excluded_year
<-
predictors_obs
[
predictors_obs
$
unscaled_year
==
exclude_year
,
]
}
predictors_excluded_year
<-
predictors_obs
[
predictors_obs
$
unscaled_year
==
exclude_year
,
]
}
predictors_obs
<-
predictors_obs
[
predictors_obs
$
unscaled_year
!=
exclude_year
,
]
predictors_obs
<-
predictors_obs
[
predictors_obs
$
unscaled_year
!=
exclude_year
,
]
if
(
is_
quiet
){
print
(
paste
(
"3. start making all_model_terms"
,
Sys.time
()))}
if
(
is_
verbose
){
print
(
paste
(
"3. start making all_model_terms"
,
Sys.time
()))}
# #build models needed for analysis with a function
# #build models needed for analysis with a function
all_model_terms
<-
built.all.models
(
env.cov.names
=
all_model_terms
<-
built.all.models
(
env.cov.names
=
...
@@ -278,11 +278,11 @@ names(predictor_estimates) <- c("intercept", predictor_names,
...
@@ -278,11 +278,11 @@ names(predictor_estimates) <- c("intercept", predictor_names,
# calculate stability of the full model if desired
# calculate stability of the full model if desired
if
(
do_stability
){
if
(
do_stability
){
if
(
is_
quiet
){
print
(
paste
(
"Start stability calculation"
,
Sys.time
()))}
if
(
is_
verbose
){
print
(
paste
(
"Start stability calculation"
,
Sys.time
()))}
full_model
<-
paste
(
full_model
<-
paste
(
m_terms
[
all_model_terms
[
nrow
(
all_model_terms
),
]
==
1
],
m_terms
[
all_model_terms
[
nrow
(
all_model_terms
),
]
==
1
],
collapse
=
"+"
)
collapse
=
"+"
)
if
(
is_
quiet
){
print
(
paste
(
"This is the full-model"
,
full_model
))}
if
(
is_
verbose
){
print
(
paste
(
"This is the full-model"
,
full_model
))}
model
<-
as.formula
(
model
<-
as.formula
(
paste
(
"nr_nests ~"
,
full_model
,
"+ offset(offset_term)"
))
paste
(
"nr_nests ~"
,
full_model
,
"+ offset(offset_term)"
))
...
@@ -300,7 +300,7 @@ write.csv(dfbeta_frame, file.path(outdir,
...
@@ -300,7 +300,7 @@ write.csv(dfbeta_frame, file.path(outdir,
}
}
# #run models
# #run models
if
(
is_
quiet
){
print
(
paste
(
"8. Start running models"
,
Sys.time
()))}
if
(
is_
verbose
){
print
(
paste
(
"8. Start running models"
,
Sys.time
()))}
if
(
is.na
(
exclude_year
)){
if
(
is.na
(
exclude_year
)){
...
@@ -435,4 +435,4 @@ write.csv(summary_mean_coefficients,
...
@@ -435,4 +435,4 @@ write.csv(summary_mean_coefficients,
save.image
(
file.path
(
outdir
,
paste0
(
"abundance_model_fitting_"
,
save.image
(
file.path
(
outdir
,
paste0
(
"abundance_model_fitting_"
,
name_suffix
,
name_suffix
,
Sys.Date
(),
".RData"
)))
Sys.Date
(),
".RData"
)))
if
(
is_
quiet
){
print
(
paste
(
"11. finished script, finally, at"
,
Sys.time
()))}
if
(
is_
verbose
){
print
(
paste
(
"11. finished script, finally, at"
,
Sys.time
()))}
This diff is collapsed.
Click to expand it.
src/prediction/abundance_prediction.R
+
16
−
16
View file @
6df35c73
...
@@ -91,29 +91,29 @@ if (!(options$year_to_predict %in% year_to_predict_possibilities)) {
...
@@ -91,29 +91,29 @@ if (!(options$year_to_predict %in% year_to_predict_possibilities)) {
# is quiet?
# is quiet?
is_
quiet
<-
options
$
quiet
_script
is_
verbose
<-
options
$
verbose
_script
# input directory
# input directory
indir
<-
options
$
input_directory
indir
<-
options
$
input_directory
if
(
is_
quiet
){
print
(
paste
(
"indir"
,
indir
))}
if
(
is_
verbose
){
print
(
paste
(
"indir"
,
indir
))}
# input directory
# input directory
indir_predictors
<-
options
$
pred_input_directory
indir_predictors
<-
options
$
pred_input_directory
if
(
is_
quiet
){
print
(
paste
(
"indir_predictors"
,
indir_predictors
))}
if
(
is_
verbose
){
print
(
paste
(
"indir_predictors"
,
indir_predictors
))}
# directory in which output is written
# directory in which output is written
outdir
<-
options
$
output_directory
outdir
<-
options
$
output_directory
if
(
is_
quiet
){
print
(
paste
(
"outdir"
,
outdir
))}
if
(
is_
verbose
){
print
(
paste
(
"outdir"
,
outdir
))}
year_to_predict
<-
as.numeric
(
options
$
year_to_predict
)
year_to_predict
<-
as.numeric
(
options
$
year_to_predict
)
if
(
is_
quiet
){
print
(
paste
(
"year to predict "
,
year_to_predict
))}
if
(
is_
verbose
){
print
(
paste
(
"year to predict "
,
year_to_predict
))}
exclude_year
<-
as.numeric
(
options
$
exclude_year
)
exclude_year
<-
as.numeric
(
options
$
exclude_year
)
if
(
is_
quiet
){
print
(
paste
(
"exclude year"
,
exclude_year
))}
if
(
is_
verbose
){
print
(
paste
(
"exclude year"
,
exclude_year
))}
if
(
is_
quiet
){
print
(
paste
(
Sys.time
(),
"0. start run"
))}
if
(
is_
verbose
){
print
(
paste
(
Sys.time
(),
"0. start run"
))}
#------------------------#
#------------------------#
# command line arguments #
# command line arguments #
#------------------------#
#------------------------#
...
@@ -132,7 +132,7 @@ source(file.path(indir_fun, "generic/path.to.current.R"))
...
@@ -132,7 +132,7 @@ source(file.path(indir_fun, "generic/path.to.current.R"))
# Load coefficients and weights
# Load coefficients and weights
abundMod_results_path
<-
path.to.current
(
indir
,
"abundMod_results"
,
"rds"
)
abundMod_results_path
<-
path.to.current
(
indir
,
"abundMod_results"
,
"rds"
)
if
(
is_
quiet
){
print
(
paste
(
"this is abundMod_results_path:"
,
abundMod_results_path
))}
if
(
is_
verbose
){
print
(
paste
(
"this is abundMod_results_path:"
,
abundMod_results_path
))}
abundMod_results
<-
readRDS
(
abundMod_results_path
)
abundMod_results
<-
readRDS
(
abundMod_results_path
)
# exclude the first column, which contains models, exclude the coefficient of the
# exclude the first column, which contains models, exclude the coefficient of the
# autocorellation term and the weighted aic of the model
# autocorellation term and the weighted aic of the model
...
@@ -166,19 +166,19 @@ predictor_names <- predictor_names_coeffs[!grepl("I(*)", predictor_names_coeffs)
...
@@ -166,19 +166,19 @@ predictor_names <- predictor_names_coeffs[!grepl("I(*)", predictor_names_coeffs)
#----------------------------#
#----------------------------#
# Load and prepare estimates #
# Load and prepare estimates #
#----------------------------#
#----------------------------#
if
(
is_
quiet
){
print
(
paste
(
"these are predictor names: "
,
predictor_names
))}
if
(
is_
verbose
){
print
(
paste
(
"these are predictor names: "
,
predictor_names
))}
predictors_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"predictors_abundance_"
,
predictors_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"predictors_abundance_"
,
year_to_predict
),
"rds"
)
year_to_predict
),
"rds"
)
if
(
is_
quiet
){
print
(
paste
(
"this is predictors path"
,
predictors_path
))}
if
(
is_
verbose
){
print
(
paste
(
"this is predictors path"
,
predictors_path
))}
predictors
<-
readRDS
(
predictors_path
)
%>%
predictors
<-
readRDS
(
predictors_path
)
%>%
dplyr
::
filter
(
predictor
%in%
predictor_names
)
%>%
dplyr
::
filter
(
predictor
%in%
predictor_names
)
%>%
dcast
(
id
+
z_year
~
predictor
,
value.var
=
"scaled_value"
)
dcast
(
id
+
z_year
~
predictor
,
value.var
=
"scaled_value"
)
predictors
$
year
<-
predictors
$
z_year
predictors
$
year
<-
predictors
$
z_year
predictors
$
z_year
<-
NULL
predictors
$
z_year
<-
NULL
if
(
is_
quiet
){
str
(
predictors
)}
if
(
is_
verbose
){
str
(
predictors
)}
if
(
is_
quiet
){
print
(
paste
(
"this is nrow predictors"
,
nrow
(
predictors
)))}
if
(
is_
verbose
){
print
(
paste
(
"this is nrow predictors"
,
nrow
(
predictors
)))}
#--------------------------#
#--------------------------#
# PREDICTION FOR each year #
# PREDICTION FOR each year #
...
@@ -202,7 +202,7 @@ names(predictor_estimates) <- c("intercept", predictor_names,
...
@@ -202,7 +202,7 @@ names(predictor_estimates) <- c("intercept", predictor_names,
# but takes a bit longer (52s, to 35s for 100 rows)
# but takes a bit longer (52s, to 35s for 100 rows)
## PLUS PAY ATTENTION, IF PREDICTIONS NOT SAME NROW--> VALUES GET RECYCLED
## PLUS PAY ATTENTION, IF PREDICTIONS NOT SAME NROW--> VALUES GET RECYCLED
if
(
is_
quiet
){
print
(
paste
(
"1. start pred_per_cell"
,
Sys.time
()))}
if
(
is_
verbose
){
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
:
nrow
(
predictor_estimates
),
.combine
=
c
)
%dopar%
{
# pred_per_cell <- foreach(i = 1:100, .combine = c) %dopar% {
# pred_per_cell <- foreach(i = 1:100, .combine = c) %dopar% {
t_predictor_estimates
<-
t
(
predictor_estimates
[
i
,
])
t_predictor_estimates
<-
t
(
predictor_estimates
[
i
,
])
...
@@ -213,7 +213,7 @@ pred_estimates_sum <- apply(pred_estimates_wcoeffs, 1, sum)
...
@@ -213,7 +213,7 @@ pred_estimates_sum <- apply(pred_estimates_wcoeffs, 1, sum)
return
(
exp
(
pred_estimates_calc
))
return
(
exp
(
pred_estimates_calc
))
}
}
if
(
is_
quiet
){
print
(
paste
(
Sys.time
(),
"2. finished dopar loop"
))}
if
(
is_
verbose
){
print
(
paste
(
Sys.time
(),
"2. finished dopar loop"
))}
# is this correct -> ????
# is this correct -> ????
pred_per_cell
<-
as.data.frame
(
cbind
(
predictors
$
id
,
pred_per_cell
))
pred_per_cell
<-
as.data.frame
(
cbind
(
predictors
$
id
,
pred_per_cell
))
...
@@ -258,7 +258,7 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
...
@@ -258,7 +258,7 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
#-----------------------#
#-----------------------#
# convert output to map #
# convert output to map #
#-----------------------#
#-----------------------#
if
(
is_
quiet
){
print
(
paste
(
Sys.time
(),
"3. Start making map"
))}
if
(
is_
verbose
){
print
(
paste
(
Sys.time
(),
"3. Start making map"
))}
geography_grid_path
<-
path.to.current
(
indir_predictors
,
geography_grid_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"geography_"
,
year_to_predict
),
"rds"
)
paste0
(
"geography_"
,
year_to_predict
),
"rds"
)
...
@@ -308,4 +308,4 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
...
@@ -308,4 +308,4 @@ save.image(file.path(outdir, paste0("abundance_pred_image_", name_suffix,
if
(
is_
quiet
){
print
(
paste
(
Sys.time
(),
"4. wrote results and done :-)"
))}
if
(
is_
verbose
){
print
(
paste
(
Sys.time
(),
"4. wrote results and done :-)"
))}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment