-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.timeslices_1000BCE_0CE.R
648 lines (535 loc) · 32.9 KB
/
3.timeslices_1000BCE_0CE.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
### Timeslices - preparation of files for each timeID
### Date 19/03/2024
### Author: Mercedes Roman Dobarco
### Objective: Prepare the HYDE3.2 data layer for the period 1000 BCE - 1 CE at thedesired temporal resolution
# analysis packages
library(dplyr)
library(tidyverse)
library(sf)
library(terra)
# visualization packages
library(ggplot2)
library(viridis)
library(scales)
library(viridisLite)
library(rasterVis)
# 1. HYDE - 1000 BCE - 0CE ---------------------------------------------------
### We have HYDE for 1000 BCE - 1 BCE (millenial stime step), e.g. grazing1000BC_Fr.tif -- timeID_0
### And we have HYDE 0 CE - 99 CE (centennial time step), e.g., grazing0AD_Fr.tif -- -- timeID_10
### set output wd
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices")
timeSteps <- c(0:10)
for(i in 1:length(timeSteps)){dir.create(paste0("TimeID_",timeSteps[[i]]))}
increment.hyde.1000BCE_0CE.func <- function(TimeID_10,TimeID_0,type_increment, name) {
### Make a SpatRaster
input <- c(TimeID_0,TimeID_10)
### Prepare input raster stacks
total_change <- terra::lapp(input, fun=function(x,y){return(y-x)})
b <- terra::lapp(input, fun=function(x,y){return((y/x)^0.1)})
input2 <- c(TimeID_0,total_change)
input3 <- c(TimeID_0, b)
if (type_increment=="linear") {
TimeID_1 = terra::lapp(input2, fun=function(x,y){return(x+(0.1*y))},
filename=paste0("TimeID_1/",name,"_timeID_1.tif"),
overwrite=TRUE)
TimeID_2 = terra::lapp(input2, fun=function(x,y){return(x+(0.2*y))},
filename=paste0("TimeID_2/",name,"_timeID_2.tif"),
overwrite=TRUE)
TimeID_3 = terra::lapp(input2, fun=function(x,y){return(x+(0.3*y))},
filename=paste0("TimeID_3/",name,"_timeID_3.tif"),
overwrite=TRUE)
TimeID_4 = terra::lapp(input2, fun=function(x,y){return(x+(0.4*y))},
filename=paste0("TimeID_4/",name,"_timeID_4.tif"),
overwrite=TRUE)
TimeID_5 = terra::lapp(input2, fun=function(x,y){return(x+(0.5*y))},
filename=paste0("TimeID_5/",name,"_timeID_5.tif"),
overwrite=TRUE)
TimeID_6 = terra::lapp(input2, fun=function(x,y){return(x+(0.6*y))},
filename=paste0("TimeID_6/",name,"_timeID_6.tif"),
overwrite=TRUE)
TimeID_7 = terra::lapp(input2, fun=function(x,y){return(x+(0.7*y))},
filename=paste0("TimeID_7/",name,"_timeID_7.tif"),
overwrite=TRUE)
TimeID_8 = terra::lapp(input2, fun=function(x,y){return(x+(0.8*y))},
filename=paste0("TimeID_8/",name,"_timeID_8.tif"),
overwrite=TRUE)
TimeID_9 = terra::lapp(input2, fun=function(x,y){return(x+(0.9*y))},
filename=paste0("TimeID_9/",name,"_timeID_9.tif"),
overwrite=TRUE)
} else if (type_increment=="exponential"){
TimeID_1 = terra::lapp(input3, fun=function(x,y){return(x*(y^1))},
filename=paste0("TimeID_1/",name,"_timeID_1.tif"),
overwrite=TRUE)
TimeID_2 = terra::lapp(input3, fun=function(x,y){return(x*(y^2))},
filename=paste0("TimeID_2/",name,"_timeID_2.tif"),
overwrite=TRUE)
TimeID_3 = terra::lapp(input3, fun=function(x,y){return(x*(y^3))},
filename=paste0("TimeID_3/",name,"_timeID_3.tif"),
overwrite=TRUE)
TimeID_4 = terra::lapp(input3, fun=function(x,y){return(x*(y^4))},
filename=paste0("TimeID_4/",name,"_timeID_4.tif"),
overwrite=TRUE)
TimeID_5 = terra::lapp(input3, fun=function(x,y){return(x*(y^5))},
filename=paste0("TimeID_5/",name,"_timeID_5.tif"),
overwrite=TRUE)
TimeID_6 = terra::lapp(input3, fun=function(x,y){return(x*(y^6))},
filename=paste0("TimeID_6/",name,"_timeID_6.tif"),
overwrite=TRUE)
TimeID_7 = terra::lapp(input3, fun=function(x,y){return(x*(y^7))},
filename=paste0("TimeID_7/",name,"_timeID_7.tif"),
overwrite=TRUE)
TimeID_8 = terra::lapp(input3, fun=function(x,y){return(x*(y^8))},
filename=paste0("TimeID_8/",name,"_timeID_8.tif"),
overwrite=TRUE)
TimeID_9 = terra::lapp(input3, fun=function(x,y){return(x*(y^9))},
filename=paste0("TimeID_9/",name,"_timeID_9.tif"),
overwrite=TRUE)
}
### return raster stack
hyde.gradual <- c(TimeID_1,TimeID_2,TimeID_3,TimeID_4,TimeID_5,TimeID_6,TimeID_7,TimeID_8,TimeID_9)
plot(hyde.gradual)
return(hyde.gradual)
}
# TimeID10 <- 25
# TimeID0 <- 0.6
# #TimeID10= a*(b^10)
# #TimeID0= a*(b^0)
# #TimeID10/TimeID0 = (b^10)
# b=(TimeID10/TimeID0)^(1/10)
# a=TimeID0
# exponential.inc <- function(x) {a*(b^x)}
# y <- exponential.inc(x)
# x <- 0:10
# plot(x,y)
### Time ID 0
### Copy and rename files
setwd("D:/HYDE/HYDE3.2/unzip/h1000BC_lu/")
files_1000BCE <- list.files(pattern=".tif")
file.copy(from = paste0("D:/HYDE/HYDE3.2/unzip/h1000BC_lu/",files_1000BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE),
pattern="1000BC_Fr",
replacement="_timeID_0"))
### Time ID 10
### Copy and rename files
setwd("D:/HYDE/HYDE3.2/unzip/h0AD_lu/")
files_0CE <- list.files(pattern=".tif")
file.copy(from = paste0("D:/HYDE/HYDE3.2/unzip/h0AD_lu/",files_0CE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE),
pattern="0AD_Fr",
replacement="_timeID_10"))
### Process HYDE variables for time steps in between
### Select HYDE 3.2 variables
### cropping
### grazing
### total irrigation
HydeVars <- c("cropland","grazing","pasture","rangeland",
"conv_rangeland","tot_irri","tot_rainfed","tot_rice",
"ir_norice","rf_norice","ir_rice","rf_rice")
### Cropland
cropland_timeID_0 <- rast("./TimeID_0/cropland_timeID_0.tif")
cropland_timeID_10 <- rast("./TimeID_10/cropland_timeID_10.tif")
plot(cropland_timeID_0)
plot(cropland_timeID_10)
cropland_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = cropland_timeID_10,
TimeID_0 = cropland_timeID_0,
type_increment = "linear",
name = "cropland_l")
cropland_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = cropland_timeID_10,
TimeID_0 = cropland_timeID_0,
type_increment = "exponential",
name = "cropland_e")
cropland <- c(cropland_timeID_0,cropland_1000BCE_0CE,cropland_timeID_10)
names(cropland) <- c("crop2900BP", "crop2800BP", "crop2700BP", "crop2600BP", "crop2500BP", "crop2400BP",
"crop2300BP", "crop2200BP", "crop2100BP", "crop2000BP", "crop1900BP")
plot(cropland)
rasterVis::levelplot(cropland, par.settings = viridisTheme)
### grazing
grazing_timeID_0 <- rast("./TimeID_0/grazing_timeID_0.tif")
grazing_timeID_10 <- rast("./TimeID_10/grazing_timeID_10.tif")
plot(grazing_timeID_0)
plot(grazing_timeID_10)
grazing_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = grazing_timeID_10,
TimeID_0 = grazing_timeID_0,
type_increment = "linear",
name = "grazing_l")
grazing_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = grazing_timeID_10,
TimeID_0 = grazing_timeID_0,
type_increment = "exponential",
name = "grazing_e")
grazing <- c(grazing_timeID_0,grazing_1000BCE_0CE,grazing_timeID_10)
names(grazing) <- c("graz2900BP", "graz2800BP", "graz2700BP", "graz2600BP", "graz2500BP", "graz2400BP",
"graz2300BP", "graz2200BP", "graz2100BP", "graz2000BP", "graz1900BP")
plot(grazing)
rasterVis::levelplot(grazing, par.settings = viridisTheme)
### pasture
pasture_timeID_0 <- rast("./TimeID_0/pasture_timeID_0.tif")
pasture_timeID_10 <- rast("./TimeID_10/pasture_timeID_10.tif")
plot(pasture_timeID_0)
plot(pasture_timeID_10)
pasture_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = pasture_timeID_10,
TimeID_0 = pasture_timeID_0,
type_increment = "linear",
name = "pasture_l")
pasture <- c(pasture_timeID_0,pasture_1000BCE_0CE,pasture_timeID_10)
names(pasture) <- c("pasture2900BP", "pasture2800BP", "pasture2700BP", "pasture2600BP", "pasture2500BP", "pasture2400BP",
"pasture2300BP", "pasture2200BP", "pasture2100BP", "pasture2000BP", "pasture1900BP")
plot(pasture)
rasterVis::levelplot(pasture, par.settings = viridisTheme)
# pasture_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = pasture_timeID_10,
# TimeID_0 = pasture_timeID_0,
# type_increment = "exponential",
# name = "pasture_e")
#
# pasture <- c(pasture_timeID_0,pasture_1000BCE_0CE,pasture_timeID_10)
# names(pasture) <- c("2900BP", "2800BP", "2700BP", "2600BP", "2500BP", "2400BP",
# "2300BP", "2200BP", "2100BP", "2000BP", "1900BP")
# plot(pasture)
### Exponential change does not work well because the term "a" ia 0 and everything is predicted as 0
### rangeland
# rangeland_timeID_0 <- rast("./TimeID_0/rangeland_timeID_0.tif")
# rangeland_timeID_10 <- rast("./TimeID_10/rangeland_timeID_10.tif")
# plot(rangeland_timeID_0)
# plot(rangeland_timeID_10)
#
# rangeland_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = rangeland_timeID_10,
# TimeID_0 = rangeland_timeID_0,
# type_increment = "linear",
# name = "rangeland_l")
# rangeland <- c(rangeland_timeID_0,rangeland_1000BCE_0CE,rangeland_timeID_10)
# names(rangeland) <- c("2900BP", "2800BP", "2700BP", "2600BP", "2500BP", "2400BP",
# "2300BP", "2200BP", "2100BP", "2000BP", "1900BP")
# plot(rangeland)
### conv_rangeland
conv_rangeland_timeID_0 <- rast("./TimeID_0/conv_rangeland_timeID_0.tif")
conv_rangeland_timeID_10 <- rast("./TimeID_10/conv_rangeland_timeID_10.tif")
plot(conv_rangeland_timeID_0)
plot(conv_rangeland_timeID_10)
conv_rangeland_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = conv_rangeland_timeID_10,
TimeID_0 = conv_rangeland_timeID_0,
type_increment = "linear",
name = "conv_rangeland_l")
conv_rangeland <- c(conv_rangeland_timeID_0,conv_rangeland_1000BCE_0CE,conv_rangeland_timeID_10)
names(conv_rangeland) <- c("conv_2900BP", "conv_2800BP", "conv_2700BP", "conv_2600BP", "conv_2500BP",
"conv_2400BP", "conv_2300BP", "conv_2200BP", "conv_2100BP", "conv_2000BP",
"conv_1900BP")
plot(conv_rangeland)
rasterVis::levelplot(conv_rangeland, par.settings = viridisTheme)
### Other Hyde variables
otherHydeVars <- c("tot_irri","tot_rainfed","tot_rice",
"ir_norice","rf_norice","ir_rice","rf_rice")
for(i in 1:length(otherHydeVars)){
print(i)
### X variable
timeID_0 <- rast(paste0("./TimeID_0/",otherHydeVars[[i]],"_timeID_0.tif"))
timeID_10 <- rast(paste0("./TimeID_10/",otherHydeVars[[i]],"_timeID_10.tif"))
plot(timeID_0)
plot(timeID_10)
r_1000BCE_0CE <- increment.hyde.1000BCE_0CE.func(TimeID_10 = timeID_10,
TimeID_0 = timeID_0,
type_increment = "linear",
name = paste0(otherHydeVars[[i]],"_l"))
r_stack <- c(timeID_0,r_1000BCE_0CE,timeID_10)
names(r_stack) <- paste0(otherHydeVars[[i]],c("_2900BP", "_2800BP", "_2700BP", "_2600BP", "_2500BP",
"_2400BP", "_2300BP", "_2200BP", "_2100BP", "_2000BP",
"_1900BP"))
plot(r_stack)
print(rasterVis::levelplot(r_stack, par.settings = viridisTheme))
}
#########################################################################################################
# 2. Climate - 1000 BCE - 0CE ----------------------------------------------------------------
### Copy and rename files
setwd("D:/FRANCE/Covariates/Climate/TimeID_-9/")
files_1000BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_1000BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/", files_1000BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/")
files_1000BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_1000BCE),
to = gsub(x = paste0("./", files_1000BCE),
pattern="_-9_V1.0_Fr",
replacement="_timeID_0"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-8/")
files_900BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_900BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_1/", files_900BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_1/", files_900BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_1/", files_900BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_1/")
files_900BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_900BCE),
to = gsub(x = paste0("./", files_900BCE),
pattern="_-8_V1.0_Fr",
replacement="_timeID_1"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-7/")
files_800BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_800BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_2/", files_800BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_2/", files_800BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_2/", files_800BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_2/")
files_800BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_800BCE),
to = gsub(x = paste0("./", files_800BCE),
pattern="_-7_V1.0_Fr",
replacement="_timeID_2"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-6/")
files_700BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_700BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_3/", files_700BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_3/", files_700BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_3/", files_700BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_3/")
files_700BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_700BCE),
to = gsub(x = paste0("./", files_700BCE),
pattern="_-6_V1.0_Fr",
replacement="_timeID_3"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-5/")
files_600BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_600BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/", files_600BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/", files_600BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/", files_600BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/")
files_600BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_600BCE),
to = gsub(x = paste0("./", files_600BCE),
pattern="_-5_V1.0_Fr",
replacement="_timeID_4"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-4/")
files_500BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_500BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_5/", files_500BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_5/", files_500BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_5/", files_500BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_5/")
files_500BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_500BCE),
to = gsub(x = paste0("./", files_500BCE),
pattern="_-4_V1.0_Fr",
replacement="_timeID_5"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-3/")
files_400BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_400BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_6/", files_400BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_6/", files_400BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_6/", files_400BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_6/")
files_400BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_400BCE),
to = gsub(x = paste0("./", files_400BCE),
pattern="_-3_V1.0_Fr",
replacement="_timeID_6"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-2/")
files_300BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_300BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_7/", files_300BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_7/", files_300BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_7/", files_300BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_7/")
files_300BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_300BCE),
to = gsub(x = paste0("./", files_300BCE),
pattern="_-2_V1.0_Fr",
replacement="_timeID_7"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_-1/")
files_200BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_200BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_8/", files_200BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_8/", files_200BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_8/", files_200BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_8/")
files_200BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_200BCE),
to = gsub(x = paste0("./", files_200BCE),
pattern="_-1_V1.0_Fr",
replacement="_timeID_8"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_0/")
files_100BCE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_100BCE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/", files_100BCE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/", files_100BCE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/", files_100BCE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/")
files_100BCE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_100BCE),
to = gsub(x = paste0("./", files_100BCE),
pattern="_0_V1.0_Fr",
replacement="_timeID_9"))
setwd("D:/FRANCE/Covariates/Climate/TimeID_1/")
files_0CE <- list.files(pattern="Fr.tif")
file.copy(from = paste0("./",files_0CE),
to = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE))
file.rename(from = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE),
to = gsub(x = paste0("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/", files_0CE),
pattern="CHELSA_TraCE21k_",
replacement="CHELSA_"))
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/")
files_0CE <- list.files(pattern="CHELSA")
file.rename(from = paste0("./", files_0CE),
to = gsub(x = paste0("./", files_0CE),
pattern="_1_V1.0_Fr",
replacement="_timeID_10"))
# 2. Forest cover (Zanon et al., 2018) - 1000 BCE - 0CE ----------------------------------------------------------------
### The fossil dataset was divided into 49 timeslices ranging from 12,000 to 0
### calibrated years BP (years before AD 1950; hereafter BP).
### Each timeslice covers a 250-year window with the exception
### of the most recent one, which is asymmetric as it cannot project
### into the future, and therefore covers an interval of 185 years
### centered on 0 BP.
### For my new Time IDs between TimeID_0 to TimeID_10 I will need the files named
### 1750 BP, 2000 BP, 2250 BP, 2500 BP, 2750 BP and 3000 BP that correspond to
### 200 CE, 50 BCE, 300 BCE, 550 BCE, 800 BCE and 1050 BCE
setwd("D:/FRANCE/Covariates/vegetation/Zanon/")
zanon_files <- list.files(pattern=".tif")
### some Zanon maps correspond with my TimeIDs (midpoint, not whole interval)
file.copy(from = "D:/FRANCE/Covariates/vegetation/Zanon/forest_cover_2500.tif",
to = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/forest_cover_2500.tif")
file.rename(from = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/forest_cover_2500.tif",
to = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_4/forest_cover_timeID_4.tif")
file.copy(from = "D:/FRANCE/Covariates/vegetation/Zanon/forest_cover_2000.tif",
to = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/forest_cover_2000.tif")
file.rename(from = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/forest_cover_2000.tif",
to = "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_9/forest_cover_timeID_9.tif")
### The time IDs correspond to the following interval midpoint
yearsBP <- c(-3000,-2900,-2800,-2700,-2600,-2500,-2400,-2300,-2200,-2100,-2000,-1900)
timeSteps <- (paste0("TimeID_",-1:10))
### function to make linear regression model
lmZanon.1000BCE_0CE.func <- function(Zanon0, Zanon1, timeZ0, timeZ1, TimeBP,outdir, name) {
### Make a SpatRaster
input <- c(Zanon0,Zanon1)
### Calculate slope and intercept
slope <- terra::lapp(input, fun=function(x,y){return((y-x)/(timeZ1-timeZ0))})
input <- c(slope,Zanon1)
intercept <- terra::lapp(input, fun=function(x,y){return(y - (x*timeZ1))})
### Estimate forest cover for target time
input <- c(intercept,slope)
forest_cover <- terra::lapp(input, fun=function(x,y){return(x+(y*TimeBP))},
filename=paste0(outdir, name,".tif"),
overwrite=TRUE)
return(forest_cover)
}
### TimeID_0
setwd("D:/FRANCE/Covariates/vegetation/Zanon/")
Zanon_3000BP <- rast("forest_cover_3000.tif")
Zanon_2750BP <- rast("forest_cover_2750.tif")
Zanon_2500BP <- rast("forest_cover_2500.tif")
Zanon_2250BP <- rast("forest_cover_2250.tif")
Zanon_2000BP <- rast("forest_cover_2000.tif")
Zanon_1750BP <- rast("forest_cover_1750.tif")
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_0/"
forest_cover_timeID_0 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_3000BP,
Zanon1 = Zanon_2750BP,
timeZ0 = -3000,
timeZ1 = -2750,
TimeBP = -2900,
outdir = putdir,
name="forest_cover_timeID_0")
plot(forest_cover_timeID_0)
### timeID_1
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_1/"
forest_cover_timeID_1 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_3000BP,
Zanon1 = Zanon_2750BP,
timeZ0 = -3000,
timeZ1 = -2750,
TimeBP = -2800,
outdir = putdir,
name="forest_cover_timeID_1")
plot(forest_cover_timeID_1)
### timeID_2
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_2/"
forest_cover_timeID_2 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2750BP,
Zanon1 = Zanon_2500BP,
timeZ0 = -2750,
timeZ1 = -2500,
TimeBP = -2700,
outdir = putdir,
name="forest_cover_timeID_2")
plot(forest_cover_timeID_2)
### timeID_3
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_3/"
forest_cover_timeID_3 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2750BP,
Zanon1 = Zanon_2500BP,
timeZ0 = -2750,
timeZ1 = -2500,
TimeBP = -2600,
outdir = putdir,
name="forest_cover_timeID_3")
plot(forest_cover_timeID_3)
### timeID_5
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_5/"
forest_cover_timeID_5 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2500BP,
Zanon1 = Zanon_2250BP,
timeZ0 = -2500,
timeZ1 = -2250,
TimeBP = -2400,
outdir = putdir,
name="forest_cover_timeID_5")
plot(forest_cover_timeID_5)
### timeID_6
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_6/"
forest_cover_timeID_6 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2500BP,
Zanon1 = Zanon_2250BP,
timeZ0 = -2500,
timeZ1 = -2250,
TimeBP = -2300,
outdir = putdir,
name="forest_cover_timeID_6")
plot(forest_cover_timeID_6)
### timeID_7
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_7/"
forest_cover_timeID_7 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2250BP,
Zanon1 = Zanon_2000BP,
timeZ0 = -2250,
timeZ1 = -2000,
TimeBP = -2200,
outdir = putdir,
name="forest_cover_timeID_7")
plot(forest_cover_timeID_7)
### timeID_8
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_8/"
forest_cover_timeID_8 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2250BP,
Zanon1 = Zanon_2000BP,
timeZ0 = -2250,
timeZ1 = -2000,
TimeBP = -2100,
outdir = putdir,
name="forest_cover_timeID_8")
plot(forest_cover_timeID_8)
### timeID_10
putdir <- "C:/Users/mercedes.roman/Desktop/SELVANS/France/Output/mytimeslices/TimeID_10/"
forest_cover_timeID_10 <- lmZanon.1000BCE_0CE.func(Zanon0 = Zanon_2000BP,
Zanon1 = Zanon_1750BP,
timeZ0 = -2000,
timeZ1 = -1750,
TimeBP = -1900,
outdir = putdir,
name="forest_cover_timeID_10")
plot(forest_cover_timeID_10)
### end of the script