Skip to content

Instantly share code, notes, and snippets.

View jsta's full-sized avatar
🪼
...

Jemma Stachelek jsta

🪼
...
View GitHub Profile
@jsta
jsta / vermontlakes.R
Created March 11, 2020 20:04
Scrape VERMONT DEC Lakes Portal [unfinished]
library(rvest)
library(httr)
url <- "https://anrweb.vermont.gov/dec/_dec/LongTermMonitoringLakes.aspx"
html_session(url) %>%
html_form()
html_session(url) %>%
html_nodes()
@jsta
jsta / hollister2011.py
Created February 13, 2020 19:09
Hollister 2011 - Predicting Maximum Lake Depth from Surrounding Topography
import time
start = time.clock()
import sys, os
import arcpy
arcpy.CheckOutExtension("Spatial")
import rpy2.robjects as robjects
import math
r=robjects.r
r("library(rgdal)")
#These options can be set to desired workspace and names of input elevation, catchment, and lake datasets
@jsta
jsta / ny_gg.R
Last active January 22, 2020 03:54
Map New York water using LAGOSNEgis
library(LAGOSNEgis) # devtools::install_github("cont-limno/LAGOSNEgis")
library(ggplot2)
library(dplyr)
library(sf)
# st_layers(lagosnegis_path())
# gdalUtils::ogrinfo(lagosnegis_path(), "Stream_Polylines", so = TRUE)
state <- query_gis("STATE", "State_Name", "New York")
lakes <- query_gis_(query = "SELECT * FROM LAGOS_NE_All_Lakes_4ha WHERE STATE LIKE 'NY' AND Lake_Area_Ha > 1600")
@jsta
jsta / full_citation.R
Last active November 19, 2019 01:44
Full citation for an R package including contributors
library(desc)
library(stringr)
full_citation <- function(pkg, year){
# pkg <- "rnoaa"
# year <- 2019
file <- system.file("DESCRIPTION", package = pkg)
dt <- desc::desc(package = pkg)
aut <- dt$get_authors()
@jsta
jsta / gist_data-store.R
Created May 15, 2019 13:49
Using a gist as a data store
library(gistr)
data(iris)
dt <- iris
str <- ''
tc <- textConnection('str', 'w', local = TRUE)
write.csv(dt, file = tc, row.names = FALSE)
close(tc)
@jsta
jsta / jensens_inequality.R
Created March 12, 2019 00:13
Jensen's inequality
library(ggplot2)
library(dplyr)
x <- 1:30
y <- log(x)
xi <- sample(x, 6)
xi <- xi[order(xi)]
fxi <- log(xi)
@jsta
jsta / zenodo.R
Created March 11, 2019 00:46
Download files from Zenodo record id
#' Download files from Zenodo record id
#'
#' @param record_id record id
#' @param dest_folder destination folder for file downloads
#' @param token API key
#'
#' @details https://github.com/zenodo/zenodo/issues/1629#issuecomment-435062462
#'
#' @importFrom httr GET content
#' @importFrom jsonlite fromJSON
@jsta
jsta / kreft_de-leeuw_1998.R
Last active February 27, 2019 17:15
Kreft, I.G. and De Leeuw, J., 1998. Introducing multilevel modeling. Sage.
# Kreft, I.G. and De Leeuw, J., 1998. Introducing multilevel modeling. Sage.
library(CMatching)
library(dplyr)
library(purrr)
library(tidyr)
library(broom)
library(ggplot2)
data("schools")
@jsta
jsta / progress_message.R
Last active February 14, 2019 19:11
Progress bar with updating message
library(progress)
f <- function(i){
pb$tick(tokens = list(status = "pulling data ", iter = i))
Sys.sleep(0.4)
pb$tick(tokens = list(status = "running calculations", iter = i))
Sys.sleep(0.7)
}
@jsta
jsta / locus_intersect.R
Created January 18, 2019 16:25
Debug locus locations not intersecting lake polygons
library(LAGOSNE)
library(mapview)
llid <- 1867
coords <- lake_info(llid)
mapview(coordinatize(coords))