def cmd_tool(args=None):
from argparse import ArgumentParser<EOL>if not HAS_BITSHUFFLE:<EOL><INDENT>print("<STR_LIT>")<EOL>exit()<EOL><DEDENT>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT:filename>', type=str, help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>fileroot = args.filename.split('<STR_LIT>')[<NUM_LIT:0>]<EOL>filelist = glob.glob(fileroot + '<STR_LIT>')<EOL>filelist = sorted(filelist)<EOL>r = GuppiRaw(filelist[<NUM_LIT:0>])<EOL>header, data = r.read_next_data_block()<EOL>dshape = data.shape <EOL>print(dshape)<EOL>n_blocks_total = <NUM_LIT:0><EOL>for filename in filelist:<EOL><INDENT>print(filename)<EOL>r = GuppiRaw(filename)<EOL>n_blocks_total += r.n_blocks<EOL><DEDENT>print(n_blocks_total)<EOL>full_dshape = np.concatenate(((n_blocks_total,), dshape))<EOL>h5 = h5py.File(fileroot + '<STR_LIT>', '<STR_LIT:w>')<EOL>h5.attrs['<STR_LIT>'] = '<STR_LIT>'<EOL>block_size = <NUM_LIT:0>      <EOL>dset = h5.create_dataset('<STR_LIT:data>',<EOL>shape=full_dshape,<EOL>dtype=data.dtype) <EOL>h5_idx = <NUM_LIT:0><EOL>for filename in filelist:<EOL><INDENT>print("<STR_LIT>" % filename)<EOL>r = GuppiRaw(filename)<EOL>h5 = h5py.File(filename + '<STR_LIT>', '<STR_LIT:w>')<EOL>header, data = r.read_next_data_block()<EOL>for ii in range(<NUM_LIT:0>, r.n_blocks):<EOL><INDENT>t0 = time.time()<EOL>print("<STR_LIT>" % (h5_idx+<NUM_LIT:1>, full_dshape[<NUM_LIT:0>]))<EOL>header, data = r.read_next_data_block()<EOL>t1 = time.time()<EOL>t2 = time.time()<EOL>print("<STR_LIT>" % (h5_idx+<NUM_LIT:1>, full_dshape[<NUM_LIT:0>]))<EOL>dset[h5_idx, :] = data<EOL>t3 = time.time()<EOL>print("<STR_LIT>" % ((t1-t0), (t3-t2)))<EOL>h5_idx += <NUM_LIT:1><EOL>for key, value in header.items():<EOL><INDENT>dset.attrs[key] = value<EOL><DEDENT><DEDENT>h5.close()<EOL>t1 = time.time()<EOL>print("<STR_LIT>" % (t1- t0))<EOL><DEDENT>
Command line tool for converting guppi raw into HDF5 versions of guppi raw