Skip to content

Commit 9c812d7

Browse files
committed
Large modifications of object names and file names for consistency
1 parent 161a3af commit 9c812d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2654
-2640
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Package: IASDT.R
33
Title: Modelling the distribution of invasive alien plant species in
44
Europe
55
Version: 0.1.09
6-
Date: 2025-09-12
6+
Date: 2025-09-15
77
Authors@R:
88
person("Ahmed", "El-Gabbas", , "ahmed.el-gabbas@ufz.de", role = c("aut", "cre"),
99
comment = c(ORCID = "0000-0003-2225-088X"))

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export("%>%")
44
export(CHELSA_prepare)
55
export(CHELSA_process)
66
export(CHELSA_project)
7-
export(CLC_process)
87
export(EASIN_download)
98
export(EASIN_plot)
109
export(EASIN_process)
@@ -17,6 +16,7 @@ export(IAS_distribution)
1716
export(IAS_plot)
1817
export(IAS_process)
1918
export(bioreg_process)
19+
export(clc_process)
2020
export(coda_to_tibble)
2121
export(convergence_alpha)
2222
export(convergence_beta_ranges)

R/DWF_CHELSA_prepare.R

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ CHELSA_prepare <- function(
3535
# https://www.r-bloggers.com/2019/08/no-visible-binding-for-global-variable/
3636
Variable <- Path_Down <- TimePeriod <- Ext <- ClimateScenario <- Variable <-
3737
Path_CHELSA_In <- File <- Path_Out_tif <- Path_Out_NC <- Path_CHELSA_Out <-
38-
Path_DwnLinks <- URL <- Folder <- URL_File <- ClimateModel <- Exclude <-
39-
BaseURL <- NULL
38+
Path_dwnload_links <- URL <- Folder <- URL_File <- ClimateModel <-
39+
Exclude <- chelsa_base_url <- NULL
4040

4141
# # ..................................................................... ###
4242

4343
# Environment variables -----
44-
EnvVars2Read <- tibble::tribble(
44+
env_vars_to_read <- tibble::tribble(
4545
~var_name, ~value, ~check_dir, ~check_file,
46-
"Path_CHELSA_Out", "DP_R_CHELSA_processed", FALSE, FALSE,
47-
"Path_CHELSA_In", "DP_R_CHELSA_raw", FALSE, FALSE,
48-
"Path_DwnLinks", "DP_R_CHELSA_links", TRUE, FALSE,
49-
"BaseURL", "DP_R_CHELSA_url", FALSE, FALSE)
46+
"Path_CHELSA_Out", "DP_R_chelsa_processed", FALSE, FALSE,
47+
"Path_CHELSA_In", "DP_R_chelsa_raw", FALSE, FALSE,
48+
"Path_dwnload_links", "DP_R_chelsa_links", TRUE, FALSE,
49+
"chelsa_base_url", "DP_R_chelsa_url", FALSE, FALSE)
5050
# Assign environment variables and check file and paths
5151
ecokit::assign_env_vars(
52-
env_file = env_file, env_variables_data = EnvVars2Read)
53-
rm(EnvVars2Read, envir = environment())
52+
env_file = env_file, env_variables_data = env_vars_to_read)
53+
rm(env_vars_to_read, envir = environment())
5454

5555
# # ..................................................................... ###
5656

