Skip to content

Instantly share code, notes, and snippets.

View marcosci's full-sized avatar
💭
in progress ...

Marco Sciaini marcosci

💭
in progress ...
View GitHub Profile
# Function to create a plot for the spatstat class ‘fv’, combined with 'Quantum Plots' from:
# Esser, D. S., Leveau, J. H. J., Meyer, K. M., & Wiegand, K. (2014). Spatial scales of interactions among bacteria and between bacteria and the leaf surface. FEMS Microbiology Ecology, 91(3), fiu034. http://doi.org/10.1093/femsec/fiu034
# The colored bands highlight the spatial scales at which the summary statistics deviate from the simulation envelopes.
quantumPlot <- function(x,colour=c("#d73027", "#ffffbf", "#91bfdb")){
# load Packages
require(ggplot2)
require(ggthemes)
library(raster)
nlm_raster <- nlm_gaussianfield(100, 100, 5)
setGeneric(
"splitRaster",
function(r, nx = 1, ny = 1, buffer = c(0, 0), path = file.path(getwd(), names(r)), cl) {
standardGeneric("splitRaster")
})
# create landscapes
set.seed(5)
percolation_landscape <- nlm_percolation(100,100,0.4, resolution = 10)
random_landscape <- nlm_random(100,100, resolution = 10)
distagrad_landscape <- nlm_distancegradient(100, 100, origin = c(10,15,10,15), resolution = 10)
edgegradient_landscape <- nlm_edgegradient(100,100, 90, resolution = 10)
planar_landscape <- nlm_planargradient(100,100, resolution = 10)
randomRecCluster_landscape <- nlm_randomrectangularcluster(100, 100, minL = 8, maxL = 16, rescale = FALSE, resolution = 10)
randomElement_landscape <- nlm_randomelement(100,100, n = 90, resolution = 10)
@marcosci
marcosci / test.R
Created March 16, 2018 08:59
velox problem
ncol <- 100
nrow <- 100
germs <- 50
# bounding box placing germs and clipping ----
bounding_box <- sf::st_sfc(sf::st_polygon(list(rbind(c(0, 0),
c(ncol, 0),
c(ncol, nrow),
c(0, nrow),
c(0, 0)))))
@marcosci
marcosci / remote_future.R
Created June 5, 2018 08:33
how to setup a remote connection with future in R
# Specify remote worker
login <- tweak(remote, workers = "SERVER IP", user = 'USERNAME')
# Specify future topology
## login node -> { multiple cores }
plan(list(
login,
multiprocess
))
---
title: "???? <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html>"
author: "Marco Sciaini"
date: "`r Sys.Date()`"
output:
xaringan::moon_reader:
css: [default, metropolis, metropolis-fonts]
nature:
beforeInit: "macros.js"
highlightStyle: github
@marcosci
marcosci / clumpy
Created July 9, 2018 15:02
clumpiness metric from fragstats
landscape_padded <- pad_raster(landscape)
# landscape_padded <- landscape
adjacent_cells <- raster::adjacent(
landscape_padded,
cells = seq_len(raster::ncell(landscape_padded)),
directions = 4,
pairs = TRUE
)
@marcosci
marcosci / buffer_anim.R
Created September 25, 2018 10:03
animation to illustrate sample_lsm (sample landscape metrics in buffers around points of interest)
library(NLMR)
library(sf)
library(purrr)
library(rcartocolor)
library(gganimate)
library(classInt)
landscape <- NLMR::nlm_fbm(50, 100, fract_dim = 1.2)
breaks <- landscape %>%
@marcosci
marcosci / recover_future.R
Created October 10, 2018 04:30
read results from .future
future_results <- list.files("/home/uni08/msciain/.future", pattern = glob2rx("*1.rds"), recursive = T, full.names = TRUE) %>% map_dfr(readRDS)
@marcosci
marcosci / nlrx_links_team
Created January 11, 2019 21:51
nlrx Team Assembly