def split_data(im_in, dim):
    from numpy import array_split
    dim_list = ['x', 'y', 'z', 't']
    # Parse file name
    # Open first file.
    data = im_in.data
    if dim+1 > len(shape(data)):  # in case input volume is 3d and dim=t
        data = data[..., newaxis]
    # Split data into list
    data_split = array_split(data, data.shape[dim], dim)
    # Write each file
    im_out_list = []
    for i, dat in enumerate(data_split):
        im_out = im_in.copy()
        im_out.data = dat
        im_out.setFileName(im_out.file_name+'_'+dim_list[dim].upper()+str(i).zfill(4)+im_out.ext)
        im_out_list.append(im_out)

    return im_out_list
Add fields that will be included in all messages sent through this
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/sct_image.py/split_data--crossover with--dataset/ETHPy150Open ClusterHQ/eliot/eliot/_output.py/Destinations.addGlobalFields