Skip to content

Instantly share code, notes, and snippets.

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

Jemma Stachelek jsta

🪼
...
View GitHub Profile
@jsta
jsta / usa-conus_pygmt.py
Created December 15, 2021 22:01
Plot USA CONUS using pygmt - Generic Mapping Tools
import pygmt
fig = pygmt.Figure()
fig.coast(region="-122/23/-65/48r", frame=False, land="#666666", water="skyblue", projection="A-100/30/4.5i")
# fig.show()
fig.savefig("usa.pdf")
@jsta
jsta / write_gif.R
Created December 10, 2021 15:57
Use rstats magick to convert a png series to gif
library(magick)
image_write_gif(image_join(lapply(list.files("path/to/folder", pattern = "png",
include.dirs = TRUE, full.names = TRUE), image_read)), "output.gif", delay = 4.5)
@jsta
jsta / txt2tif
Created November 19, 2021 02:21
Create a GTiff from an ascii grid with no raster metadata
#!/bin/bash
# Create a GTiff from an ascii grid with no raster metadata
#
# Examples
# # 4320: ncols
# # 2124: nrows
# # -180: xllcorner
# # -88.5: yllcorner
# # 0.0833333: cellsize
# touch test.txt
@jsta
jsta / gleon2021_rspatial.R
Created September 24, 2021 22:01
GLEON 2021 R Spatial Workshop
library(sf)
library(mapview)
erie_outline <- st_read("data/erie_outline.shp")
st_geometry_type(erie_outline)
st_crs(erie_outline)
@jsta
jsta / bib2cards.Rmd
Created September 16, 2021 01:26
Display a bib file as bootstrap cards
---
title: "Papers"
description: >
My papers!
output:
html_document:
theme:
version: 4
---
@jsta
jsta / ggzoom.R
Created September 16, 2021 01:24
Automated zooming map with ggplot
library(ggplot2)
library(gganimate)
library(sf)
lg_extent <- c(xmin = -97.9036, ymin = 34.6176, xmax = -66.9989, ymax = 49.4194)
lg_extent <- sf::st_as_sfc(sf::st_bbox(lg_extent), crs = 4326)
earth <- sf::st_as_sf(
rnaturalearth::ne_states(country = "United States of America"))
views <- data.frame(rbind(
@jsta
jsta / lake_data_map.R
Last active May 31, 2021 13:03
Mapping some lake data
# Mapping some lake data
# Reference: https://r-spatial.org/r/2018/10/25/ggplot2-sf.html
library(sf) # create geospatial layers
library(rnaturalearth) # basemap
library(ggplot2) # plotting
library(tidyr)
library(scales)
dt <- read.csv("lake_data_file.csv", stringsAsFactors = FALSE)
@jsta
jsta / purrr.R
Last active April 12, 2021 16:50
purrr and non-purrr code comparison
library(purrr)
library(dplyr)
library(broom)
mtcars %>%
split(.$cyl) %>% # from base R
map(~ lm(mpg ~ wt, data = .)) %>%
map(summary) %>%
map_dbl("r.squared")
@jsta
jsta / xarray_holoviews.py
Created March 4, 2021 20:46
*Simple* example of plotting an xarray object with holoviews showing values on mouseover
import holoviews as hv
import xarray as xr
hv.extension('bokeh')
test = xr.open_rasterio(raster_file)
gg = hv.Image(test, kdims = ['x', 'y'])
gg.opts(opts.Image(tools=['hover']))
hv.save(gg, 'curve.html', backend='bokeh')
@jsta
jsta / jupyinit
Created March 1, 2021 20:04
Create a new Jupyter notebook from the command line
#!/bin/bash
# Create a new Jupyter notebook from the command line
#
# Examples
# jupyinit env_name py_file.py py_file.ipynb
touch $2
jupytext --set-kernel $1 $2
jupytext --to notebook --execute $2
jupytext --set-formats ipynb,py $3