Skip to content

Instantly share code, notes, and snippets.

@dvreed77
Last active December 14, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvreed77/fa3060b18257008df383 to your computer and use it in GitHub Desktop.
Save dvreed77/fa3060b18257008df383 to your computer and use it in GitHub Desktop.
a small python script which generates some test data in which I want to run pairwise comparisons on. There is an unresolved error that comes up when running the `get_hd()` function
import numpy as np
import tables as tb
class Iris(tb.IsDescription):
subject_id = tb.IntCol()
iris_id = tb.IntCol()
database = tb.StringCol(5)
is_left = tb.BoolCol()
is_flipped = tb.BoolCol()
templates = tb.BoolCol(shape=(17, 20*480))
masks1 = tb.BoolCol(shape=(17, 20*480))
phasors = tb.ComplexCol(itemsize=8, shape=(17, 20*240))
masks2 = tb.BoolCol(shape=(17, 20*240))
def create_hdf5():
"""
"""
with tb.openFile('test.h5', 'w') as f:
# Create and fill the table of irises
irises = f.createTable(f.root, 'irises', Iris, 'Irises', filters=tb.Filters(1))
for ii in range(4620):
r = irises.row
r['subject_id'] = ii
r['iris_id'] = 0
r['database'] = 'test'
r['is_left'] = True
r['is_flipped'] = False
r['templates'] = np.empty((17, 20*480), np.bool8)
r['masks1'] = np.empty((17, 20*480), np.bool8)
r['phasors'] = np.empty((17, 20*240), np.complex)
r['masks2'] = np.empty((17, 20*240), np.bool8)
r.append()
irises.flush()
def get_hd():
"""
"""
from itertools import combinations, izip
with tb.openFile('test.h5') as f:
irises = f.root.irises
templates = f.root.irises.cols.templates
masks = f.root.irises.cols.masks1
N_irises = len(irises)
print '%i Comparisons' % (N_irises*(N_irises - 1)/2)
D = np.empty((N_irises, N_irises))
for (t1, m1, ii), (t2, m2, jj) in combinations(izip(templates, masks, range(N_irises)), 2):
D[ii, jj] = ii*jj
np.save('test', D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment