Sct_dmri_moco [Errno 2] 0GenericAffine SCT v6.2

Dear SCT developers,

After successful T2 segmentation and shape analysis, I tried to perform Diffusion-weighted MRI processing on sagital dMRI data.

While “Generating mean image”, “Spinal cord segmentation” and “Creating a mask around the spinal cord” works well, the “Motion correction algorithm” failed at the “Estimation motion across groups” step, using this input code:

sct_dmri_moco -i Subj_DTI.nii -m mask_Subj_DTI_dwi_mean.nii -param metric=CC -bvec Subj_DTI_bvec.txt -qc ~/qc_singleSubj -qc-seg Subj_DTI_dwi_mean_seg.nii


Error message:
...
-------------------------------------------------------------------------------
  Estimating motion across groups...
-------------------------------------------------------------------------------

Input parameters:
  Input file ............ datasub-groups.nii
  Reference file ........ datasub_0_mean.nii.gz
  Polynomial degree ..... 2
  Smoothing kernel ...... 1
  Gradient step ......... 1
  Metric ................ CC
  Sampling .............. None
  Todo .................. estimate_and_apply
  Mask  ................. mask.nii
  Output mat folder ..... mat_groups

Data dimensions:
  144 x 192 x 40 x 12

[Z0 to Z39 register 100%]

Traceback (most recent call last):
  File "/opt/sct_6.2/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 223, in <module>
    main(sys.argv[1:])
  File "/opt/sct_6.2/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 208, in main
    fname_output_image = moco_wrapper(param)
  File "/opt/sct_6.2/spinalcordtoolbox/moco.py", line 364, in moco_wrapper
    copy_mat_files(nt, file_mat_datasub, index_moco, mat_final, param)
  File "/opt/sct_6.2/spinalcordtoolbox/moco.py", line 124, in copy_mat_files
    copyfile(fsrc, fdest)
  File "/opt/sct_6.2/python/envs/venv_sct/lib/python3.9/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'mat_groups/mat.Z0000T00000GenericAffine.mat

This error message is very similar to the one posted here:
https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/2625

I also checked for user write permission.

I can send private email with images and full (long) output message if needed

Thanks for your help!

Roger

Dependencies:

--
Spinal Cord Toolbox (6.2)
sct_check_dependencies
--
SYSTEM INFORMATION
------------------
SCT info:
- version: 6.2
- path: /opt/sct_6.2
OS: linux (Linux-5.15.0-107-generic-x86_64-with-glibc2.35)
CPU cores: Available: 24, Used by ITK functions: 24
RAM: Total: 48148MB, Used: 5998MB, Available: 41352MB
OPTIONAL DEPENDENCIES
---------------------
Check FSLeyes version...............................[OK] (1.11.0)
MANDATORY DEPENDENCIES
----------------------
Check Python executable.............................[OK]
Using bundled python 3.9.19 (main, Mar 21 2024, 17:11:28)
[GCC 11.2.0] at /opt/sct_6.2/python/envs/venv_sct/bin/python
Check if data are installed.........................[OK]
Check if dipy is installed..........................[OK] (1.5.0)
Check if ivadomed is installed......................[OK] (2.9.9)
Check if matplotlib is installed....................[OK] (3.8.3)
Check if monai is installed.........................[OK] (1.3.0)
Check if nibabel is installed.......................[OK] (3.2.2)
Check if nilearn is installed.......................[OK] (0.10.2)
Check if nnunetv2 is installed......................[OK]
Check if numpy is installed.........................[OK] (1.23.5)
Check if onnxruntime is installed...................[OK] (1.17.0)
Check if pandas is installed........................[OK] (1.4.4)
Check if portalocker is installed...................[OK] (2.8.2)
Check if psutil is installed........................[OK] (5.9.8)
Check if pyqt5 (5.12.3) is installed................[OK] (5.12.3)
Check if pyqt5-sip is installed.....................[OK]
Check if pytest is installed........................[OK] (8.0.0)
Check if pytest-cov is installed....................[OK] (4.1.0)
Check if requests is installed......................[OK] (2.31.0)
Check if requirements-parser is installed...........[OK]
Check if scipy is installed.........................[OK] (1.12.0)
Check if scikit-image is installed..................[OK] (0.22.0)
Check if scikit-learn is installed..................[OK] (1.4.0)
Check if xlwt is installed..........................[OK] (1.3.0)
Check if tqdm is installed..........................[OK] (4.66.2)
Check if transforms3d is installed..................[OK] (0.4.1)
Check if urllib3 is installed.......................[OK] (2.2.0)
Check if pytest_console_scripts is installed........[OK]
Check if pyyaml is installed........................[OK] (6.0.1)
Check if voxelmorph is installed....................[OK] (0.2)
Check if wquantiles is installed....................[OK] (0.4)
Check if xlsxwriter is installed....................[OK] (3.1.9)
Check if spinalcordtoolbox is installed.............[OK]
Check ANTs compatibility with OS ...................[OK]
Check PropSeg compatibility with OS ................[OK]
Check if figure can be opened with PyQt.............[OK]
Check if figure can be opened with matplotlib.......[OK] (Using GUI backend: 'QtAgg')

