[portland] Need Help With a For Loop
Rich Shepard
rshepard at appl-ecosys.com
Sat Mar 22 01:20:27 CET 2008
On Fri, 21 Mar 2008, kirby urner wrote:
> OK, so here's my solution, using only basic Python:
> starting = True
...
> starting = False
Kirby,
The flag was the key. I've used flags for control in C code so I don't
know why it did not occur to me to use one in the Python code. But, it
didn't.
I cleaned up the code significantly, Dylan, and now have to fix some
problems with the plotting functions and matplotlib itself. But, all you
lifted me out of the rut, and I greatly appreciate it.
The working code is attached.
Carpe weekend,
Rich
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
-------------- next part --------------
#!/usr/bin/env python
import os, config, functions
import matplotlib
import matplotlib.numerix as nx
import pylab
varData = [("Low","Variety","Fish","Wildlife","Decay S-Curve",1,0.0,100.0,0.0,50.0,0.0,50.0,50.0,50.0,100.0,1.0,2),
("High","Variety","Fish","Wildlife","Growth S-Curve",2,0.0,100.0,0.0,50.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","HabitatComplexity","Terrestrial","Wildlife","Decay S-Curve",1,0.0,100.0,0.0,50.0,0.0,50.0,50.0,50.0,100.0,1.0,2),
("High","HabitatComplexity","Terrestrial","Wildlife","Growth S-Curve",2,0.0,100.0,0.0,50.0,0.0,100.0,50.0,50.0,100.0,1.0,2),
("Low","Variety","Terrestrial","Wildlife","Decay S-Curve",1,50.0,50.0,0.0,100.0,0.0,0.0,50.0,50.0,100.0,1.0,2),
("High","Variety","Terrestrial","Wildlife","Growth S-Curve",2,0.0,100.0,0.0,50.0,0.0,50.0,50.0,100.0,100.0,1.0,2),
("Low","HabitatComplexity","Fish","Wildlife","Decay S-Curve",1,0.0,100.0,0.0,50.0,0.0,50.0,50.0,0.0,100.0,1.0,2),
("High","HabitatComplexity","Fish","Wildlife","Growth S-Curve",2,0.0,100.0,0.0,50.0,0.0,50.0,50.0,100.0,100.0,1.0,2),
("Low","SpecialConcern","Fish","Wildlife","Decay S-Curve",1,0.0,50.0,0.0,50.0,0.0,50.0,50.0,0.0,50.0,1.0,3),
("Moderate","SpecialConcern","Fish","Wildlife","Bell Curve",2,0.0,100.0,0.0,100.0,0.0,50.0,50.0,50.0,50.0,1.0,3),
("Many","SpecialConcern","Fish","Wildlife","Growth S-Curve",3,50.0,100.0,50.0,50.0,0.0,100.0,50.0,100.0,50.0,1.0,3)]
def testCode():
for row in varData:
curComp = row[3]
curSub = row[2]
curVar = row[1]
plotting = False
plotting = True
if plotting:
pylab.hold(True)
if row[4] == 'Decay S-Curve':
functions.zCurve(row[10],row[9])
elif row[4] == 'Bell Curve':
functions.gaussCurve(row[13],row[14])
elif row[4] == 'Growth S-Curve':
functions.sCurve(row[8],row[11])
elif row[4] == 'Beta':
functions.betaCurve(row[13],row[12],row[14])
elif row[4] == 'Data':
continue
elif row[4] == 'Linear Increasing':
functions.linearIncrCurve(row[8],row[11])
elif row[4] == 'Linear Decreasing':
functions.linearDecrCurve(row[10],row[9])
elif row[4] == 'Left Shoulder':
functions.leftShoulderCurve(row[10],row[11],row[9])
elif row[4] == 'Trapezoid':
functions.trapezoidCurve(row[8],row[10],row[11],row[9])
elif row[4] == 'Right Shoulder':
functions.rightShoulderCurve(row[8],row[10],row[11])
elif row[4] == 'Triangle':
functions.triangleCurve(row[8],row[13],row[9])
elif row[4] == 'Singleton':
functions.singletonCurve(row[13],row[14])
elif row[4] == 'Rectangle':
functions.rectangleCurve(row[8],row[10],row[11],row[9])
elif row[4] == 'Outcome':
functions.outcomeCurve()
print "Current curve: ", row[5], '\t', "Max. curves: ", row[16]
if row[5] == row[16]:
plotting = False
pylab.savefig(curVar+'.png')
pylab.hold(False)
if __name__ == "__main__":
testCode()
More information about the Portland
mailing list