Skip to content

Instantly share code, notes, and snippets.

View khufkens's full-sized avatar

Koen Hufkens khufkens

View GitHub Profile
@khufkens
khufkens / clean_gh-pages.sh
Created February 12, 2023 14:31
Create clean gh-pages branch
git checkout --orphan gh-pages
# preview files to be deleted
git rm -rf --dry-run .
# actually delete the files
git rm -rf .
@khufkens
khufkens / format_rsofun_drivers.R
Created December 5, 2022 09:13
Format rsofun drivers
#' Format and run p-model drivers on Euler
#'
#' Takes site information for a single
#' or multiple sites and grabs all data
#' required for a p-model run in rsofun.
#'
#' Parameter settings are provided as
#' arguments, but could be altered after
#' the fact if desired.
#'
@khufkens
khufkens / aggregate_netcdf.R
Created November 29, 2022 15:19
NetCDF aggregation using {terra}
library(terra)
library(stringr)
#---- static code ----
# read in the original data
r <- rast("LPX-Bern_SH1_gpppft.nc")
# first subset to only the required years
# 1978 - 2020
@khufkens
khufkens / batch_unzip.sh
Created November 22, 2022 11:12
Batch unzip in bash
find . -name '*.zip' -exec sh -c 'unzip {};'
@khufkens
khufkens / polar_map.r
Last active July 6, 2022 08:59
Fancy polar plot in R
#-------- arctic map
library(sp)
library(maps)
library(rgeos)
# function to slice and dice a map and convert it to an sp() object
maps2sp = function(xlim, ylim, l.out = 100, clip = TRUE) {
stopifnot(require(maps))
m = map(xlim = xlim, ylim = ylim, plot = FALSE, fill = TRUE)
@khufkens
khufkens / reference_blue_marble.sh
Created June 8, 2022 18:30
Georeferencing a NASA blue marble world map
gdal_translate -a_ullr -180 90 180 -90 -a_srs EPSG:4326 world.topo.bathy.200408.3x5400x2700.jpg tmp.tif
@khufkens
khufkens / opt_span_example.R
Created April 13, 2022 17:07
Calculate optimal span for MODIS time series
# Interpolation using a loess smoother
# and optimal span determination
library(MODISTools)
library(phenocamr)
library(tidyverse)
VI <- mt_subset(
product = "MOD13Q1",
lon = -72.1755,
@khufkens
khufkens / animation.sh
Last active January 26, 2022 17:57
Twitter movie from PNG sequence
# convert pngs to mp4
ffmpeg -r 2 -i tmp/%03d.png -y out.mp4
# convert mp4 to twitter compatible format
ffmpeg -i out.mp4 -vf scale=1280:720 -b:v 5000K -minrate 5000K -maxrate 5000K -b:a 128K -r 30 -f mp4 -vcodec libx264 -profile:v high -pix_fmt yuv420p -strict -2 -ac 2 -acodec aac twitter.mp4
@khufkens
khufkens / download_plumber2.R
Created November 4, 2021 15:22
Download Plumber 2 data
library(rvest)
# base html url
url <- "http://dapds00.nci.org.au/thredds/fileServer/ks32/CLEX_Data/PLUMBER2/v1-0/Flux/"
# catalogue
html_page = read_html("https://dap.nci.org.au/thredds/remoteCatalogService?catalog=http://dapds00.nci.org.au/thredds/catalog/ks32/CLEX_Data/PLUMBER2/v1-0/Flux/catalog.xml")
# grab files from the catalogue
files = html_page %>%
@khufkens
khufkens / waffle_plot.R
Last active July 20, 2021 15:43
Complex waffle plot example
# data wrangling
library(tidyverse)
# waffle plot
library(waffle)
# combining graphs
library(patchwork)
# text magic