This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diverge0 <- function(p, ramp) { | |
# p: a trellis object resulting from rasterVis::levelplot | |
# ramp: the name of an RColorBrewer palette (as character), a character | |
# vector of colour names to interpolate, or a colorRampPalette. | |
require(RColorBrewer) | |
require(rasterVis) | |
if(length(ramp)==1 && is.character(ramp) && ramp %in% | |
row.names(brewer.pal.info)) { | |
ramp <- suppressWarnings(colorRampPalette(brewer.pal(11, ramp))) | |
} else if(length(ramp) > 1 && is.character(ramp) && all(ramp %in% colors())) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Temporal Interpolation #################################################### | |
# Perform cell-wise linear interpolation between multiple raster layers, and | |
# extrapolation beyond the upper limit of input data. Output is saved in .tif | |
# format. | |
# | |
# Arguments | |
# s: a rasterStack containing the time slices to be interpolated | |
# | |
# xin: a numeric vector that indicates the times associated with layers in s (in | |
# the same order as the layers of s - see names(s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.bubbles { | |
stroke-width: 1px; | |
stroke: black; | |
opacity: .8 | |
} | |
.bubbles:hover { | |
stroke: black; | |
} | |
* { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exdet <- function (ref, p, mic=TRUE, tol, quiet=FALSE) { | |
# ref: data.frame of environments at reference locations. | |
# p: data.frame of environments to assess. | |
# mic: should the most influential covariates also be returned? | |
# quiet: should messages be suppressed? | |
# tol: tolerance, passed to mahalanobis(). See ?solve. | |
# ============================================================= | |
# When passing `mic=TRUE`, a data.frame will be returned with 3 | |
# columns giving the exdet score (D), the most influential | |
# covariate with respect to type 1 novelty (MIC1; equivalent to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sf_arrow <- function(from, to, len, deg, prefixFrom='from.', prefixTo='to.') { | |
# from, to: sf objects. `from` should be either a single point, or the same | |
# number of points as in `to`. | |
# len: the length of the arrow head, in map units. | |
# deg: the angle (in degrees) of the arrow head. | |
# prefixFrom, prefixTo: the attributes of `from` and `to` are added to the | |
# returned sf object. These prefixes will be prepended to the existing names | |
# of `from` and `to`. | |
crs <- st_crs(to) | |
n <- nrow(to) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(jsonlite) | |
# create an empty list to store results | |
items <- list() | |
i <- 1 # initialise counter to 1. This is used to specify the start index for queries | |
# We can download at most 100 records at a time, so we download in pages, | |
# increasing the start index by 100 each time. We do this until the result of | |
# the query has fewer than 100 results (i.e. we've retrieved the last page of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dms2dd <- function(x) { | |
dms <- strsplit(x, '[^0-9.]+') | |
sapply(dms, function(x) { | |
sum(as.numeric(x)/c(1, 60, 3600)[seq_along(x)]) | |
}) | |
} | |
dms2dd(c('34°53’07”S', '138°36’40”E', '138.61111', '34°53’')) | |
## [1] 34.88528 138.61111 138.61111 34.88333 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_namespaces <- function(file, as_imports=FALSE) { | |
require(stringi) | |
require(dplyr) | |
nm <- readLines(file) %>% | |
stringi::stri_extract_all(regex='[\\w_.]+::[\\w_.]+') %>% | |
unlist %>% | |
setdiff(NA) %>% | |
sort | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PYTHON_VERSION=3.4.3 | |
export PYTHON_SHORT_VERSION=3.4 | |
export GEOS_VERSION=3.6.2 | |
export GDAL_VERSION=2.2.2 | |
export PROJ4_VERSION=4.9.3 | |
sudo yum-config-manager --enable epel | |
sudo yum install gdal-python | |
sudo yum -y install make automake gcc gcc-c++ libcurl-devel proj-devel geos-devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gdal_mean <- function(infile, outfile, return_raster=FALSE, overwrite=FALSE) { | |
# Be aware that the outfile type will be the same as the infile type | |
require(rgdal) | |
if(return_raster) require(raster) | |
# infile: The multiband raster file (or a vector of paths to multiple | |
# raster files) for which to calculate cell mean. | |
# outfile: Path to raster output file. | |
# return_raster: (logical) Should the output raster be read back into R? | |
# overwrite: (logical) Should outfile be overwritten if it exists? | |
gdal_calc <- Sys.which('gdal_calc.py') |
NewerOlder