def find_shape(pdic):
    # Varian files are typically either from imaging experiments or
    # from NMR experiments.  For both the direct dimension (R+I) is stored in
    # the np parameters in the procpar file.  In addition an array may be
    # present.

    # Imaging experiments have a 'seqcon' parameter present in the procpar and
    # have indirect dimension are set by nv, nv2, and nv3.

    # NMR experiments has indirect dimension shapes (R|I) are stored in
    # ni,ni2,ni3 with the phase arrays stored as phase,phase2,phase3

    # Thanks to the VeSPA project (http://scion.duhs.duke.edu/vespa/) for
    # information on imaging experiments

    try:
        shape = [int(pdic["np"]["values"][0]) // 2]
    except:
        # when shape finding fails issue warning and return None
        warn("shape cannot be determined.")
        return None

    # check for an array, we will deal only with the inner most array.
    # When multiple parameters are arrayed the ordering of indirect dimension
    # must also be known, which typically is not provided, so we will leave
    # this edge case to the user.
    if "array" in pdic:
        array_name = pdic['array']['values'][0]
        array_name = array_name.split(',')[-1]   # keep only innermost array
        if array_name.startswith('phase') is False and array_name in pdic:
            shape.insert(0, len(pdic[array_name]["values"]))

    # imaging files have a seqcon parameter
    if 'seqcon' in pdic:
        if "nv" in pdic:
            s = max(int(pdic["nv"]["values"][0]), 1)
            if s > 1:
                shape.insert(0, s)
        if "nv2" in pdic:
            s = max(int(pdic["nv2"]["values"][0]), 1)
            if s > 1:
                shape.insert(0, s)

        if "nv3" in pdic:
            s = max(int(pdic["nv3"]["values"][0]), 1)
            if s > 1:
                shape.insert(0, s)
        return tuple(shape)

    # assume we have NMR data
    if "ni" in pdic:
        multi = 2       # assume R+I in cases where no phase parameter.
        if "phase" in pdic:
            multi = len(pdic["phase"]["values"])
        s = max(int(pdic["ni"]["values"][0]), 1)
        shape.insert(0, s * multi)

    if "ni2" in pdic:
        multi = 2
        if "phase2" in pdic:
            multi = len(pdic["phase2"]["values"])
        s = max(int(pdic["ni2"]["values"][0]), 1)
        shape.insert(0, s * multi)

    if "ni3" in pdic:
        multi = 2
        if "phase3" in pdic:
            multi = len(pdic["phase"]["values"])
        s = max(int(pdic["ni3"]["values"][0]), 1)
        shape.insert(0, s * multi)

    return tuple(shape)
Determine the shape of a Agilent/Varian file from the procpar dictionary
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/varian.py/find_shape