Skip to content

Instantly share code, notes, and snippets.


Koen Hufkens khufkens

View GitHub Profile
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
# set colour theme
colours = brewer.pal(11,"RdBu")
# download CHIRP data
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')
// Create a geometry representing an export region.
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 / 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
# 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 / polar_map.r
Last active Nov 13, 2018
Fancy polar plot in R
View polar_map.r
#-------- arctic map
# function to slice and dice a map and convert it to an sp() object
maps2sp = function(xlim, ylim, l.out = 100, clip = TRUE) {
m = map(xlim = xlim, ylim = ylim, plot = FALSE, fill = TRUE)
khufkens / extract_MODIS_phenology_layer.r
Created Apr 14, 2017
Extract MODIS phenology dates (as DOY) from the MCD12Q2 HDF files and export as tiff.
View extract_MODIS_phenology_layer.r
# calculate adjusted phenology dates
# for greenness onset and maximum
extract_MODIS_phenology_layer <- function(value="increase",tiles_file="mytiles.txt"){
# load required libraries
require(MODIS) # to import the SDS layers
# list all hdf files, and extract unique years
khufkens /
Created Apr 14, 2017
Converts MOD04 'swath' data to gridded data, using internal ground control point data.
# swath to grid conversion for
# MOD04 reflectance data
# get the reprojection information
gdal_translate -of VRT HDF4_EOS:EOS_SWATH:"$1":mod04:Mean_Reflectance_Land land.vrt
gdal_translate -of VRT HDF4_EOS:EOS_SWATH:"$1":mod04:Mean_Reflectance_Ocean ocean.vrt
khufkens /
Created Apr 14, 2017
NCDC Batch Download Tool (command line) - downloads station data from the National Climatic Data Center
# Bash script to download all NCDC weather records for
# a list of stations (Station number (AWS/WMO/DATSAV3 number))
# (it's easy to adjust the script to take any selection
# of years, just replace the ncftpls query for the years
# with a years file of your own liking or a range in the
# for loop e.g. years 2001 - 2010 = {2001..2010..1} )
# raw data is downloaded, extracted from gz files
khufkens /
Created Apr 14, 2017
Renames Wingscape Plantcam files to the PhenoCam file format
# convert wingscape PlantCam files
# and moves the files into the desired file structure
# for easy processing with the PhenoCam GUI or toolkit
# NOTE: requires a running version of linux/Mac or cygwin
# with exif installed.
khufkens /
Created Apr 14, 2017
MODIS Batch Download Tool (MBDT) - downloads MODIS tiles per year / product
# MODIS Batch Download Tool Command Line (MBDTcl)
# Bash script to download all modis hdf files for a particular year
# to the current directory.
# Beware this script will only download level 5 products
# if other products are selected the script will fail.
# Coded by Koen Hufkens at Boston University 2010