from scipy.spatial import Delaunay, ConvexHull
import networkx as nx
points = [ [0,0],[0,50],[50,50],[50,0],[0,400],[0,450],[50,400],[50,450],[700,300],[700,350],[750,300],[750,350],
[900,600],[950,650],[950,600],[900,650]
]
def concave(points,alpha_x=150,alpha_y=250):
points = [(i[0],i[1]) if type(i) <> tuple else i for i in points]
de = Delaunay(points)
import itertools as IT
def scale_polygon(path,offset):
center = centroid_of_polygon(path)
for i in path:
if i[0] > center[0]:
i[0] += offset
else:
i[0] -= offset
if i[1] > center[1]:
def clear(df):
array = df.values
for n,i in enumerate(array):
for k,j in enumerate(i):
if type(j) == str:
try:
j.decode('ascii')
except:
array[n][k] = j.decode('utf-8')
from bs4 import BeautifulSoup
def read_excel_xml(path):
file = open(path).read()
soup = BeautifulSoup(file,'xml')
workbook = []
for sheet in soup.findAll('Worksheet'):
sheet_as_list = []
for row in sheet.findAll('Row'):
import time
class print_time:
def __enter__(self):
self.time = time.time()
return self.time
def __exit__(self, type, value, traceback):
time_elapsed = time.time() - self.time
print time_elapsed
This file contains 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
from IPython.display import HTML | |
HTML(''' | |
<style> | |
.df tbody tr:nth-child(even) { background-color: lightblue; } | |
</style> | |
''' + df.to_html(classes='df')) |
from contextlib import contextmanager
@contextmanager
def catch(*exceptions, **kwargs):
try:
yield kwargs.get("default", None)
except exceptions or Exception:
print kwargs
from numpy import dot,array,empty_like
from matplotlib.path import Path
def make_path(x1,y1,x2,y2):
return Path([[x1,y1],[x1,y2],[x2,y2],[x2,y1]])
def perp( a ) :
b = empty_like(a)
b[0] = -a[1]
This file contains 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
def get_filelist(path, extension=None,only_folders=False): | |
'''Returns list of files in a given folder, without going further | |
Parameters | |
--------- | |
extension: Collect only files with this extension | |
only_folders: Collect only folders names | |
''' | |
filenames = [] | |
if not only_folders: |
This file contains 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
def sort_df(df, column_idx, key): | |
'''Takes dataframe, column index and custom function for sorting, | |
returns dataframe sorted by this column using this function''' | |
col = df.ix[:,column_idx] | |
temp = pd.DataFrame([]) | |
temp[0] = col | |
temp[1] = df.index | |
temp = temp.values.tolist() | |
df = df.ix[[i[1] for i in sorted(temp, key=key)]] |
OlderNewer