Skip to content

Instantly share code, notes, and snippets.

View khufkens's full-sized avatar

Koen Hufkens khufkens

View GitHub Profile
@khufkens
khufkens / equi2polar.sh
Created July 1, 2021 11:49
Convert equirectangular files to polar projections (upward looking)
#!/bin/bash
# convert equirectangular 2 fisheye
files=`ls *.jpg`
for i in $files;
do
noext=`echo $i | cut -d'.' -f1`
echo $noext
@khufkens
khufkens / downsample_extract_hwsd.R
Last active July 7, 2021 17:38
Downsample (or extract) HWSD data
# Downsample HWSD data to the scale of 0.5 degree
# WFDEI / CRU data
library(raster)
library(hwsdr)
library(tidyverse)
# get mu_global at 0.5 degrees from the
# ORNL DAAC (which is easier than reading in
# that monstrous BIL file)
@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
@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 / 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 / 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 / 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 / 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 / batch_unzip.sh
Created November 22, 2022 11:12
Batch unzip in bash
find . -name '*.zip' -exec sh -c 'unzip {};'
@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