Rev. | 3f535e30889fb692dfee04aeb5423599bd902db7 |
---|---|
Größe | 1,306 Bytes |
Zeit | 2010-01-11 01:55:33 |
Autor | lorenzo |
Log Message | A small script (to be integrated in the older codes) to generate the couples of ID's associated to
|
#!/usr/bin/env python
import scipy as s
import pylab as p
import numpy as n
import sys
import string
def my_hash(arr): #this will operate on a similar function which
#has already combined tag_id and bootcount (both taking 16 bites each)
# my_hash(arr) >> 32 to get back the 1st argument
# my_hash(arr) & 0xFFFFFFFF to get back the second argument
arr=s.sort(arr) #maybe this is not needed at all; the rows of sliced data (which are arr)
#are already sorted out elsewhere.
return (arr[0] << 32) | arr[1]
def my_unhash(longnum): #this is the inverse of the function above
arr_out=s.zeros(2).astype("int64")
arr_out[0]= longnum >> 32
arr_out[1]= longnum & 0xFFFFFFFF
return (arr_out)
f = open(sys.argv[1])
hashed_interactions = [map(int, string.split(line)) for line in f.readlines()]
f.close()
hashed_interactions = s.array(hashed_interactions, dtype="int64")
decoupled_arr=s.zeros((len(hashed_interactions),2)).astype("int64")
for i in xrange(len(hashed_interactions)):
decoupled_arr[i,:]=my_unhash(hashed_interactions[i])
n.savetxt("decoupled_hash_for_contact_durations_1_.dat", decoupled_arr, fmt='%d')
n.savetxt("decoupled_hash_1d_for_contact_durations_1_.dat",\
decoupled_arr.reshape(-1,1), fmt='%d')
print "So far so good"