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
32dda8a9
Commit
32dda8a9
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
replacing verbose with quiet
parent
31c6d67f
Branches
Branches containing commit
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
+21
-21
21 additions, 21 deletions
src/model_fitting/abundance_model.R
src/prediction/abundance_prediction.R
+19
-19
19 additions, 19 deletions
src/prediction/abundance_prediction.R
with
40 additions
and
40 deletions
src/model_fitting/abundance_model.R
+
21
−
21
View file @
32dda8a9
...
...
@@ -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
=
TRU
E
,
help
=
"print all intermediate results"
)
make_option
(
c
(
"-
q
"
,
"--
quiet
"
),
dest
=
"
quiet
_script"
,
action
=
"store_true"
,
default
=
FALS
E
,
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
()))}
This diff is collapsed.
Click to expand it.
src/prediction/abundance_prediction.R
+
19
−
19
View file @
32dda8a9
...
...
@@ -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
=
TRU
E
,
help
=
"print all intermediate results"
)
make_option
(
c
(
"-
q
"
,
"--
quiet
"
),
dest
=
"
quiet
_script"
,
action
=
"store_true"
,
default
=
FALS
E
,
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 :-)"
))}
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