From: Justin Kitzes Date: Tue, 13 Nov 2012 04:00:44 +0000 (-0800) Subject: Script to make data_pops.csv table X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=38452ed3731a8f1f4f9cdf3fa2207d7a84f85c95;p=swc-testing-nose.git Script to make data_pops.csv table --- 38452ed3731a8f1f4f9cdf3fa2207d7a84f85c95 diff --git a/python/make_data_pops.py b/python/make_data_pops.py new file mode 100644 index 0000000..68ae79f --- /dev/null +++ b/python/make_data_pops.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +''' +Make and save logistic growth population data +''' + +from __future__ import division +import numpy as np + +def logistic_growth(r, K, n0, p=0.1): + # Set up population array + n = np.zeros((npops, nt)) + n[:,0] = n0 + + # Loop through all time steps + steps = np.arange(1, nt) + for i in steps: + cat = (np.random.rand(npops) < p) # Random catastrophe 10% of time + ni = np.round(n[:,i-1] + r*n[:,i-1]*(1 - n[:,i-1]/K)) + ni[cat] = n0 + n[:,i] = ni + + return n + +if __name__ == '__main__': + nt = 15 + npops = 50 + result = logistic_growth(0.6, 100, 10) + np.savetxt('data_pops.csv', result, '%i', ',')