From 38452ed3731a8f1f4f9cdf3fa2207d7a84f85c95 Mon Sep 17 00:00:00 2001 From: Justin Kitzes Date: Mon, 12 Nov 2012 20:00:44 -0800 Subject: [PATCH] Script to make data_pops.csv table --- python/make_data_pops.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 python/make_data_pops.py 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', ',') -- 2.26.2