Last active
January 5, 2017 05:11
-
-
Save calebrob6/a493c5e14d14cb6c8f118a285ffda567 to your computer and use it in GitHub Desktop.
IPython Notebook Header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import sys | |
import os | |
import time | |
import warnings | |
#warnings.filterwarnings("ignore") | |
#with warnings.catch_warnings(): | |
# warnings.simplefilter("ignore") | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
plt.style.use('ggplot') | |
import numpy as np | |
import resource | |
GIGA = 10**9 | |
MEGA = 10**6 | |
def limitMemory(maxsize): | |
soft, hard = resource.getrlimit(resource.RLIMIT_AS) | |
resource.setrlimit(resource.RLIMIT_AS, (maxsize, hard)) | |
memLimit = 8.00*GIGA | |
limitMemory(memLimit) | |
print "Starting notebook with %d byte memory limit" % (memLimit) | |
def startCell(message): | |
print "-" * 80 | |
print message | |
return float(time.time()) | |
def endCell(message, startTime): | |
print "Finished %s in %0.4f seconds" % (message, time.time()-startTime) | |
print "-" * 80 | |
def updateProgress(i,n,lastTime): | |
'''This will guess that the remaining time is linear. | |
''' | |
currentTime = (time.time()-lastTime) | |
remainingTime = (time.time()-lastTime) * (n-i) | |
print "%d/%d\t%0.4f seconds\t%0.4f seconds remaining" % (i, n, currentTime, remainingTime) | |
return float(time.time()) | |
def humansize(nbytes): | |
'''Call as humansize(X.nbytes) | |
''' | |
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] | |
if nbytes == 0: return '0 B' | |
i = 0 | |
while nbytes >= 1024 and i < len(suffixes)-1: | |
nbytes /= 1024. | |
i += 1 | |
f = ('%.2f' % nbytes).rstrip('0').rstrip('.') | |
return '%s %s' % (f, suffixes[i]) | |
_ = ''' | |
cellTime = startCell("Loading data") | |
endCell("loading data", cellTime) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment