source: trunk/anuga_work/development/mem_time_tests/parameters/timelen-over-timestep/main.py @ 8331

Last change on this file since 8331 was 8331, checked in by pittj, 12 years ago

update for the new experiments

  • Property svn:executable set to *
File size: 3.3 KB
Line 
1#------------------------------------------------------------------------------
2# Import necessary modules
3#------------------------------------------------------------------------------
4# Import standard shallow water domain and standard boundaries.
5import anuga
6import time
7import subprocess
8import csv
9import os
10from anuga.abstract_2d_finite_volumes.util import add_directories
11from anuga.utilities.log_analyser import analyse_log
12
13
14#------------------------------------------------------------------------------
15# Set up variables for the correct directories to store the output
16#------------------------------------------------------------------------------
17home = os.getenv('INUNDATIONHOME')
18scenariodir = add_directories(home, ["data","mem_time_test", "parameters",
19                                     "timelen-over-timestep"])
20meta = 'metalog.csv'
21meta_path = os.path.join(scenariodir, meta)
22final = 'final.csv'
23final_path = os.path.join(scenariodir, final)
24
25# main loops that give the time length (m) and the time step (n)
26for m in range(10,1000,200):
27
28    for n in range(10,1000,100):
29        n = n/100.0 #adjust it so its small enough to see the nature of the relationship
30        subprocess.call(['python2.5', 'ex1.py',str(m),str(n)])#run it
31print 'Done'
32
33#get the important data for the experiments from the anuga experiments
34analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) 
35
36#open files to read from and write to
37metalog = csv.reader(open(meta_path,'rb'))
38final = csv.writer(open(final_path,'wb'))
39
40#list stores the index of the values requird
41indexlist = []
42
43#read in the first row
44firstrow = metalog.next()
45
46#get the indices of the values we want, so that the data can be condensed
47indexlist.append(firstrow.index("beforetime"))
48indexlist.append(firstrow.index("aftertime"))
49indexlist.append(firstrow.index("beforesimulationmemory"))
50indexlist.append(firstrow.index("aftermeshmemory"))
51indexlist.append(firstrow.index("afterinitialconditionsmemory"))
52indexlist.append(firstrow.index("afterboundarymemory"))
53indexlist.append(firstrow.index("aftersimulationmemory"))
54indexlist.append(firstrow.index("variable1"))
55
56#not all experiments have 3 variables, but some do
57try:
58    indexlist.append(firstrow.index("variable2"))
59except ValueError:
60    indexlist.append(firstrow.index("beforetime"))
61try:
62    indexlist.append(firstrow.index("variable3"))
63except ValueError:
64    indexlist.append(firstrow.index("aftertime"))
65
66#write the header for the final csv
67final.writerow(["TimeTaken(s)",firstrow[(indexlist[2])],
68                firstrow[(indexlist[3])],firstrow[(indexlist[4])],
69                firstrow[(indexlist[5])],firstrow[(indexlist[6])],
70                firstrow[(indexlist[7])],firstrow[(indexlist[8])],
71                firstrow[(indexlist[9])]])
72
73#write the data for each column in the final csv
74for row in metalog:
75
76    #manipulate the beginning and end time to get the time taken
77    begin = time.strptime(row[(indexlist[0])],'%Y%m%d_%H%M%S')
78    end = time.strptime(row[(indexlist[1])],'%Y%m%d_%H%M%S')
79    taken = time.mktime(end) - time.mktime(begin)
80
81    #write to file
82    final.writerow([str(taken),row[(indexlist[2])],
83                    row[(indexlist[3])],row[(indexlist[4])],
84                    row[(indexlist[5])],row[(indexlist[6])],
85                    row[(indexlist[7])],row[(indexlist[8])],
86                    row[(indexlist[9])]])
87
88
Note: See TracBrowser for help on using the repository browser.