Last active
March 29, 2016 19:26
-
-
Save tomkooij/c8d2e0c0a1a8444e16c0a1a271e7b747 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
import numpy | |
from hashlib import md5 | |
from tables.utilsExtension import get_nested_field | |
import numexpr | |
from numexpr.necompiler import NumExpr, stringToExpression | |
import tables | |
FILENAME = '/data/hisparc/corsika/corsika_overview.h5' | |
def do_md5(args): | |
m = md5() | |
for arg in args: | |
m.update(arg) | |
return m.hexdigest() | |
def makeNumExpr(): | |
""" Make a NumExpr object exactly as pytables """ | |
mysig = [('energy', float)] | |
print 'mysig ', mysig | |
typemap = {'energy': float} | |
strexpr = stringToExpression('log10(energy) >= 14.', typemap, {}) | |
print "strexpr ", strexpr | |
return NumExpr(strexpr, mysig) | |
if __name__ == '__main__': | |
print "numexpr version: ", numexpr.__version__ | |
expr = makeNumExpr() | |
data = tables.open_file(FILENAME, 'r') | |
e = data.root.simulations.col('energy') | |
dt = [('energy', numpy.float32)] | |
energy = numpy.array(e, dtype=dt) | |
#print energy | |
#print expr.program.encode('hex') | |
#print expr.signature | |
#print expr.input_names | |
#print sum(expr.run(energy)) | |
recarrs = [energy, data.root.simulations.read()] | |
for recarr in recarrs: | |
print "next array" | |
print "type of recarr", type(recarr) | |
field = get_nested_field(recarr, 'energy') | |
print "sum field: ", sum(field) | |
print "type of field: ", type(field) | |
print "md5 hash of field: ", do_md5(*[field]) | |
# this is the call pytables makes in tables.conditions.call_on_recarray() | |
print sum(expr(*[field])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment