Example #1
0
 def __init__(self, infile):
     """
     given a filename parse into many BIRDpacket instances
     """
     super(BIRDpackets, self).__init__()
     with open(infile, 'r') as fp:
         dat = fp.readlines()
     dat = [v.strip() for v in dat]
     self.filename = infile
     # make this class a list of BIRDpacket objects
     length = len(dat)
     for ii, v in enumerate(dat):
         if ii % 400 == 0:
             tb.progressbar(ii, 1, length, text='Parsing Packets')
         self.append(BIRDpacket(v, self.filename))
     tb.progressbar(length, 1, length, text='Parsing Packets')
     print('')
Example #2
0
 def test_progressbar(self):
     """progressbar shouldhave a known output"""
     realstdout = sys.stdout
     output = StringIO.StringIO()
     sys.stdout = output
     self.assertEqual(tb.progressbar(0, 1, 100), None)
     result = output.getvalue()
     output.close()
     self.assertEqual(result, "\rDownload Progress ...0%")
     sys.stdout = realstdout
Example #3
0
 def test_progressbar(self):
     """progressbar shouldhave a known output"""
     realstdout = sys.stdout
     output = StringIO.StringIO()
     sys.stdout = output
     self.assertEqual(tb.progressbar(0, 1, 100), None)
     result = output.getvalue()
     output.close()
     self.assertEqual(result, "\rDownload Progress ...0%")
     sys.stdout = realstdout
Example #4
0
import timeit
import os

import numpy as np
import spacepy.toolbox as tb

# this is a git access module useful in here.
import dulwich

ans = {}
for val in xrange(1, 9):
    tb_t = timeit.Timer("tb.linspace(1.5, 10.5, " + str(10**(val/2)) + ")", setup="import spacepy.toolbox as tb")
    np_t = timeit.Timer("np.linspace(1.5, 10.5, " + str(10**(val/2)) + ")", setup="import numpy as np")
    bnh = [np_t.timeit(10000)/tb_t.timeit(10000) for v in range(50)]    
    ans[10**(val/2)] = [np.mean(bnh), np.std(bnh)]
    tb.progressbar(val, 1, len(xrange(1, 9)), 'Progress')
    
x = np.array(ans.keys())
x.sort()
y = np.asarray([ans[v][0] for v in x])
yerr = np.asarray([ans[v][1] for v in x])
plt.errorbar(x, y, yerr, color='b', fmt='o-')
plt.xscale('log')
plt.xlabel('linspace points')
plt.ylabel('tb.linspace/np.linspace')
# get the title
rep = dulwich.repo.Repo(os.path.abspath('../../../'))
refs = rep.get_refs()
title = refs['HEAD']
plt.title(title)
plt.savefig('linspace_bench.png')