Hi @Roger_Mateu,

Thank you for sharing your bug report to the forum! I really appreciate the detailed, thorough post. :slight_smile:

This would be very helpful for debugging this issue. I will DM you my Polytechnique Montreal work email address that you can send this information to, then I will start looking into this issue right away. :slight_smile:

Kind regards,
Joshua

Hi @Roger_Mateu,

Thank you for sending me your data. I am able to reproduce the issue on my own machine.

Technical details of the problem
  • The error occurs during an intermediate step of the motion correction (copy_mat_files()).

  • In this intermediate step, the script generates a MATLAB affine matrix file for every Z-axis slice and T volume. There are 12 volumes and 40 Z-axis slices, which should result in 480 affine matrices.

  • However, when checking the temporary directory where the files are stored, only 228 files are generated. So, some expected temporary files are not generated. In particular, only slices 9-27 have matrices generated for them; 0-8 and 28-39 do not.

  • The code that generates the matrix files can be found at moco_wrappermocoregister. In this function, we can see that the registration will only be performed if the “mask” file is nonzero. If I add a print statement here, we can see that this condition is triggered for slices 0-8 and slices 28-39, meaning no files will be generated. (There really should be proper logging for this!)

  • Looking at the command you used, it seems like you provided a mask file for -m. Visualizing this mask, we see:

    Ah, interesting! The Z slice actually belongs to the LR axis, as the image is in AIL/PSR orientation.

  • Looking back at the code that is supposed to generate the matrix files, I see this little TODO: “` # TODO: create affine mat file with identity, in case used by -g 2”. This is suspicious, and implies that we’re not creating affine mat files with an identity matrix, which would explain the FileNotFoundErrors.

  • If I modify the code to generate a dummy affine matrix file that matches the files that are created using scipy.io.savemat, then the motion correction proceeds without issue.

  • The modification is as follows (L725-L739 in the file spinalcordtoolbox/moco.py):

            if im_mask is not None:
                # if user specified a mask, make sure there are non-null voxels in the image before running the registration
                if np.count_nonzero(im_mask.data):
                    cmd += ['--masks', im_mask.absolutepath]
                else:
                    # Mask only contains zeros. Copying the image instead of estimating registration.
                    copy(file_src, file_out_concat, verbose=0)
-                   # TODO: create affine mat file with identity, in case used by -g 2
+                   mat_dict = {
+                       'AffineTransform_double_2_2': np.array([[1.0], [0.0], [0.0], [1.0], [0.0], [0.0]]).astype("<f8"),
+                       'fixed': np.array([[0.0], [0.0]]).astype("<f8")
+                   }
+                   scipy.io.savemat((file_mat + param.suffix_mat), mat_dict, format="4")
  • However, when I do this, I actually observe… no motion correction being performed at all? The _moco image and the input image appear to be identical.

tl;dr:

  • The input data has Z axis = LR (sagittal data).
  • Because of this, the motion correction traverses a section of code specific to the “LR” case, which contains a # TODO that was never finished. This missing logic is the direct cause of the error.
  • Completing the TODO allows motion correction to proceed without error.
  • However, I’m not sure if my fix has actually fixed the functionality, because there is no motion correction at all. If my fix is correct, then the MOCO command may need to be tweaked as well.

I will need to take a closer look at the history of this TODO (when it was added, by whom) and make sure that I fully understand the context and to make sure that I’m applying the right fix. It looks like the TODO predates the issue you cited (#2625) as well as its fix (#2634).

I would also need to better understand sagittal motion correction, seeing as it was not supported until (relatively) recently in SCT’s history, and is likely undertested compared to axial motion correction.

But, I think I have a good start to a fix for you. :slight_smile:

((@jcohenadad may be able to provide some context as well.))

Kind regards,
Joshua

quick feedback (in the middle of a meeting): I would use -g 1 for sagittal images

Ah! -g isn’t specified in the command, so I missed this, but it looks like -g is initialized to 3 by default. In that case, I suppose -g 1 is required for sagittal images?

1 Like

oops-- i’m getting an error with -g 1:

Terminal output
julien-macbook:~/Desktop/DTI $ sct_dmri_moco -i 01_ATAXIA_AMUS_01_DTI.nii -m mask_01_ATAXIA_AMUS_01_DTI_dwi_mean.nii -param metric=CC -g 1 -bvec 01_ATAXIA_AMUS_01_DTI.bvec -qc qc -qc-seg 01_ATAXIA_AMUS_01_DTI_dwi_mean_seg.nii

--
Spinal Cord Toolbox (git-master-bb479d82ea1e2076dd50343177056a61bd17e260)

sct_dmri_moco -i 01_ATAXIA_AMUS_01_DTI.nii -m mask_01_ATAXIA_AMUS_01_DTI_dwi_mean.nii -param metric=CC -g 1 -bvec 01_ATAXIA_AMUS_01_DTI.bvec -qc qc -qc-seg 01_ATAXIA_AMUS_01_DTI_dwi_mean_seg.nii
--


Input parameters:
  Input file ............ 01_ATAXIA_AMUS_01_DTI.nii
  Group size ............ 1
Creating temporary folder (/var/folders/5f/6n99hhyj5_g5cv_1bbx1q7cr0000gn/T/sct_2024-06-04_16-02-57_moco-wrapper_g82ky7ki)

Copying input data to tmp folder and convert to nii...

Get dimensions of data...
  144 x 192 x 40

Data orientation: AIL
  Treated as sagittal

Set suffix of transformation file name, which depends on the orientation:
Orientation is sagittal, suffix is '0GenericAffine.mat'. The image is split across the R-L direction, and the estimated transformation is a 2D affine transfo.

Identify b=0 and DWI images...
  WARNING: bvecs file is 3xn instead of nx3. Consider using sct_dmri_transpose_bvecs.
  Transpose bvecs...
  Number of b=0: 1 [0]
  Number of DWI: 12 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Split along T dimension...

Merge and average b=0 data...
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:   0%|                             | 0/12 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:   8%|█▊                   | 1/12 [00:00<00:01,  5.88iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  17%|███▌                 | 2/12 [00:00<00:01,  6.29iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  25%|█████▎               | 3/12 [00:00<00:01,  6.58iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  33%|███████              | 4/12 [00:00<00:01,  6.62iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  42%|████████▊            | 5/12 [00:00<00:01,  6.67iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  50%|██████████▌          | 6/12 [00:00<00:00,  6.74iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  58%|████████████▎        | 7/12 [00:01<00:00,  6.74iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  67%|██████████████       | 8/12 [00:01<00:00,  6.59iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  75%|███████████████▊     | 9/12 [00:01<00:00,  6.22iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  83%|████████████████▋   | 10/12 [00:01<00:00,  5.96iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  92%|██████████████████▎ | 11/12 [00:01<00:00,  5.89iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups: 100%|████████████████████| 12/12 [00:01<00:00,  6.28iter/s]

Merge across groups...

-------------------------------------------------------------------------------
  Estimating motion on b=0 images...
-------------------------------------------------------------------------------

Input parameters:
  Input file ............ b0.nii
  Reference file ........ data_T0000.nii.gz
  Polynomial degree ..... 2
  Smoothing kernel ...... 1
  Gradient step ......... 1
  Metric ................ CC
  Sampling .............. None
  Todo .................. estimate_and_apply
  Mask  ................. mask.nii
  Output mat folder ..... mat_b0groups

Data dimensions:
  144 x 192 x 40 x 1

Copy file_target to a temporary file...

Register. Loop across Z (note: there is only one Z if orientation is axial)
Z=0/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=0/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 17.33iter/s]
Z=1/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=1/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 17.96iter/s]
Z=2/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=2/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.07iter/s]
Z=3/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=3/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.32iter/s]
Z=4/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=4/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.11iter/s]
Z=5/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=5/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.39iter/s]
Z=6/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=6/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 13.25iter/s]
Z=7/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=7/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.07iter/s]
Z=8/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=8/39: 100%|███████████████████████████████████| 1/1 [00:00<00:00, 18.55iter/s]
Z=9/39:   0%|                                           | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=9/39: 100%|███████████████████████████████████| 1/1 [00:01<00:00,  1.04s/iter]
Z=10/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=10/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.04iter/s]
Z=11/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=11/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.04iter/s]
Z=12/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=12/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.08iter/s]
Z=13/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=13/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.01iter/s]
Z=14/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=14/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.07iter/s]
Z=15/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=15/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.04iter/s]
Z=16/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=16/39: 100%|██████████████████████████████████| 1/1 [00:01<00:00,  1.04s/iter]
Z=17/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=17/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.07iter/s]
Z=18/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=18/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.06iter/s]
Z=19/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=19/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.09iter/s]
Z=20/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=20/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.07iter/s]
Z=21/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=21/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.06iter/s]
Z=22/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=22/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.08iter/s]
Z=23/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=23/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.06iter/s]
Z=24/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=24/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.07iter/s]
Z=25/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=25/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.07iter/s]
Z=26/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=26/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.03iter/s]
Z=27/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=27/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00,  1.02iter/s]
Z=28/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=28/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.75iter/s]
Z=29/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=29/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 11.39iter/s]
Z=30/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=30/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.61iter/s]
Z=31/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=31/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.04iter/s]
Z=32/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=32/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.26iter/s]
Z=33/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=33/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.16iter/s]
Z=34/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=34/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.72iter/s]
Z=35/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=35/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.48iter/s]
Z=36/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=36/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.61iter/s]
Z=37/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=37/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 18.90iter/s]
Z=38/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=38/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 13.32iter/s]
Z=39/39:   0%|                                          | 0/1 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Z=39/39: 100%|██████████████████████████████████| 1/1 [00:00<00:00, 13.25iter/s]
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.

-------------------------------------------------------------------------------
  Estimating motion across groups...
-------------------------------------------------------------------------------

Input parameters:
  Input file ............ datasub-groups.nii
  Reference file ........ datasub_0_mean.nii.gz
  Polynomial degree ..... 2
  Smoothing kernel ...... 1
  Gradient step ......... 1
  Metric ................ CC
  Sampling .............. None
  Todo .................. estimate_and_apply
  Mask  ................. mask.nii
  Output mat folder ..... mat_groups

Data dimensions:
  144 x 192 x 40 x 12

Copy file_target to a temporary file...

Register. Loop across Z (note: there is only one Z if orientation is axial)
Z=0/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.27iter/s]
Z=1/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.71iter/s]
Z=2/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.11iter/s]
Z=3/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.93iter/s]
Z=4/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.71iter/s]
Z=5/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.22iter/s]
Z=6/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 19.57iter/s]
Z=7/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.36iter/s]
Z=8/39: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 18.88iter/s]
Z=9/39: 100%|█████████████████████████████████| 12/12 [00:17<00:00,  1.47s/iter]
Z=10/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.25s/iter]
Z=11/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.33s/iter]
Z=12/39: 100%|████████████████████████████████| 12/12 [00:16<00:00,  1.37s/iter]
Z=13/39: 100%|████████████████████████████████| 12/12 [00:14<00:00,  1.25s/iter]
Z=14/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.30s/iter]
Z=15/39: 100%|████████████████████████████████| 12/12 [00:13<00:00,  1.14s/iter]
Z=16/39: 100%|████████████████████████████████| 12/12 [00:16<00:00,  1.36s/iter]
Z=17/39: 100%|████████████████████████████████| 12/12 [00:16<00:00,  1.38s/iter]
Z=18/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.30s/iter]
Z=19/39: 100%|████████████████████████████████| 12/12 [00:14<00:00,  1.18s/iter]
Z=20/39: 100%|████████████████████████████████| 12/12 [00:14<00:00,  1.25s/iter]
Z=21/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.31s/iter]
Z=22/39: 100%|████████████████████████████████| 12/12 [00:16<00:00,  1.41s/iter]
Z=23/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.25s/iter]
Z=24/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.30s/iter]
Z=25/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.31s/iter]
Z=26/39: 100%|████████████████████████████████| 12/12 [00:14<00:00,  1.22s/iter]
Z=27/39: 100%|████████████████████████████████| 12/12 [00:15<00:00,  1.32s/iter]
Z=28/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 17.78iter/s]
Z=29/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 18.57iter/s]
Z=30/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 17.83iter/s]
Z=31/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 18.37iter/s]
Z=32/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 17.77iter/s]
Z=33/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 19.17iter/s]
Z=34/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 18.32iter/s]
Z=35/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 18.77iter/s]
Z=36/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 16.09iter/s]
Z=37/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 19.10iter/s]
Z=38/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 17.83iter/s]
Z=39/39: 100%|████████████████████████████████| 12/12 [00:00<00:00, 14.53iter/s]
Traceback (most recent call last):
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 232, in <module>
    main(sys.argv[1:])
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 217, in main
    fname_output_image = moco_wrapper(param)
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/moco.py", line 364, in moco_wrapper
    copy_mat_files(nt, file_mat_datasub, index_moco, mat_final, param)
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/moco.py", line 124, in copy_mat_files
    copyfile(fsrc, fdest)
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'mat_groups/mat.Z0000T00000GenericAffine.mat'

Yep, that’s the same error that I think I fixed with my modification proposed in Sct_dmri_moco [Errno 2] 0GenericAffine SCT v6.2 - #3 by joshuacwnewton. (Replacing the #TODO with affine matrix creation.)

ok, i had a look at the data shared by @Roger_Mateu – the main issue with the data is eddy current distortions, not subject motion. Eddy current distortions can be tackled using 3D methods such as eddy or topup. Slicewise moco should not be used in this case.

regardless, there is bug we need to fix :sweat_smile:

1 Like

Thank you for your quick feedback!

I think that probably the -g 3 command was previously launched in almostthesame code, modified due to “For sagittal data group_size should be one for more robustness. Forcing group_size=1.” message without the -g 1 command, and I avoided it. My apologies for that. I assumed that this command would have no effect on the error message because it’s a fixed value.

1 Like

I assumed that this command would have no effect on the error message because it’s a fixed value.

Indeed. Good catch