sobig 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sobig/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """Simulation of observations of biodiversity across gradients."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .sobig import fEnv, Species, Sim, run_demo
6
+
7
+ # Public API exports will go here as the package stabilizes.
sobig/_r/run_gdm.R ADDED
@@ -0,0 +1,42 @@
1
+ library(gdm)
2
+ library(terra)
3
+
4
+ # get file paths
5
+ args <- commandArgs(trailingOnly = TRUE)
6
+ site_survey_filename = args[1]
7
+ env_rast_filename = args[2]
8
+ abundance = as.logical(args[3])
9
+ fits_filename = args[4]
10
+ pca_rast_filename = args[5]
11
+
12
+ # read site-survey table
13
+ site_survey = read.csv(site_survey_filename)
14
+
15
+ # read environmental raster data
16
+ env_rast = terra::rast(env_rast_filename)
17
+
18
+ # format data for analysis
19
+ site_pair = gdm::formatsitepair(bioData=site_survey,
20
+ bioFormat=1,
21
+ abundance=abundance,
22
+ siteColumn='site',
23
+ XColumn='x',
24
+ YColumn='y',
25
+ predData=env_rast)
26
+
27
+ # fit GDM
28
+ mod = gdm::gdm(site_pair, geo=F)
29
+ print(summary(mod))
30
+
31
+ # save fitted functions
32
+ fits = as.data.frame(isplineExtract(mod))
33
+ write.csv(fits, fits_filename)
34
+
35
+ # save first <=3 PCs of GDM-transformed env space
36
+ env_rast_trans <- gdm::gdm.transform(model=mod, data=env_rast)
37
+ pca_samp <- terra::prcomp(env_rast_trans, maxcell = 5e5)
38
+ n_pcs = min(3, dim(env_rast)[3])
39
+ pca_rast <- terra::predict(env_rast_trans, pca_samp, index=1:n_pcs)
40
+ pca_rast <- terra::stretch(pca_rast)
41
+ terra::writeRaster(pca_rast, pca_rast_filename, overwrite=T)
42
+ cat("\nGDM OUTPUTS SAVED TO DISK.\n")