Python script for Vortex

Vortex is used on the Conservation Biology MSc course at UCT to simulate the extinction process of a species stochastically. Its user interface in managing/renaming different scenarios isn’t great, and I was a bit lazy and ended up with a single vortex project file containing a huge number of scenarios that were redundant for my project. I certainly wasn’t going to create them all again from scratch, so I manually removed the chunks in my .vpj pertaining to the simulations I no longer wanted, and wrote a quick script which would fix all of the numbering and references throughout the .vpj program using Python and regex. I hope this will help someone else:

import re
btm = open('C:/yourpathto/vortexproject.vpj', 'r')
i = 0
outputdata = []

# Iterate through all of the scenario notes, keeping track of what number we are on and changing numbers as necessary
for line in btm:
 match = re.match('^\[(\d\d?\d?) Scenario Notes\]$', line)
 if match:
   i = i + 1
 match ='^\[\d\d?\d?\d? ', line)
 if match:
   line = re.sub('^\[\d\d?\d?\d? ','[' + str(i) + ' ', line)

# Create a new file to output the data
outputfile = open('C:/replacementvortexproject.vpj', 'w')
# Loop through each line in outputdata and add it to the new file
for line in outputdata:
# Close the file and print to screen to know the program has ended
print 'Finished'

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>