Skip to content

Instantly share code, notes, and snippets.

View adamhsparks's full-sized avatar

Adam H. Sparks adamhsparks

View GitHub Profile
@adamhsparks
adamhsparks / downwind.R
Created September 21, 2021 01:21
Spore trap upwind/downwind
dat <-
dat %>%
left_join(wind, by = c("field" = "FIELD")) %>%
mutate(
field = factor(field),
trap_coord_deg = case_when(
trap_coord == "N" ~ 0,
trap_coord == "NbE" ~ 11.25,
trap_coord == "NNE" ~ 22.5,
trap_coord == "NEbN" ~ 33.75,
##############################################################################
# title : EPIRICE-sim-bs-lb.R;
# purpose : Install the epicrop package and simulate rice brown spot and
# rice leaf blast epidemics;
# producer : prepared by A. Sparks;
# last update : in Perth, WA, Australia, Jun 2021;
# inputs : na;
# outputs : leaf blast and brown spot model outputs of unmanaged disase
# epidemics;
# remarks : Prepared for Jean Fabrice Adanve;
@adamhsparks
adamhsparks / mean_weather.R
Last active March 17, 2021 12:07
Download and calculate country and year mean values for weather variables using GSODR and dplyr
library("GSODR")
library("tidyr")
library("dplyr")
library("countrycode")
w <- get_GSOD(years = 1929:1931)
w <-
w %>%
group_by(CTRY, YEAR) %>%
@adamhsparks
adamhsparks / leaf_wet.jl
Created February 20, 2021 09:29
Julia code to calculate leaf wetness using latitude, day of year and relative humidity. Not functional, just a start at translation from R, see leaf_wet.R gist.
function leaf_wet(wth = wth, simple = TRUE)
rh = diurnal_rh(
doy = wth[, DOY],
rh = wth[, RHUM],
tmin = wth[, TMIN],
tmax = wth[, TMAX],
tmp = wth[, TEMP],
lat = wth[, LAT]
@adamhsparks
adamhsparks / leaf_wet.R
Last active February 20, 2021 08:27
Calculate leaf wetness in R using relative humidity, latitude and day length. Adapted from GPL3 code from R. Hijmans in the meteor and cropsim packages.
#' Get weather data from NASA POWER API
#'
#' @param lonlat A numeric vector of geographic coordinates for a cell or region
#' entered as x, y coordinates.
#' @param dates A character vector of start and end dates in that order.
#'
#' @return A \code{\link[data.table]{data.table}} of weather data, dates and
@adamhsparks
adamhsparks / Create PHL Map
Last active April 9, 2020 07:08
Quickly creates a generic map using ggplot2, sf and rnaturalearth
library("ggplot2")
library("ggthemes")
theme_set(theme_map())
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
ctry <- world[world$name == "Philippines", ]
@adamhsparks
adamhsparks / track_package_downloads.R
Last active December 22, 2021 02:44
Tracks my R package downloads over time
library(dplyr)
library(ggplot2)
library(lubridate)
library(cranlogs)
library(janitor)
dl <-
cran_downloads(
package = c(
"bomrang",
@adamhsparks
adamhsparks / bomrang_climogram.R
Last active July 3, 2019 04:32
Generate a climogram using bomrang to download station data for 2018/19 summer growing season in Australia
library(bomrang)
library(tidyverse)
library(theme.usq)
# Find stations ----------------------------------------------------------------
# Find nearest stations for each area
# search https://www.latlong.net/ for the lat lon values of each location
# clermont
# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed
brew install findutils
@adamhsparks
adamhsparks / bibtex_2academic.R
Created February 14, 2019 10:45 — forked from lbusett/bibtex_2academic.R
script for importing publications from a "bibtex" file to a hugo-academic website
#' @title bibtex_2academic
#' @description import publications from a bibtex file to a hugo-academic website
#' @author Lorenzo Busetto, phD (2017) <lbusett@gmail.com>
bibtex_2academic <- function(bibfile,
outfold,
abstract = FALSE,
overwrite = FALSE) {
require(RefManageR)