Skip to content

Instantly share code, notes, and snippets.

View Martin-Jung's full-sized avatar
🦆
Fixing bugs and saving ducks...

Martin Jung Martin-Jung

🦆
Fixing bugs and saving ducks...
View GitHub Profile
#define function to calculate area between the curves
area.between.curves <- function(yAxis1, yAxis2, xAxis)
{
d <- c(yAxis2 - yAxis1)[-1]
d <- d * diff(xAxis)
neg <- sum(abs(d[which(d < 0)]))
pos <- sum(d[which(d > 0)])
<html><head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<style>
html, body { background-color: white; }
table { border-collapse:collapse; border:none; }
caption { font-weight: bold; text-align:left; }
td { }
.thead { border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; }
.tdata { padding:0.2cm; text-align:left; vertical-align:top; }
.arc { background-color:#f2f2f2; }
@Martin-Jung
Martin-Jung / RPackageInstall.R
Last active April 30, 2022 10:17
A script to be sourced to install multiple r packages at once
# Martin Jung - 2018
# Function to check for installed packages and install them if they are not installed
install <- function(packages){
new.packages <- packages[!(packages %in% installed.packages()[, "Package"])]
if (length(new.packages))
install.packages(new.packages, dependencies = TRUE)
sapply(packages, require, character.only = TRUE)
}
@Martin-Jung
Martin-Jung / MK_dask.py
Created June 10, 2018 22:37
Mann kendall calculations on multidimensional arrays
# -*- coding: utf-8 -*-
"""
Created on Thu May 17 12:12:49 2018
@author: Martin Jung
@email: M.jung@sussex.ac.uk
Idea:
Set up a xarray-dask environment to be run on landsat stacks
Calculate pixelwise mann-kendal tests and retain sign. slopes
# -*- coding: utf-8 -*-
"""
Created on Thu May 24 13:43:36 2018
@author: mj291
"""
# Defaults defaults
import numpy as np
import matplotlib.pyplot as plt
@Martin-Jung
Martin-Jung / aggregateTIF2NC.py
Last active March 31, 2018 10:38
Aggregated all tifs in folder with a given name into a netcdf file
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 17 14:23:27 2015
@title: Creating netCDF container for all files
@author: Martin Jung
"""
from __future__ import print_function # make sure print behaves the same in 2.7 and 3.x
import netCDF4 as nc
@Martin-Jung
Martin-Jung / gist:ef687124b119b523e36924bc9c935f43
Created February 23, 2018 15:45
USGS elearning documents. Useful ?
https://lpdaac.usgs.gov/sites/default/files/public/elearning/GeoTIFF_MaskingPlottingAppEEARS_GeoTIFF_TS.html
# Source:
# https://github.com/soskuthy/gamm_intro/blob/master/gamm_hacks.r
post.sim.gamm <- function (mod, newdat, n=10000, exclude=NULL) {
lp.full <- predict(mod, newdata=newdat, type = "lpmatrix", exclude=exclude)
coefs.full <- coef(mod)
vc.full <- vcov(mod)
sim.full <- mvrnorm(n, mu = coefs.full, Sigma = vc.full)
fits.full <- lp.full %*% t(sim.full)
}
@Martin-Jung
Martin-Jung / colorcoded-map-population-structures.R
Created July 3, 2017 11:58 — forked from ikashnitsky/colorcoded-map-population-structures.R
Code to reproduce the RGB map of the population structure of NUTS-3 regions of Europe -- https://ikashnitsky.github.io/2017/colorcoded-map/
################################################################################
#
# ikashnitsky.github.io 2017-06-30
# Produce an RGB coded map of pop structures at NUTS-3 level
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
# Erase all objects in memory
rm(list = ls(all = TRUE))
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)