Skip to content

Instantly share code, notes, and snippets.

View tpoisot's full-sized avatar

Timothée Poisot tpoisot

View GitHub Profile
@tpoisot
tpoisot / gist:1202402
Created September 8, 2011 01:48
Use Warnock Pro for text and maths in XeLaTeX
\usepackage{mathspec}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Warnock Pro Light}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Myriad Pro}
\setmonofont[Scale=MatchLowercase]{Andale Mono}
\setmathfont(Greek,Latin,Digits){Warnock Pro Light}
@tpoisot
tpoisot / gist:1209734
Created September 11, 2011 15:55
Andralis ND OsF / ND SC in XeLaTeX
\setmainfont[
UprightFeatures = { SmallCapsFont = {Andralis ND SC} },
BoldFeatures = { SmallCapsFont = {Andralis ND SC Bold} },
ItalicFeatures = { SmallCapsFont = {Andralis ND SC Italic} },
BoldItalicFeatures = { SmallCapsFont = {Andralis ND SC Bold Italic} },
]{Andralis ND OsF}
@tpoisot
tpoisot / tritrophicPlot.py
Created November 23, 2011 21:07
Plotting a tri-trophic system in PyX
from pyx import *
import numpy as np
import scipy as sp
def null_bernoulli(top,bot,nint):
tint = top*bot
zeroes = tint-nint
## We only return a matrix with no non-interacting species
hasNull = True
trials = 0
@tpoisot
tpoisot / GenPop.r
Created December 4, 2011 18:48
Simple model of population genetics
gfreq = function(p) list(AA=p^2,Aa=2*p*(1-p),aa=(1-p)^2)
mfit = function(p,fit)
{
with(as.list(fit),{
mf = (p^2)*wAA+(2*p*(1-p)*wAa)+((1-p)^2)*waa
return(mf)
})
}
@tpoisot
tpoisot / 2Darray.py
Created December 14, 2011 17:09
Move along a 2D numpy array in weave/inline
import numpy as np
import scipy as sp
from scipy.weave import inline
def along2Darray(rows,cols):
arr = np.zeros((rows,cols))
code = """
int Pos;
for(int Row = 0; Row < rows; Row++)
@tpoisot
tpoisot / COFM.py
Created January 9, 2012 00:50
[Python] Number of co-occurences / draft
def COFM(comat,normal=True):
CoFreq = []
for sp1 in xrange(len(comat)-1):
for sp2 in xrange(sp1,len(comat)):
NCo = 0
for nsite in xrange(len(comat[0])):
if comat[sp1][nsite]*comat[sp2][nsite] > 0:
NCo += 1
if normal:
NCo /= len(comat[0])
@tpoisot
tpoisot / MatPermut.r
Created January 26, 2012 18:50
Permutation of a matrix with the diagonal kept constant
mat = matrix(abs(round(rnorm(100,15,8),0))+1,10)
diag(mat) = 0
print(mat)
permat = function(mat)
{
mat[lower.tri(mat)+upper.tri(mat)==1] = sample(mat[lower.tri(mat)+upper.tri(mat)==1],replace=FALSE)
return(mat)
}
@tpoisot
tpoisot / gist:2093483
Created March 19, 2012 03:40
MinionPro in LaTeX
\usepackage{MnSymbol}
\usepackage[mathlf,textlf,loosequotes]{MinionPro}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
@tpoisot
tpoisot / metaco.py
Created March 27, 2012 13:50
Simple metacommunity model in python using NetworkX
import matplotlib.pyplot as plt
import networkx as nx
import scipy as sp
import numpy as np
class comm:
"""
A CLASS FOR COMMUNITIES
pos : tuple with the spatial position
id : the name of the community
@tpoisot
tpoisot / gist:2725839
Created May 18, 2012 15:22
Metapop model using networkx
#!/usr/bin/env python
# encoding: utf-8
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
Patches = 100 # Number of patches
P_ext = 0.01 # Probability of extinction (e)
P_col = 0.014 # Probability of colonization (c)