@@ -74,13 +74,13 @@ CHELSA_prepare <- function(
7474

7575
ecokit::cat_time("Prepare CHELSA metadata", level = 1L)
7676

77-
if (!endsWith(BaseURL, "/")) {
78-
BaseURL <- paste0(BaseURL, "/")
77+
if (!endsWith(chelsa_base_url, "/")) {
78+
chelsa_base_url <- paste0(chelsa_base_url, "/")
7979
}
8080

8181
CHELSA_Metadata <- list.files(
82-
path = Path_DwnLinks, recursive = TRUE, full.names = TRUE,
83-
pattern = "DwnLinks_Climatologies_.+txt$") %>%
82+
path = Path_dwnload_links, recursive = TRUE, full.names = TRUE,
83+
pattern = "dwnload_links_Climatologies_.+txt$") %>%
8484
dplyr::tibble(URL_File = .) %>%
8585
# Add download links
8686
dplyr::mutate(
@@ -89,14 +89,15 @@ CHELSA_prepare <- function(
8989
tidyr::unnest_longer("URL") %>%
9090
dplyr::mutate(
9191
URL = purrr::map_chr(URL, stringr::str_trim),
92-
Folder = purrr::map_chr(URL, stringr::str_remove_all, pattern = BaseURL),
92+
Folder = purrr::map_chr(
93+
URL, stringr::str_remove_all, pattern = chelsa_base_url),
9394
File = purrr::map_chr(Folder, basename),
9495
Folder = purrr::map_chr(Folder, dirname),
9596

9697
# Extract time period
9798
TimePeriod = purrr::map_chr(
9899
URL_File, stringr::str_remove_all,
99-
pattern = "DwnLinks_Climatologies_|.txt"),
100+
pattern = "dwnload_links_Climatologies_|.txt"),
100101

101102
# File extension
102103
Ext = purrr::map_chr(URL, tools::file_ext),

R/DWF_CHELSA_process.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ CHELSA_process <- function(
101101
"Environment file is not found or invalid.", env_file = env_file)
102102
}
103103

104-
EnvVars2Read <- tibble::tribble(
104+
env_vars_to_read <- tibble::tribble(
105105
~var_name, ~value, ~check_dir, ~check_file,
106-
"Path_CHELSA_In", "DP_R_CHELSA_raw", FALSE, FALSE,
107-
"Path_CHELSA_Out", "DP_R_CHELSA_processed", FALSE, FALSE)
106+
"Path_CHELSA_In", "DP_R_chelsa_raw", FALSE, FALSE,
107+
"Path_CHELSA_Out", "DP_R_chelsa_processed", FALSE, FALSE)
108108
# Assign environment variables and check file and paths
109109
ecokit::assign_env_vars(
110-
env_file = env_file, env_variables_data = EnvVars2Read)
111-
rm(EnvVars2Read, envir = environment())
110+
env_file = env_file, env_variables_data = env_vars_to_read)
111+
rm(env_vars_to_read, envir = environment())
112112

113113
# Ensure that the output path exists
114114
fs::dir_create(

R/DWF_CHELSA_project.R

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CHELSA_project <- function(
5050

5151
# Avoid "no visible binding for global variable" message
5252
# https://www.r-bloggers.com/2019/08/no-visible-binding-for-global-variable/
53-
Path_Grid <- NULL
53+
path_grid <- NULL
5454

5555
# # ..................................................................... ###
5656

@@ -74,25 +74,25 @@ CHELSA_project <- function(
7474
"Environment file is not found or invalid.", env_file = env_file)
7575
}
7676

77-
EnvVars2Read <- tibble::tribble(
77+
env_vars_to_read <- tibble::tribble(
7878
~var_name, ~value, ~check_dir, ~check_file,
79-
"Path_Grid", "DP_R_Grid_processed", TRUE, FALSE)
79+
"path_grid", "DP_R_grid_processed", TRUE, FALSE)
8080
# Assign environment variables and check file and paths
8181
ecokit::assign_env_vars(
82-
env_file = env_file, env_variables_data = EnvVars2Read)
83-
rm(EnvVars2Read, envir = environment())
82+
env_file = env_file, env_variables_data = env_vars_to_read)
83+
rm(env_vars_to_read, envir = environment())
8484

8585
# # ..................................................................... ###
8686

8787
# Loading reference grid -----
8888

89-
GridR <- fs::path(Path_Grid, "Grid_10_Land_Crop.RData")
90-
if (!file.exists(GridR)) {
89+
grid_r <- fs::path(path_grid, "grid_10_land_crop.RData")
90+
if (!file.exists(grid_r)) {
9191
ecokit::stop_ctx(
92-
"Path for the Europe boundaries does not exist", GridR = GridR,
92+
"Path for the Europe boundaries does not exist", grid_r = grid_r,
9393
include_backtrace = TRUE)
9494
}
95-
GridR <- ecokit::load_as(GridR, unwrap_r = TRUE)
95+
grid_r <- ecokit::load_as(grid_r, unwrap_r = TRUE)
9696

9797
# # ..................................................................... ###
9898

@@ -108,12 +108,12 @@ CHELSA_project <- function(
108108

109109
# Extent to crop the maps prior to processing. This ensures that the object
110110
# reads from the memory. See below
111-
CropExtent <- terra::ext(-26, 37.5, 34, 72)
111+
crop_extent <- terra::ext(-26, 37.5, 34, 72)
112112

113-
LandMaskL <- system.file(
113+
land_mask_l <- system.file(
114114
"extdata", "LandMask.nc", package = "IASDT.R", mustWork = TRUE) %>%
115115
terra::rast() %>%
116-
terra::crop(CropExtent) %>%
116+
terra::crop(crop_extent) %>%
117117
suppressWarnings() %>% # suppress warning on LUMI while cropping
118118
terra::classify(cbind(0, NA))
119119

@@ -126,22 +126,22 @@ CHELSA_project <- function(
126126
# later consider the scale and offset information manually. This is more safe
127127
# as I found that some of the future projections do not include such
128128
# information in the tiff files.
129-
Rstr <- terra::rast(metadata$Path_Down, raw = TRUE) %>%
129+
r_map <- terra::rast(metadata$Path_Down, raw = TRUE) %>%
130130
stats::setNames(basename(metadata$Path_Down)) %>%
131131
# crop to European boundaries although it is not necessary to crop the input
132132
# maps into the European boundaries, we will crop the data prior to
133133
# projection. Cropping will make the values of the raster read from memory
134134
# not from the file. This is a workaround to avoid wrong extreme values in
135135
# the output file because of a bug in terra package (see this issue:
136136
# https://github.com/rspatial/terra/issues/1356) [18.02.2023]
137-
terra::crop(CropExtent) %>%
137+
terra::crop(crop_extent) %>%
138138
# mask by land mask
139-
terra::mask(LandMaskL) %>%
139+
terra::mask(land_mask_l) %>%
140140
# `gsp` maps contains extremely high values instead of NA; the following
141141
# replace extreme values with NA
142142
terra::classify(cbind(420000000, Inf, NA))
143143

144-
rm(LandMaskL, CropExtent, envir = environment())
144+
rm(land_mask_l, crop_extent, envir = environment())
145145

146146
# # ..................................................................... ###
147147

@@ -150,21 +150,21 @@ CHELSA_project <- function(
150150
# For `npp` layers, all tiff maps except for current climate does have a
151151
# scaling factor all scale and offset information were set manually
152152
if (metadata$scale != 1) {
153-
Rstr <- Rstr * metadata$scale
153+
r_map <- r_map * metadata$scale
154154
}
155155
if (metadata$offset != 0) {
156-
Rstr <- Rstr + metadata$offset
156+
r_map <- r_map + metadata$offset
157157
}
158158

159159
# # ..................................................................... ###
160160

161161
# Projecting to reference grid EPSG 3035 ------
162162

163-
Rstr <- Rstr %>%
163+
r_map <- r_map %>%
164164
# project to reference grid
165-
terra::project(GridR, method = "average", threads = TRUE) %>%
165+
terra::project(grid_r, method = "average", threads = TRUE) %>%
166166
# mask to the reference grid
167-
terra::mask(GridR) %>%
167+
terra::mask(grid_r) %>%
168168
# Ensure that values are read from memory
169169
terra::toMemory() %>%
170170
ecokit::set_raster_crs(crs = "epsg:3035")
@@ -174,22 +174,22 @@ CHELSA_project <- function(
174174
# Write file to disk --- tiff -----
175175

176176
terra::writeRaster(
177-
x = Rstr, filename = metadata$Path_Out_tif, overwrite = TRUE,
177+
x = r_map, filename = metadata$Path_Out_tif, overwrite = TRUE,
178178
gdal = c("COMPRESS=DEFLATE", "TILED=YES"))
179179

180180
# # ..................................................................... ###
181181

182182
# Write file to disk --- nc -----
183183

184184
# Variable name of the output *.nc file
185-
VarName4NC <- c(
185+
var_name_for_nc <- c(
186186
metadata$TimePeriod, metadata$ClimateModel, metadata$ClimateScenario) %>%
187187
unique() %>%
188188
paste(collapse = "__") %>%
189189
paste0(metadata$Variable, "__", .)
190190

191191
# global attributes to be added to the *.nc file
192-
Attrs <- c(
192+
attributes <- c(
193193
paste0("URL=", metadata$URL),
194194
paste0("OriginalFile=", metadata$Path_Down),
195195
paste0("Variable=", metadata$Variable),
@@ -202,10 +202,10 @@ CHELSA_project <- function(
202202

203203
# save as *.nc file
204204
terra::writeCDF(
205-
Rstr,
206-
filename = metadata$Path_Out_NC, varname = VarName4NC,
205+
r_map,
206+
filename = metadata$Path_Out_NC, varname = var_name_for_nc,
207207
unit = metadata$unit, zname = metadata$TimePeriod,
208-
atts = Attrs, overwrite = TRUE, compression = compression_level)
208+
atts = attributes, overwrite = TRUE, compression = compression_level)
209209

210210
# # ..................................................................... ###
211211

0 commit comments

Comments
 (0)