library(raster)
#> Loading required package: sp
# Create a random raster
set.seed(10)
foo <- raster(matrix(round(runif(100)), 10, 10))
# Add up neighbors
# NOTE: won't do anything about cells on the raster edge
foo_focal <- focal(foo, w = matrix(1, 3, 3), fun = sum)
# Set an isolation threshold
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
find0cross <- function(x) { | |
# x must be numeric | |
stopifnot(is.numeric(x)) | |
# Length 0 and 1 can't have zero crossings | |
if (length(x) < 2) { | |
return(rep(FALSE, length(x))) | |
} | |
# Recursively find zero-crossing values |
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
# Takes a grayscale tiff (with alpha) and converts all dark points (by threshold) to the new color | |
colorize_tiff <- function(input, threshold, newcolor) { | |
# Read original tiff | |
orig_tiff <- tiff::readTIFF(input) | |
# Convert grayscale to black and white | |
orig_tiff[, , 1] <- ifelse(orig_tiff[, , 1] > threshold, 1, 0) | |
# Create a colorized tiff | |
new_tiff <- array(0, dim = c(dim(orig_tiff)[1:2], 4)) | |
# Set RGB |
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
--- | |
title: "Supporting Information" | |
subtitle: "Modeling short-term energetic costs of sonar disturbance to cetaceans using high resolution foraging data" | |
author: | |
- "Max F. Czapanskiy" | |
- "Matthew S. Savoca" | |
- "William T. Gough" | |
- "Paolo S. Segre" | |
- "Danuta M. Wisniewska" | |
- "David E. Cade" |
library(tidyverse)
set.seed(1024)
d <- tibble(
a = letters[1:5],
b = LETTERS[6:10],
x = 1:5,
y = (1:5)^2,
z = runif(5)
)
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(raster) | |
library(scales) | |
library(tidyverse) | |
powpow <- function(n, a, b) { | |
# based on answers at: https://dsp.stackexchange.com/questions/47640/generating-a-timeseries-with-an-arbitrary-power-spectrum | |
# Thank you Sam! | |
if (n %% 2 != 0) |
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(tidyverse) | |
# Start with some dummy data | |
whale_data <- tribble( | |
~species, ~prey, ~order, | |
"B. musculus", "krill", 5, | |
"B. physalus", "fish", 3, | |
"B. physalus", "krill", 4, | |
"M. novaeangliae", "fish", 1, | |
"M. novaeangliae", "krill", 2 |
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(ggrepel) | |
library(tidyverse) | |
# These were my measurements for mussel area and quadrat area respectively | |
musselfrac <- 0.043 / 0.097 | |
# dbinom() is the probability of n successes out of x trials with probability p | |
# So dbinom(0:25, 25, musselfrac) is the chance of: [0 points in mussels, 1 | |
# point in mussels, 2 points in mussels, ..., 25 points in mussels] | |
musselprobs <- tibble(n = 0:25, | |
p = dbinom(0:25, 25, musselfrac)) | |
# This is the probability of 24/25 points in mussels |
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
pred_mr <- function( | |
mass_kg, | |
mr_method = c("kleiber", "kolokotronesetal", "nagy", "savageetal", "whiteseymour"), | |
unit = c("kcal_day", "kJ_day", "mlO2_hr", "W"), | |
multiplier = 1 | |
) { | |
#' Predicted metabolic rate | |
#' | |
#' Predict mammalian metabolic rates from various scaling equations. | |
#' |
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(geosphere) | |
library(glue) | |
library(ggplot2) | |
library(mapproj) | |
# Example data frame | |
set.seed(1) | |
tracks <- tibble( | |
time = 1:5, |
OlderNewer