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
95b784d8
Commit
95b784d8
authored
8 years ago
by
Maria Voigt
Browse files
Options
Downloads
Patches
Plain Diff
fixing problems in map making
parent
b4cffdd5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/prediction/abundance_prediction.R
+25
-14
25 additions, 14 deletions
src/prediction/abundance_prediction.R
with
25 additions
and
14 deletions
src/prediction/abundance_prediction.R
+
25
−
14
View file @
95b784d8
...
@@ -37,7 +37,9 @@ year_to_predict <- as.numeric(args[4])
...
@@ -37,7 +37,9 @@ year_to_predict <- as.numeric(args[4])
print
(
paste
(
"year "
,
year_to_predict
))
print
(
paste
(
"year "
,
year_to_predict
))
indir_fun
<-
"~/orangutan_density_distribution/src/functions/"
indir_fun
<-
"~/orangutan_density_distribution/src/functions/"
crs_aea
<-
"+proj=aea +lat_1=7 +lat_2=-32 +lat_0=-15 +lon_0=125 +x_0=0
+y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
# final projection
#-------------------------------#
#-------------------------------#
# Load and prepare coefficients #
# Load and prepare coefficients #
...
@@ -156,35 +158,44 @@ saveRDS(pred_per_cell,
...
@@ -156,35 +158,44 @@ saveRDS(pred_per_cell,
year_to_predict
,
"_"
,
year_to_predict
,
"_"
,
Sys.Date
(),
".rds"
)))
Sys.Date
(),
".rds"
)))
save.image
(
file.path
(
outdir
,
"image_before_map.RData"
))
#-----------------------#
#-----------------------#
# convert output to map #
# convert output to map #
#-----------------------#
#-----------------------#
print
(
paste
(
Sys.time
(),
"3. Start making map"
))
print
(
paste
(
Sys.time
(),
"3. Start making map"
))
estimates_prediction
<-
cbind
(
predictors
,
pred_per_cell
)
%>%
geography_grid_path
<-
path.to.current
(
indir_predictors
,
paste0
(
"geography_"
,
year_to_predict
),
"rds"
)
geography_grid
<-
readRDS
(
geography_grid_path
)
geography_grid_for_join
<-
dplyr
::
select
(
geography_grid
,
id
,
x_start
,
y_start
)
pred_per_cell_sp
<-
left_join
(
geography_grid_for_join
,
pred_per_cell
,
by
=
"id"
)
%>%
as.data.frame
()
as.data.frame
()
estimates_prediction_sp
<-
SpatialPointsDataFrame
(
coords
=
cbind
(
estimates_prediction
$
x_start
,
pred_per_cell_sp
<-
SpatialPointsDataFrame
(
coords
=
estimates_prediction
$
y_start
),
cbind
(
pred_per_cell_sp
$
x_start
,
data
=
estimates_prediction
,
pred_per_cell_sp
$
y_start
),
data
=
pred_per_cell_sp
,
proj4string
=
CRS
(
crs_aea
),
match.ID
=
T
)
proj4string
=
CRS
(
crs_aea
),
match.ID
=
T
)
writeOGR
(
estimates_prediction
_sp
,
dsn
=
outdir
,
writeOGR
(
pred_per_cell
_sp
,
dsn
=
outdir
,
layer
=
paste0
(
"prediction_shp_"
,
year
),
driver
=
"ESRI Shapefile"
)
layer
=
paste0
(
"prediction_shp_"
,
year
_to_predict
),
driver
=
"ESRI Shapefile"
)
# pay attention that the tif gets a new name because later we delete all
# pay attention that the tif gets a new name because later we delete all
# with the same name as the shapefile
# with the same name as the shapefile
system_string
<-
paste0
(
"gdal_rasterize -ot 'Float32' -a
prdctn
_ "
,
system_string
<-
paste0
(
"gdal_rasterize -ot 'Float32' -a
abndnc
_ "
,
"-tr 1000.0 1000.0 -l prediction_s
ample
_"
,
"-tr 1000.0 1000.0 -l prediction_s
hp
_"
,
year
,
" "
,
outdir
,
"/"
,
year
_to_predict
,
" "
,
outdir
,
"/"
,
"prediction_shp_"
,
year
,
".shp"
,
"prediction_shp_"
,
year
_to_predict
,
".shp"
,
" "
,
outdir
,
"/"
,
" "
,
outdir
,
"/"
,
"prediction_map_"
,
year
,
".tif"
)
"prediction_map_"
,
year
_to_predict
,
".tif"
)
system
(
system_string
)
system
(
system_string
)
#delete the shapefile again because clogs up my system
#delete the shapefile again because clogs up my system
system_string_del
<-
paste0
(
"rm -f "
,
outdir
,
"/prediction_shp_"
,
system_string_del
<-
paste0
(
"rm -f "
,
outdir
,
"/prediction_shp_"
,
year
,
".*"
)
year
_to_predict
,
".*"
)
system
(
system_string_del
)
system
(
system_string_del
)
...
...
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