Change orientation in 5-dim nifti files using nibabel

I have deforamtion vector field nifti files which consitis of 5 dimensions. For example, (127, 203, 161, 1, 3). These data are in PLI orientation. Now I want to convert them into RAS orientation.

I can convert and save any 3D nifiti files directly to RAS format using following few lines.

img_can = nibabel.load(img_vol_path)
canonical_img = nibabel.as_closest_canonical(img_can)
updated_image = nibabel.Nifti1Image(numpy.asanyarray(canonical_img.dataobj), canonical_img.affine)
nibabel.save(updated_image, output_nifti_Path)

My question is how can I convert them into RAS oreintaion using nibabel ? Can I use the same procedure to convert 5 dimensional data ?

I’m asking because the created 5-dim file after using the aforementioned procedure cannot be opened with simpleITK. The original 5-dim file, however, possible to open with simpleItk. THe error message I have got is as below.
Exception thrown in SimpleITK ReadImage: .\src\sitkImageFileReader.cxx:325:
sitk::ERROR: The file has unsupported 5 dimensions.

Please help me to resolve this issue.

Yes. as_closest_canonical only rotates the spatial dimensions.

@Suranga I would carefully consider why you rotate data from PLI to RAS. This will be a lossless re-ordering of the image data on disk. In this case, you are transposing and flipping the rows and columns, and flipping the order of slices. At a minimum, the SliceTiming vector in the BIDS JSON file will need to be flipped.