def reorder_data(data, shape, torder):
    """
    Reorder raw data from file.

    Parameters
    ----------
    data : 2D ndarray
        Raw data as ordered in binary file.
    shape : tuple of ints
        Shape of the NMR data.
    torder : {'f', 'r', 'o' of Pytho function}
        Trace ordering . See :py:func:`read` for details.

    Returns
    -------
    tdata : ndarray
        Array of NMR data.

    Notes
    -----
    Minimal error checking is done to see if data and shape contain the same
    number of values.  This should be done before calling this function.

    """
    # take care of flat files...
    if torder == 'flat' or torder == 'f':
        try:
            data = data.reshape(shape)
        except __HOLE__:
            warn(str(data.shape) + "cannot be shaped into" + str(shape))
        return data

    # all other cases
    # make an empty array to hold reordered data
    ndata = np.empty(shape, dtype=data.dtype)

    # index2tuple converter
    i2t = torder2i2t(torder)

    # loop over all non-direct dimension indices
    for tup in np.ndindex(shape[:-1]):
        # determine the corresponding trace
        ntrace = i2t(shape[:-1], tup)
        # write the trace to the index
        ndata[tup] = data[ntrace]
    return ndata
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/varian.py/reorder_data