@@ -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