Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ClimDatDownloadR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jentsch, Helge
ClimDatDownloadR
Commits
68c83015
Commit
68c83015
authored
2 years ago
by
Jentsch, Helge
Browse files
Options
Downloads
Patches
Plain Diff
WC CMIP6 Update
parent
d4800b20
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
DESCRIPTION
+1
-1
1 addition, 1 deletion
DESCRIPTION
R/WorldClim_download_functions.R
+106
-65
106 additions, 65 deletions
R/WorldClim_download_functions.R
man/WorldClim.CMIP_6.download.Rd
+4
-2
4 additions, 2 deletions
man/WorldClim.CMIP_6.download.Rd
with
111 additions
and
68 deletions
DESCRIPTION
+
1
−
1
View file @
68c83015
...
@@ -45,7 +45,7 @@ Suggests: knitr, testthat, usethis, rmarkdown
...
@@ -45,7 +45,7 @@ Suggests: knitr, testthat, usethis, rmarkdown
VignetteBuilder: knitr
VignetteBuilder: knitr
SystemRequirements: Tested with at least 4 GB RAM.
SystemRequirements: Tested with at least 4 GB RAM.
NeedsCompilation: no
NeedsCompilation: no
Packaged: 2023-0
5-11 12:43:2
1 UTC; helge
Packaged: 2023-0
6-23 12:34:0
1 UTC; helge
Author: Helge Jentsch [aut, cre],
Author: Helge Jentsch [aut, cre],
Maria Bobrowski [aut],
Maria Bobrowski [aut],
Johannes Weidinger [aut],
Johannes Weidinger [aut],
...
...
This diff is collapsed.
Click to expand it.
R/WorldClim_download_functions.R
+
106
−
65
View file @
68c83015
...
@@ -1135,9 +1135,20 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
...
@@ -1135,9 +1135,20 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
bio.var
=
c
(
1
:
19
),
bio.var
=
c
(
1
:
19
),
month.var
=
c
(
1
:
12
),
month.var
=
c
(
1
:
12
),
resolution
=
c
(
"10min"
,
"5min"
,
"2.5min"
,
"30s"
),
resolution
=
c
(
"10min"
,
"5min"
,
"2.5min"
,
"30s"
),
model.var
=
c
(
"BCC-CSM2-MR"
,
"CNRM-CM6-1"
,
model.var
=
c
(
"ACCESS-CM2"
,
"BCC-CSM2-MR"
,
"CMCC-ESM2"
,
"CNRM-CM6-1"
,
"CNRM-ESM2-1"
,
"CanESM5"
,
"CNRM-ESM2-1"
,
"CanESM5"
,
"GFDL-ESM4"
,
"IPSL-CM6A-LR"
,
"EC-Earth3-Veg"
,
"FIO-ESM-2-0"
,
"GFDL-ESM4"
,
"GISS-E2-1-G"
,
"HadGEM3-GC31-LL"
,
"INM-CM5-0"
,
"IPSL-CM6A-LR"
,
"MPI-ESM1-2-HR"
,
"MRI-ESM2-0"
,
"UKESM1-0-LL"
,
"MIROC-ES2L"
,
"MIROC6"
,
"MIROC-ES2L"
,
"MIROC6"
,
"MRI-ESM2-0"
),
"MRI-ESM2-0"
),
emission.scenario.var
=
c
(
"ssp126"
,
emission.scenario.var
=
c
(
"ssp126"
,
...
@@ -1193,8 +1204,8 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
...
@@ -1193,8 +1204,8 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
# First: Set URL Root --------------------------------------------------------
# First: Set URL Root --------------------------------------------------------
# https://geodata.ucdavis.edu/cmip6/30s/ACCESS-CM2/ssp126/wc2.1_30s_tmin_ACCESS-CM2_ssp126_2021-2040.tif
URL.1
<-
"http://
bio
geo.ucdavis.edu/
data/worldclim/v2.1/fut
/"
URL.1
<-
"http
s
://geo
data
.ucdavis.edu/
cmip6
/"
# Second: Parameters ---------------------------------------------------------
# Second: Parameters ---------------------------------------------------------
for
(
parm
in
parameter
){
for
(
parm
in
parameter
){
...
@@ -1258,15 +1269,17 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
...
@@ -1258,15 +1269,17 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
# temp.temp.save.location <- normalizePath(temp.temp.save.location,
# temp.temp.save.location <- normalizePath(temp.temp.save.location,
# winslash = "/")
# winslash = "/")
dest.temp
<-
paste0
(
temp.temp.save.location
,
"WC_"
,
res
,
"_"
,
dest.temp
<-
paste0
(
temp.temp.save.location
,
"WC_"
,
res
,
"_"
,
gcm
,
"_"
,
rcp.temp
,
"_"
,
year.temp
,
"_Bulk.
zip
"
)
gcm
,
"_"
,
rcp.temp
,
"_"
,
year.temp
,
"_Bulk.
tif
"
)
URL.3
<-
paste0
(
"
wc2.1_"
,
res.temp
,
"_"
,
parm.temp
,
"_"
,
gcm
,
"_
"
,
URL.3
<-
paste0
(
"
"
,
gcm
,
"/"
,
rcp.temp
,
"/
"
,
rcp.temp
,
"_"
,
year.temp
)
"wc2.1_"
,
res.temp
,
"_"
,
parm.temp
,
"_"
,
gcm
,
"_"
,
rcp.temp
,
"_"
,
year.temp
)
print
(
URL.3
)
print
(
URL.3
)
if
(
!
file.exists
(
dest.temp
)){
if
(
!
file.exists
(
dest.temp
)){
# create a variable for the later requested Download-URL to avoid
# create a variable for the later requested Download-URL to avoid
# requireing multiple changes, if the link changes.
# requireing multiple changes, if the link changes.
URL.temp
<-
paste0
(
URL.1
,
URL.2
,
URL.3
,
".zip"
)
URL.temp
<-
paste0
(
URL.1
,
URL.2
,
URL.3
,
".tif"
)
# check if URL is available
# check if URL is available
# if(url.exists(URL.temp)){
# if(url.exists(URL.temp)){
if
(
RCurl
::
url.exists
(
url
=
URL.temp
)){
if
(
RCurl
::
url.exists
(
url
=
URL.temp
)){
...
@@ -1295,63 +1308,89 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
...
@@ -1295,63 +1308,89 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
next
()
next
()
}
}
}
}
# Unzip the files of the Bulk-Download-Zip-File
# # Unzip the files of the Bulk-Download-Zip-File
files.list
<-
list.files
(
temp.temp.save.location
,
# files.list <- list.files(temp.temp.save.location,
pattern
=
".zip"
,
# pattern = ".zip",
# full.names = T)
# for (file in files.list) {
# unzip(file,
# exdir = stringr::str_sub(temp.temp.save.location,
# start = 0,
# end = stringr::str_length(temp.temp.save.location)-1)
# )
# file.copy(from = paste0(list.files(temp.temp.save.location,
# pattern = paste0(URL.3, ".tif"),
# recursive = TRUE,
# full.names = TRUE))[1],
# to = paste0(temp.temp.save.location,
# URL.3,"_stacked_RAW.tif"),
# overwrite = TRUE)
# if(dir.exists(paste0(temp.temp.save.location,"//share"))){
# unlink(paste0(temp.temp.save.location,"//share"),
# recursive = TRUE)
#
# }
# tif.list <- list.files(temp.temp.save.location,
# pattern = "stacked_RAW.tif",
# recursive = TRUE,
# full.names = TRUE)
# print(tif.list)
# if (!is.null(tif.list)){
# if(length(tif.list)==1){
# raster.temp <- raster::unstack(raster::stack(tif.list))
# if(parm != "bio"){
# for(layer.month in month.var){
# writeRaster(x = raster.temp[[layer.month]],
# filename = paste0(temp.temp.save.location,
# URL.3,"_",layer.month,".tif"),
# overwrite = TRUE
# )
# }
# }else{
# for(layer.bio in bio.var){
# writeRaster(x = raster.temp[[layer.bio]],
# filename = paste0(temp.temp.save.location,
# URL.3,"_",layer.bio,".tif"),
# overwrite = TRUE
# )
# }
# }
# }
# unlink(tif.list)
# }
# if(keep.raw.zip == FALSE){
# print(file)
# unlink(file)
# }
# }
temp.bulkfile
<-
list.files
(
path
=
temp.temp.save.location
,
pattern
=
"Bulk.tif"
,
full.names
=
T
)
full.names
=
T
)
for
(
file
in
files.list
)
{
temp.rast
<-
rast
(
temp.bulkfile
)
unzip
(
file
,
if
(
parm
==
"bio"
){
exdir
=
stringr
::
str_sub
(
temp.temp.save.location
,
temp.rast
<-
temp.rast
[[
bio.var
]]
start
=
0
,
end
=
stringr
::
str_length
(
temp.temp.save.location
)
-1
)
)
file.copy
(
from
=
paste0
(
list.files
(
temp.temp.save.location
,
pattern
=
paste0
(
URL.3
,
".tif"
),
recursive
=
TRUE
,
full.names
=
TRUE
))[
1
],
to
=
paste0
(
temp.temp.save.location
,
URL.3
,
"_stacked_RAW.tif"
),
overwrite
=
TRUE
)
if
(
dir.exists
(
paste0
(
temp.temp.save.location
,
"//share"
))){
unlink
(
paste0
(
temp.temp.save.location
,
"//share"
),
recursive
=
TRUE
)
}
tif.list
<-
list.files
(
temp.temp.save.location
,
pattern
=
"stacked_RAW.tif"
,
recursive
=
TRUE
,
full.names
=
TRUE
)
print
(
tif.list
)
if
(
!
is.null
(
tif.list
)){
if
(
length
(
tif.list
)
==
1
){
raster.temp
<-
raster
::
unstack
(
raster
::
stack
(
tif.list
))
if
(
parm
!=
"bio"
){
for
(
layer.month
in
month.var
){
writeRaster
(
x
=
raster.temp
[[
layer.month
]],
filename
=
paste0
(
temp.temp.save.location
,
URL.3
,
"_"
,
layer.month
,
".tif"
),
overwrite
=
TRUE
)
}
}
else
{
}
else
{
for
(
layer.bio
in
bio.var
){
temp.rast
<-
temp.rast
[[
month.var
]]
writeRaster
(
x
=
raster.temp
[[
layer.bio
]],
filename
=
paste0
(
temp.temp.save.location
,
URL.3
,
"_"
,
layer.bio
,
".tif"
),
overwrite
=
TRUE
)
}
}
for
(
lyr.temp
in
seq
(
1
,
terra
::
nlyr
(
temp.rast
),
1
)){
lyrName
<-
names
(
temp.rast
[[
lyr.temp
]])
lyrName
<-
paste0
(
stringr
::
str_sub
(
temp.bulkfile
,
end
=
-9
),
lyrName
,
".tif"
)
terra
::
writeRaster
(
temp.rast
[[
lyr.temp
]],
filename
=
lyrName
,
overwrite
=
TRUE
)
}
}
}
unlink
(
tif.list
)
if
(
!
dir.exists
(
paths
=
paste0
(
temp.temp.save.location
,
"/Bulk/"
))){
}
dir.create
(
paste0
(
temp.temp.save.location
,
"/Bulk/"
))
if
(
keep.raw.zip
==
FALSE
){
print
(
file
)
unlink
(
file
)
}
}
}
# print(ls())
file.copy
(
from
=
temp.bulkfile
,
to
=
paste0
(
temp.temp.save.location
,
"/Bulk/"
,
basename
(
temp.bulkfile
)))
unlink
(
temp.bulkfile
,
force
=
T
)
# Hier weiter mit alle-betreffenden Bearbeitungen
# Hier weiter mit alle-betreffenden Bearbeitungen
# print(list.files(temp.temp.save.location, pattern = ".tif", full.names = FALSE))
# print(list.files(temp.temp.save.location, pattern = ".tif", full.names = FALSE))
...
@@ -1430,6 +1469,8 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
...
@@ -1430,6 +1469,8 @@ WorldClim.CMIP_6.download <- function(save.location = "./",
include.dirs
=
FALSE
,
include.dirs
=
FALSE
,
full.names
=
T
),
full.names
=
T
),
force
=
TRUE
)
force
=
TRUE
)
unlink
(
x
=
paste0
(
temp.temp.save.location
,
"/Bulk/"
),
recursive
=
T
)
}
}
# if no subdirectories and files are to be found in the 2nd order
# if no subdirectories and files are to be found in the 2nd order
# subdirectory the directory will be deleted for a better overview of
# subdirectory the directory will be deleted for a better overview of
...
...
This diff is collapsed.
Click to expand it.
man/WorldClim.CMIP_6.download.Rd
+
4
−
2
View file @
68c83015
...
@@ -10,8 +10,10 @@ WorldClim.CMIP_6.download(
...
@@ -10,8 +10,10 @@ WorldClim.CMIP_6.download(
bio.var = c(1:19),
bio.var = c(1:19),
month.var = c(1:12),
month.var = c(1:12),
resolution = c("10min", "5min", "2.5min", "30s"),
resolution = c("10min", "5min", "2.5min", "30s"),
model.var = c("BCC-CSM2-MR", "CNRM-CM6-1", "CNRM-ESM2-1", "CanESM5", "GFDL-ESM4",
model.var = c("ACCESS-CM2", "BCC-CSM2-MR", "CMCC-ESM2", "CNRM-CM6-1", "CNRM-ESM2-1",
"IPSL-CM6A-LR", "MIROC-ES2L", "MIROC6", "MRI-ESM2-0"),
"CanESM5", "EC-Earth3-Veg", "FIO-ESM-2-0", "GFDL-ESM4", "GISS-E2-1-G",
"HadGEM3-GC31-LL", "INM-CM5-0", "IPSL-CM6A-LR", "MPI-ESM1-2-HR", "MRI-ESM2-0",
"UKESM1-0-LL", "MIROC-ES2L", "MIROC6", "MRI-ESM2-0"),
emission.scenario.var = c("ssp126", "ssp245", "ssp370", "ssp585"),
emission.scenario.var = c("ssp126", "ssp245", "ssp370", "ssp585"),
time.interval.var = c("2021-2040", "2041-2060", "2061-2080", "2081-2100"),
time.interval.var = c("2021-2040", "2041-2060", "2061-2080", "2081-2100"),
clipping = FALSE,
clipping = FALSE,
...
...
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