def set_orientation(im, orientation, data_inversion=False, filename=False, fname_out=''):

    if fname_out:
        pass
    elif filename:
        path, fname, ext = extract_fname(im)
        fname_out = fname+'_'+orientation+ext
    else:
        fname_out = im.file_name+'_'+orientation+im.ext

    if not data_inversion:
        from sct_utils import run
        if filename:
            run('isct_orientation3d -i '+im+' -orientation '+orientation+' -o '+fname_out, 0)
            im_out = fname_out
        else:
            run('isct_orientation3d -i '+im.absolutepath+' -orientation '+orientation+' -o '+fname_out, 0)
            im_out = Image(fname_out)
    else:
        im_out = im.copy()
        im_out.change_orientation(orientation, True)
        im_out.setFileName(fname_out)
    return im_out


# START PROGRAM
# ==========================================================================================
Trap this failure if its type is in a predetermined list.
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/sct_image.py/set_orientation--crossover with--dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/python/failure.py/Failure.trap