Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Koen Hufkens khufkens

Block or report user

Report or block khufkens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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")
@khufkens
khufkens / essential_climate_variables_animation.R
Last active Apr 24, 2019
Downloads and animates CDS essential climate variables
View essential_climate_variables_animation.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")
@khufkens
khufkens / essential_climate_variable_plot.R
Last active Apr 12, 2019
Downloads and plots essential climate variable resembling the ECWMF plot
View essential_climate_variable_plot.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")
@khufkens
khufkens / gist:5fe99a9606f544b2d5d6a356a3f93fdd
Created Dec 9, 2018
Correct PDF author / title meta-data
View gist:5fe99a9606f544b2d5d6a356a3f93fdd
#!/bin/bash
# Insert PDF meta-data into exif header
# for pdf files with format author - year - title.pdf.
# This allows e-readers to query meta-data for proper
# display and sorting of authors and titles
# (note: relies on exiftool)
for filename in *.pdf; do
noext=`echo "${filename%.*}"`
@khufkens
khufkens / el_nino_precip_analysis.r
Created May 10, 2018
CHIRP drought / precipitation differences between the Amazon and Congo Basin during the 2015 El Nino
View el_nino_precip_analysis.r
# map El Nino drought in the Amazon and Africa
library(raster)
library(tidyverse)
library(maps)
library(RColorBrewer)
# set colour theme
colours = brewer.pal(11,"RdBu")
# download CHIRP data
@khufkens
khufkens / daymet_server_tests.r
Created Apr 27, 2018
Daymet single pixel server tests
View daymet_server_tests.r
# load required libraries
if(!require(devtools)){install.package("devtools")}
if(!require(daymetr)){devtools::install_github("khufkens/daymetr")}
library("daymetr")
# no delay calls
no_delay = unlist(lapply(1:100, function(...){
# download data
error = try(download_daymet(silent = TRUE))
@khufkens
khufkens / MCD12Q1_median_class.js
Created Nov 12, 2017
Median MODIS Land Cover (MCD12Q1) Map
View MCD12Q1_median_class.js
// years to process (from start year t0 to end year t1)
var t0 = "2001";
var t1 = "2014";
var LC = ee.ImageCollection('MCD12Q1')
.select('Land_Cover_Type_1')
.filterDate(t0.concat("-01-01"),t1.concat("-12-31"))
.median();
// Create a geometry representing an export region.
@khufkens
khufkens / tropicos_species_distribution.r
Created Oct 18, 2017
Scrape Tropicos for species distribution information
View tropicos_species_distribution.r
#' @param species: genus species or genus
#' @param quiet: TRUE / FALSE provides verbose output
#' @keywords Tropicos, species distribution
#' @examples
#'
#' # with defaults, outputting a data frame with species distribution
#' # for Clematis
#' df <- tropicos.species.distribution()
#' # returns NA if no data are present
#' [requires the rvest package for post-processing]
@khufkens
khufkens / robinson_map.r
Last active May 17, 2017
An example of the robinson maps often used to represent global modelling data
View robinson_map.r
library(raster)
library(maps)
library(maptools)
library(sf)
library(scales)
# set coordinate systems
robinson = CRS(" +proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
latlon = CRS("+init=epsg:4326")
@khufkens
khufkens / polar_map.r
Last active Nov 13, 2018
Fancy polar plot in R
View polar_map.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)
You can’t perform that action at this time.