In [4]:
import tifffile
import blosc
import numpy as np
blosc.set_nthreads(4)
royer1 = "/scratch/steinbac/sqeasy_data/xwing/droso-royer-may31-000005.tif"
xwingr = tifffile.imread(royer1)
haase1 = "/scratch/steinbac/sqeasy_data/xwing/000195-rhaase-20171129-fused-512x1024x92.tif"
xwingh = tifffile.imread(haase1)
In [5]:
print(xwingr.shape,xwingh.shape)
In [7]:
import math
import time
smallr = xwingr[:,:200,:]
smallh = xwingh[:,:200,:]
sizes = {"smallr" : len(smallr.tobytes()), "smallh" : len(smallh.tobytes())}
bitshuffled_nbytes = {}
def scan_blocksize(data,_shuffle = blosc.BITSHUFFLE):
value = []
for f in [0.1,0.25,0.5,1,2,4,8]:
blosc.set_blocksize( math.floor(f*data.shape[-1]*data.shape[-2]*2) )
start = time.process_time()
compressed = blosc.compress(data.tobytes(),shuffle=_shuffle,cname="lz4")
end = time.process_time()
value.append((f,len(compressed),end-start))
return value
bitshuffled_nbytes["smallr"] = scan_blocksize(smallr)
bitshuffled_nbytes["smallh"] = scan_blocksize(smallh)
In [10]:
def summary(cdic,nbytes):
print("%8s %10s %s"%("factor","outbytes","compression ratio"))
for (k,v) in cdic.items():
print(k)
for item in v:
ratio = nbytes[k]/item[1]
bw = nbytes[k]/(1024*1024.*item[-1])
print("%8f %10i"%(item[0],item[1]),ratio,bw," MB/s")
summary(bitshuffled_nbytes,sizes)
In [11]:
noshuffle_nbytes = {}
noshuffle_nbytes["smallr"] = scan_blocksize(smallr,blosc.NOSHUFFLE)
noshuffle_nbytes["smallh"] = scan_blocksize(smallh,blosc.NOSHUFFLE)
summary(noshuffle_nbytes,sizes)
In [ ]: