Skip to content

Instantly share code, notes, and snippets.

View adamhsparks's full-sized avatar

Adam H. Sparks adamhsparks

View GitHub Profile
@adamhsparks
adamhsparks / historical_weather.py
Created March 27, 2024 06:47
Fetch historical weather data with Python using various packages
# Fetch historical weather data with Python using various packages
# use plotnine for graphing
from plotnine import *
import pandas as pd
import pathlib
# pynasapower
# Fetches NASA POWER data
@adamhsparks
adamhsparks / df_to_power.R
Last active March 14, 2024 06:01
Use a data frame of lonlat and date values to get data from POWER API using {nasapower}
library("nasapower")
library("purrr")
library("dplyr")
df <- data.frame(
stringsAsFactors = FALSE,
lon = c(151.81, 112.5, 115.5),
lat = c(-27.48, -55.5, -50.5),
date = c("3/3/2023", "5/12/2023", "1/3/2024")
)
@adamhsparks
adamhsparks / wa_web_feature_services.R
Last active November 13, 2023 11:50
Use Western Australia's Web Feature Services in R
# Get all DPIRD boundary data sets available from the Public Services Slip WA and save data for use in an R package.
# HT to Thierry Onkelinx, Hans Van Calster, Floris Vanderhaeghe for their post,
# <https://inbo.github.io/tutorials/tutorials/spatial_wfs_services/>, but I
# modified this to work to save .Rds files for use in an R package, not just
# saving to disk and chose to use {httr2} in place of {httr}.
# NOTE: This URL is only for public boundaries,
<https://public-services.slip.wa.gov.au/public/services/SLIP_Public_Services/Boundaries_WFS/MapServer/WFSServer>,
there are others, see <https://catalogue.data.wa.gov.au/dataset> for other orgs and types of data
@truebit
truebit / alacritty.yml
Last active May 22, 2024 09:19 — forked from programus/alacritty.yml
pull down from top alacritty (like iTerm2)
window:
# Window dimensions (changes require restart)
#
# Number of lines/columns (not pixels) in the terminal. The number of columns
# must be at least `2`, while using a value of `0` for columns and lines will
# fall back to the window manager's recommended size.
dimensions:
columns: 500
lines: 30
@eliocamp
eliocamp / StatQuantileBin.R
Last active July 24, 2023 13:50
Percentogram (histogram with bins of equal number of observations)
# This is now available into ggpercentogram.
# https://github.com/eliocamp/ggpercentogram/
StatQuantileBin <- ggplot2::ggproto("StatQuantileBin", ggplot2::StatBin,
default_aes = ggplot2::aes(x = ggplot2::after_stat(density), y = ggplot2::after_stat(density), weight = 1),
compute_group = function(data, scales,
binwidth = NULL, bins = 30, breaks = NULL, trim = 0,
closed = c("right", "left"), pad = FALSE,
flipped_aes = FALSE,
# The following arguments are not used, but must
# be listed so parameters are computed correctly
@pudquick
pudquick / brew.md
Last active April 6, 2024 21:42
Lightly "sandboxed" homebrew on macOS

brew is a bad neighbor

This isn't a guide about locking down homebrew so that it can't touch the rest of your system security-wise.

This guide doesn't fix the inherent security issues of a package management system that will literally yell at you if you try to do something about "huh, maybe it's not great my executables are writeable by my account without requiring authorization first".

But it absolutely is a guide about shoving it into its own little corner so that you can take it or leave it as you see fit, instead of just letting the project do what it likes like completely taking over permissions and ownership of a directory that might be in use by other software on your Mac and stomping all over their contents.

By following this guide you will:

  • Never have to run sudo to forcefully change permissions of some directory to be owned by your account
@jonocarroll
jonocarroll / lissajous.jl
Created May 12, 2022 12:32
Lissajous curve matrix in Julia
## Goal: reproduce e.g. https://www.reddit.com/r/oddlysatisfying/comments/uc054a/lissajous_polygons
using Plots
import GeometryBasics: Point
## https://jcarroll.xyz/2022/04/07/interpolation-animation-in.html
interpolate(a, b) = t -> ((1.0 - t) * a + t * b)
## define the vertices of an N-gon
@adamhsparks
adamhsparks / audpc.jl
Last active January 19, 2022 10:57
A Julia function to calculate area under the disease progress curve (AUDPC)
function audpc(evaluation, dates)
n = length(evaluation) - 1
disvec = Base.zeros(n)
datevec = Base.zeros(n)
out = 0.0
for i in 1:n
disvec[i] = (evaluation[i] + evaluation[i + 1]) / 2
datevec[i] = dates[i + 1] - dates[i]
out = sum(disvec .* datevec)
@abelcallejo
abelcallejo / README.md
Last active March 14, 2024 06:15
NASA POWER Cheatsheet

NASA POWER Cheatsheet

Table of contents

Meteorology

Spatial resolution of 0.5 x 0.625 degrees of latitude and longitude respectively

library(tidyverse)
library(scholar)
# get from scholar profile urlafter "/citations?user=" and before "=en"
id_authorname <- "TQQzkCwAAAAJ&hl"
profile_authorname <- get_profile(id_authorname)
profile_authorname
library(googlesheets4)