Skip to content

Instantly share code, notes, and snippets.

View dlebauer's full-sized avatar
😀

David LeBauer dlebauer

😀
View GitHub Profile
@dlebauer
dlebauer / terraref_eml.R
Last active May 6, 2020 18:16
BETYdb --> EML first draft example with terraref eml metadata
# Code used to generate metadata/eml_metadata.xml
library(EML)
dsl <- eml$creator(individualName = eml$individualName(givenName = "David",
surName = "LeBauer"),
organizationName = "University of Arizona",
electronicMailAddress = "[email protected]",
userId = list(directory = "https://orcid.org",
userId = "https://orcid.org/0000-0001-7228-053X"))
doc <- list(packageId = "dataset-1", system = "Dryad",
@dlebauer
dlebauer / periodicity_modulo.R
Last active May 1, 2020 23:56
Exercise from math circle
# https://stats.stackexchange.com/a/1214/1381
find.freq <- function(x)
{
n <- length(x)
spec <- spec.ar(c(x),plot=FALSE)
if(max(spec$spec)>10) # Arbitrary threshold chosen by trial and error.
{
period <- round(1/spec$freq[which.max(spec$spec)])
if(period==Inf) # Find next local maximum
@dlebauer
dlebauer / periodicity_modulo.R
Created April 30, 2020 19:58
Exercise from math circle
n <- 0:20
y <- x%%7
x <- 2^n
x%%13
# https://stats.stackexchange.com/a/1214/1381
find.freq <- function(x)
{
n <- length(x)
spec <- spec.ar(c(x),plot=FALSE)
@dlebauer
dlebauer / terraref_leaflet_maps.R
Last active April 2, 2020 01:02
Maps of the Maricopa Ag center using Leaflet
library(leaflet)
library(leafem)
library(wellknown)
leaflet(options = leafletOptions(minZoom = 5, maxZoom = 5)) %>%
addTiles() %>%
# addProviderTiles(provider = providers$Esri.WorldStreetMap) %>%
addPopups(lng = -111.975, lat = 33.0755,
popup = "<center>Maricopa Agricultural Center<br/>Maricopa, AZ</center>",
options = popupOptions(closeButton = FALSE, ))
leaflet(options = leafletOptions(minZoom = 1, maxZoom = 18)) %>%
@dlebauer
dlebauer / southwest_usa.R
Created April 1, 2020 22:44
plot of states in southwest US using rnaturalearth and sf packages based on https://www.r-spatial.org/r/2018/10/25/ggplot2-sf.html
library(rnaturalearth)
library(rnaturalearthdata)
devtools::install_github('ropensci/rnaturalearthhires')
library(rnaturalearthhires)
library(ggspatial)
usa_states <- ne_states(country = 'United States of America', returnclass = 'sf')
state_points <- data.frame(state = usa_states$name,
st_coordinates(st_centroid(usa_states$geometry)))
name ecotype notes species
DP_075 Sorghum bicolor
@dlebauer
dlebauer / cleanbety200.sql
Created January 30, 2020 23:58
rough approximation of statements used to clean up bety200
begin;
delete from sites where id < 200000000001 and sitename not like '%Season 10%' and id != 1160 and id != 6000000001;
commit;
delete from benchmarks_benchmarks_reference_runs
delete from benchmarks_ensembles_scores
delete from benchmarks_ensembles
delete from reference_runs;
delete from benchmarks;
delete from inputs;
delete from pfts_species where id < 200000000001
{
"cropping_variable_metadata":{
"origin_timestamp":"2017-05-05__00-41-45-258",
"crop_bbox":{
"img_row":{
"min":16076,
"max":17625
},
"img_col":{
"min":1463,
@dlebauer
dlebauer / daylight.R
Last active December 9, 2019 19:15 — forked from hrbrmstr/daylight.R
daylight for tucson ... still needs work
library(maptools)
library(ggplot2)
library(gridExtra)
library(scales)
library(lubridate)
# adapted from http://r.789695.n4.nabble.com/maptools-sunrise-sunset-function-td874148.html
ephemeris <- function(lat, lon, date, span=1, tz="UTC") {
lon.lat <- matrix(c(lon, lat), nrow=1)
@dlebauer
dlebauer / candidates.R
Created October 23, 2019 16:31
Candidate screening script
library(tidyr)
library(dplyr)
x <- readr::read_csv('~/Downloads/Candidate Scores (Responses) - Form Responses 1 (2).csv')
x2 <- x %>% dplyr::select(evaluator = `Email Address`,
candidate = `Candidate's name`,
collaboration_communication = `Collaboration and Communication Skills`,
software = `Software development / production code`,
organization = `Organization and Planning`,