-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.1a_masking_bioclimate.R
46 lines (39 loc) · 1.22 KB
/
1.1a_masking_bioclimate.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
library(raster)
library(tictoc)
par(mar = c(0.1, 0.1, 0.1, 0.5))
#pr = stack("~/scratch/climate_now/bio19_60_cropped.tif")
rcavm = raster("~/scratch/cavm/cavm_to_bio_qgis_resampled.tif")
rcavm_t = raster("~/scratch/cavm/with_trees/cavm_with_trees_bio_qgis_resampled.tif")
msk = rcavm/rcavm
msk[is.na(rcavm_t)] = NA
#"e3v_126","e3v_585","ipsl_126",
for (modname in c("ipsl_585","mri_126","mri_585")) {
print(modname)
dir.create(paste0("~/scratch/future/masked_", modname))
pr = stack(paste0("~/scratch/future/cropped/", modname, ".tif"))
for (i in c(1:19)) {
bio1 = pr[[i]]
tic()
pr1 = mask(bio1, msk)
writeRaster(pr1, paste0("~/scratch/future/masked_", modname,"/bio", i, ".tif"),
overwrite = T)
# _with_trees
toc()
}
}
num_cor = data.frame(c(1:19), names(pr))
colnames(num_cor) = c("orig", "messed")
num_cor$messed = as.numeric(num_cor$messed)
write.csv(num_cor, "~/scratch/number_correction.csv", row.names = F)
pr = rast("~/scratch/climate_now/bio19_60_cropped.tif")
for (i in c(1:19)) {
bio1 = pr[[i]]
tic()
pr1 = mask(bio1, msk)
writeRaster(pr1, paste0("~/scratch/climate_now/masked/bio", i, ".tif"),
overwrite = T)
# _with_trees
toc()
}
plot(pr1)
toc()