Skip to content

Instantly share code, notes, and snippets.

Avatar

Koen Hufkens khufkens

View GitHub Profile
@khufkens
khufkens / reference_blue_marble.sh
Created Jun 8, 2022
Georeferencing a NASA blue marble world map
View reference_blue_marble.sh
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 Apr 13, 2022
Calculate optimal span for MODIS time series
View opt_span_example.R
# 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 / download_plumber2.R
Created Nov 4, 2021
Download Plumber 2 data
View download_plumber2.R
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 Jan 26, 2022
Twitter movie from PNG sequence
View animation.sh
# 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 / waffle_plot.R
Last active Jul 20, 2021
Complex waffle plot example
View waffle_plot.R
# data wrangling
library(tidyverse)
# waffle plot
library(waffle)
# combining graphs
library(patchwork)
# text magic
@khufkens
khufkens / downsample_extract_hwsd.R
Last active Jul 7, 2021
Downsample (or extract) HWSD data
View downsample_extract_hwsd.R
# 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 / equi2polar.sh
Created Jul 1, 2021
Convert equirectangular files to polar projections (upward looking)
View equi2polar.sh
#!/bin/bash
# convert equirectangular 2 fisheye
files=`ls *.jpg`
for i in $files;
do
noext=`echo $i | cut -d'.' -f1`
echo $noext
@khufkens
khufkens / format_phenor_data.R
Created May 28, 2021
Download and format phenocam sites in phenor
View format_phenor_data.R
# required libraries
library(phenor)
# where to store the data
out_dir <- "data-raw/"
# sites to process, stored in a csv file
# with columns site, veg_type, roi (check for extra spaces
# which can mess with name formatting)
sites <- read.table("data/sites.csv", sep = ",", header = TRUE)
@khufkens
khufkens / crop_and_animate.sh
Created Apr 3, 2021
Animate virtual forest images
View crop_and_animate.sh
#!/bin/bash
# crop section of images
mogrify -crop 2770x2304+3560+296 *.jpg
# compile into animated gif
convert -delay 100 -loop 0 -depth 8 -resize '640x' -quality 75% *.jpg anim.gif
@khufkens
khufkens / MODIS_arctic_sites_download.R
Last active Aug 21, 2020
MODIS arctic sites data request
View MODIS_arctic_sites_download.R
# download NDVI time series
library(MODISTools)
df <- data.frame(
site_name =
c("US-Bes",
"US-Atq",
"US-Ivo",
"US-ICt",
"DK-ZaH",