-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotDistr.py
94 lines (79 loc) · 3.05 KB
/
plotDistr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# =============================================================================
# Plotting script to accompany HOT theory simulation.
# Connected Tree interval size distributions.
#
# Author: Max Graves
# Last Revised: 21-MAR-2013
# =============================================================================
import pylab as pl
import argparse, os, glob, sys
# =============================================================================
# parse the cmd line
# =============================================================================
def parseCMD():
"""
Parse cmd line.
"""
helpString = ('This script plots connected tree interval size distributions\
from the 1D HOT model.\
It takes a value of N (number of sites) and L (characteristic scale).\
This assumes that the Yield_N_L_D.txt files generated from the code\
will exist in the same directory as this script, and that the number\
of sparks laid is the same for each file with the same values of N\
and L.')
parser = argparse.ArgumentParser(description=helpString)
parser.add_argument("fileN", help='Peak... file')
return parser.parse_args()
# =============================================================================
def getD(f):
"""
strips the D value out of the data file name.
"""
k = f[:-4]
i, t = -1, True
newt = ''
while t==True:
if k[i].isdigit():
newt += k[i]
else:
t = False
i -= 1
return newt[::-1]
# =============================================================================
# begin main
# =============================================================================
def main():
# read in the forest as peak yield
args = parseCMD()
fileName = args.fileN
forest = pl.loadtxt(fileName)
# determine which sites were left unTreed at maximum yield
sitesLeft = pl.array([])
for i in xrange(forest.size):
if forest[i]!=1:
sitesLeft = pl.append(sitesLeft, i)
sitesLeft = sitesLeft[::-1]
# determine intervals and sort them in order of size
intervals = pl.array([forest.size-1-sitesLeft[0]])
for i in xrange(1,sitesLeft.size-1):
sizeInt = sitesLeft[i]-sitesLeft[i+1]
intervals = pl.append(intervals, sizeInt)
intervals = pl.append(intervals, sitesLeft[-1])
intervals = pl.sort(intervals)
# assign each interval a number
nums = pl.arange(1,sitesLeft.size+1)
# main plot
fig1 = pl.figure(1)
ax = fig1.add_subplot(111)
pl.ylabel('Interval Size', fontsize=20)
pl.xlabel('(Sorted) Inverval Number', fontsize=20)
# loop over and plot each file we find
newt = getD(fileName)
ax.plot(nums,intervals,label='(D=%s)'%(newt), marker='o', linewidth=0,
markerfacecolor='None', markeredgecolor='Navy')
# put labels into legend
ax.legend(loc='upper left',shadow=True)
pl.show()
# =============================================================================
if __name__=='__main__':
main()