forked from JW-spec-tech/S_land_bio_sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run_simulatin_generate_data_stratum_local.domain_dat_loop_version.R
74 lines (59 loc) · 2.16 KB
/
Run_simulatin_generate_data_stratum_local.domain_dat_loop_version.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
#### Load packages ####
library(arrow)
library(NLMR)
library(sf)
library(raster)
library(fasterize)
library(sspm)
library(rgeos)
library(tidyr)
library(readr)
library(dplyr)
#### Load the Functions ####
source(file = "Simulation_Depth_Temp_Coordinates_Biomass_function_V2.R")
source(file = "function_patches.R")
source(file = "Make_local.domain_local.arena.R")
source(file = "Make_PB_fall.dat.R")
source(file = "Gam_analysis.R")
source(file = "Compare.R")
memory.limit(40000)
print(paste("Start of Sim generation @",Sys.time()))
reps= as.numeric(Sys.getenv('REPS')) # Number of Replicates
sims= as.numeric(Sys.getenv('SIMS')) # Number of Sims
size= as.numeric(Sys.getenv('SIZE')) # Size of the Landscape
seed= as.numeric(Sys.getenv('SEED')) # Starting seed
var = as.numeric(Sys.getenv('VAR')) # Variation in biomass field --> higher variation = increased biomass variation
percent = as.numeric(Sys.getenv('PERCENT')) # Sets sampling percentage of the sampling of the entire dataset
#### Loop to run replicates of simulations in individual folders ####
for (rep in 1:reps) {
print(paste("Replicate #",rep))
seeds = seed - 1 + rep
set.seed(seeds)
cwd <- getwd() # CURRENT dir
setwd("Data/")
newdir <- paste("Run",rep,"Size",size,"seed",seeds,"nsim",sims,"Percent",percent,Sys.Date(),sep = "_")
dir.create(newdir) # Create new directory
setwd(newdir)
write.table(as.data.frame(newdir),"seed")
#### 1. Run the sim ####
results <- S_land_bio_sim(sims,size,variation = var) # higher variation = increased biomass variation
# Save size of each strata
patches=results$patches_list$patches
patches=st_set_geometry(patches,NULL)
write_parquet(patches,"patches")
#### 2. Write the ogmap files ####
Make_patch_domain_arena_DAT(size,patches=results$patches_list$patches,the_stack=results$the_stack,percent=percent)
# #### 3. Slice data file ####
# Make_PB_fall.dat()
#
# #### 4. Analyse GAM ####
# Analyse_Gam()
#
# #### 5. Run Comparison + Print graphs ####
# Compare_Graph()
#### 6. Return to Original WD ####
setwd(cwd)
gc()
}
print(paste("End of Sim generation @",Sys.time()))
#################################################