Skip to content

Instantly share code, notes, and snippets.

Avatar

Koen Hufkens khufkens

View GitHub Profile
@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",
@khufkens
khufkens / orient_images.sh
Created Nov 19, 2019
Line to run on all images before CV processing
View orient_images.sh
# aligns virtual orientation with physical orientation
mogrify -auto-orient *.png
@khufkens
khufkens / montage.sh
Last active Jun 19, 2020
Montage of example numbers for zooniverse project
View montage.sh
montage *.png -bordercolor White -border 5x5 -colorspace Gray -gravity center -tile 7x -geometry +10+0 ~/montage.jpg
@khufkens
khufkens / ghent_air_quality_vmm.R
Created Jun 12, 2019
Ghent air quality study VMM rehash
View ghent_air_quality_vmm.R
# Ghent air pollution analysis
# parametric t-tests
# non-parametric Mann-Whitney U test
# download and collate the data
pdf_data <- paste0(pdftools::pdf_text("https://klimaat.stad.gent/sites/default/files/nota_circulatieplangent_3.pdf")[2],
collapse = " ")
# some regular expression moving about
subset <- gsub(',', ".", pdf_data)
@khufkens
khufkens / cold_front_geopotential_transect.R
Last active Apr 19, 2019
Cold front transect along geopotential heights
View cold_front_geopotential_transect.R
# Before you start install all the referenced packages below
# including the development release of ecmwfr you will also
# need the rnaturalearthdata in addition to the normal package
# To run the code copy and paste segments as this is still
# rough around the edges and requires user interaction to
# set your CDS API key.
# load libraries
if(!require(devtools)){install.packages("devtools")}
devtools::install_github("khufkens/ecmwfr")