# Path: crayimage/runutils/stream.py
# def hdf5_disk_stream(path, batch_sizes=8, cache_size=16):
#   queue = Queue(maxsize=cache_size)
# 
#   worker = threading.Thread(
#     target=hdf5_batch_worker,
#     kwargs=dict(path=path, out_queue=queue, batch_sizes=batch_sizes)
#   )
# 
#   worker.daemon = True
#   worker.start()
# 
#   return queue_stream(queue)
# 
# def np_disk_stream(data_root, batch_sizes=8, cache_size=16, mmap_mode='r'):
#   bin_patches = [
#     osp.join(data_root, 'bin_%d.npy' % i)
#     for i in range(len(os.listdir(data_root)))
#   ]
# 
#   if type(batch_sizes) in [long, int]:
#     batch_sizes = [batch_sizes] * len(bin_patches)
# 
#   queues = [ Queue(maxsize=cache_size) for _ in bin_patches ]
# 
#   workers = [
#     threading.Thread(
#       target=np_batch_worker,
#       kwargs=dict(path=path, out_queue=queue, batch_size=batch_size, mmap_mode=mmap_mode)
#     )
# 
#     for path, queue, batch_size in zip(bin_patches, queues, batch_sizes)
#   ]
# 
#   for worker in workers:
#     worker.daemon = True
#     worker.start()
# 
#   return queues_stream(queues)


from crayimage.runutils import hdf5_disk_stream, np_disk_stream
  import sys
  import os.path as osp
  import time

if __name__ == '__main__':
  DATA_PATH = sys.argv[1]
  HDF5 = False

  if HDF5:
    print('Using hdf5')

# Path: crayimage/runutils/stream.py
# def hdf5_disk_stream(path, batch_sizes=8, cache_size=16):
#   queue = Queue(maxsize=cache_size)
# 
#   worker = threading.Thread(
#     target=hdf5_batch_worker,
#     kwargs=dict(path=path, out_queue=queue, batch_sizes=batch_sizes)
#   )
# 
#   worker.daemon = True
#   worker.start()
# 
#   return queue_stream(queue)
# 
# def np_disk_stream(data_root, batch_sizes=8, cache_size=16, mmap_mode='r'):
#   bin_patches = [
#     osp.join(data_root, 'bin_%d.npy' % i)
#     for i in range(len(os.listdir(data_root)))
#   ]
# 
#   if type(batch_sizes) in [long, int]:
#     batch_sizes = [batch_sizes] * len(bin_patches)
# 
#   queues = [ Queue(maxsize=cache_size) for _ in bin_patches ]
# 
#   workers = [
#     threading.Thread(
#       target=np_batch_worker,
#       kwargs=dict(path=path, out_queue=queue, batch_size=batch_size, mmap_mode=mmap_mode)
#     )
# 
#     for path, queue, batch_size in zip(bin_patches, queues, batch_sizes)
#   ]
# 
#   for worker in workers:
#     worker.daemon = True
#     worker.start()
# 
#   return queues_stream(queues)


# Path: examples/disk_stream.py
from crayimage.runutils import hdf5_disk_stream, np_disk_stream
  import sys
  import os.path as osp
  import time


if __name__ == '__main__':
  DATA_PATH = sys.argv[1]
  HDF5 = False

  if HDF5:
    print('Using hdf5')

    stream = hdf5_disk_stream(osp.join(DATA_PATH, 'Co60.hdf5'), batch_sizes=8, cache_size=16)