Ignore:
Timestamp:
Feb 10, 2012, 10:34:08 AM (12 years ago)
Author:
pittj
Message:

update for the new experiments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/mem_time_tests/parameters/timelen-over-timestep/main.py

    r8328 r8331  
    55import anuga
    66import time
    7 import random
    87import subprocess
    98import csv
     
    1918scenariodir = add_directories(home, ["data","mem_time_test", "parameters",
    2019                                     "timelen-over-timestep"])
    21 file = 'ex1.csv'
    22 file_path = os.path.join(scenariodir, file)
    2320meta = 'metalog.csv'
    2421meta_path = os.path.join(scenariodir, meta)
     
    2623final_path = os.path.join(scenariodir, final)
    2724
    28 #create each file
    29 firstex1 = open(file_path, 'wb')
    30 spamWriter = csv.writer(firstex1)
    31 spamWriter.writerow(['Time Length(s)','Time Step (s)' , 'Time Taken','Space Used'])
     25# main loops that give the time length (m) and the time step (n)
     26for m in range(10,1000,200):
    3227
    33 # main loops that give the time length (m) and the time step (n)
    34 for m in range(1,1000,50):
    35 
    36     for n in range(1,1000,5):
     28    for n in range(10,1000,100):
    3729        n = n/100.0 #adjust it so its small enough to see the nature of the relationship
    38 
    39         x = time.time()#time it
    4030        subprocess.call(['python2.5', 'ex1.py',str(m),str(n)])#run it
    41         y = time.time()#time it
    42         spamWriter.writerow([m,n ,(y-x),'b'])#write the results
    43 
    4431print 'Done'
    4532
    46 analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv')) #get the memory usage from the log files
     33#get the important data for the experiments from the anuga experiments
     34analyse_log(scenariodir, os.path.join(scenariodir,'metalog.csv'))
    4735
    48 #close ex1.csv so we can read from it for a different csv reader object
    49 firstex1.close()
    50 
    51 #merge the metalog useful memory info and the ex1 recorded info into one csv file named final
    52 ex1 = csv.reader(open(file_path,'rb'))
     36#open files to read from and write to
    5337metalog = csv.reader(open(meta_path,'rb'))
    5438final = csv.writer(open(final_path,'wb'))
    5539
     40#list stores the index of the values requird
     41indexlist = []
    5642
    57 for row in ex1:
    58     d = metalog.next()
    59     final.writerow([row[0],row[1],d[0],d[3],d[6],d[9],d[12]])#,d[15],d[18]])
     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 TracChangeset for help on using the changeset viewer.