# Slicer does not accept certain transform values

**URL:** <https://discourse.slicer.org/t/slicer-does-not-accept-certain-transform-values/41398>\
**Category:** Development\
**Created:** [January 31, 2025, 11:26am UTC](https://discourse.slicer.org/t/slicer-does-not-accept-certain-transform-values/41398 "2025-01-31T11:26:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheZappie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thezappie/32/79279_2.png) [@TheZappie](https://discourse.slicer.org/u/TheZappie)\
**Post date:** [January 31, 2025, 11:26am UTC](https://discourse.slicer.org/t/slicer-does-not-accept-certain-transform-values/41398/1 "2025-01-31T11:26:55Z")

</div>

3d slicer does not import volumes that I create with the python code below.  
What constraint in 3D slicer is causing this?

```python
import numpy as np

import nibabel as nib
from nibabel import affines

data = np.random.normal(size=(100, 100, 100))

# this works, imports into 3D Slicer:
rotation = 4.683045966258175
translation = np.round(np.array([364049.08509937, 5991031.44814528, 0.]))

# this works, imports into 3D Slicer:
rotation = 4.69
translation = np.round(np.array([364049.08509937, 5991031.44814528, 0.]))

# this does not import into 3D Slicer:
rotation = 4.683045966258175
translation = np.array([364049.08509937, 5991031.44814528, 0.])

dxv = 0.05
dyv = 0.05
affine = np.array([[np.cos(rotation) * dxv, -np.sin(rotation) * dyv, 0],
                   [np.sin(rotation) * dxv, np.cos(rotation) * dyv, 0],
                   [0, 0, 1]]
                  )

nii_matrix = affines.from_matvec(affine, translation)

nifti_img = nib.Nifti1Image(data, nii_matrix)
nib.save(nifti_img, r"D:\TEST\test.nii")

```

I suspect it might have to do with units within 3D slicer. I tested with these settings:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba7046b9687066b5076e69d548d4789ab73fcae2.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 3, 2025, 8:24am UTC](https://discourse.slicer.org/t/slicer-does-not-accept-certain-transform-values/41398/2 "2025-02-03T08:24:37Z")

</div>

Probably the non-normalized image position values cause the problem.

Units are not causing the problem: support in Slicer is added to be able to avoid such extreme position values by choosing the most appropriate coordinate system. However, current units implementation has many limitations, so it cannot yet automatically fix such files yet.

I see that you added an issue for this, let’s continue the discussion there:

> <https://github.com/Slicer/Slicer/issues/8203#issuecomment-2630222560>
>
> \## Summary
> 
> 3d slicer does not import volumes that I create with the python code… below. Posting this here because I believe this is closer to a bug report than a usage question. 
> What constraint in 3D slicer is causing this issue?
> 
> \## Steps to reproduce
> 
> On importing the files, the volume is not loaded, and a error is produced. \[Error.txt\](https://github.com/user-attachments/files/18638632/Error.txt)
> Produced by the code below
> 
> \`\`\`python
> import numpy as np
> 
> import nibabel as nib
> from nibabel import affines
> 
> data = np.random.normal(size=(100, 100, 100))
> 
> \# this works, imports into 3D Slicer:
> rotation = 4.683045966258175
> translation = np.round(np.array(\[364049.08509937, 5991031.44814528, 0.\]))
> 
> \# this works, imports into 3D Slicer:
> rotation = 4.69
> translation = np.round(np.array(\[364049.08509937, 5991031.44814528, 0.\]))
> 
> \# this does not import into 3D Slicer:
> rotation = 4.683045966258175
> translation = np.array(\[364049.08509937, 5991031.44814528, 0.\])
> 
> dxv = 0.05
> dyv = 0.05
> affine = np.array(\[\[np.cos(rotation) \* dxv, -np.sin(rotation) \* dyv, 0\],
> \[np.sin(rotation) \* dxv, np.cos(rotation) \* dyv, 0\],
> \[0, 0, 1\]\]
> )
> 
> 
> nii\_matrix = affines.from\_matvec(affine, translation)
> 
> nifti\_img = nib.Nifti1Image(data, nii\_matrix)
> nib.save(nifti\_img, r"D:\\TEST\\test.nii")
> \`\`\`
> 
> 
> \## Environment
> \- Slicer version: 5.8.0 r33216 / d20ee94
> \- Operating system: Windows10
