|
4 | 4 | import os
|
5 | 5 | import os.path as op
|
6 | 6 | import logging
|
| 7 | +import numpy as np |
7 | 8 | import re
|
8 | 9 | from collections import OrderedDict
|
9 | 10 | from datetime import datetime
|
@@ -612,8 +613,10 @@ def get_key_info_for_fmap_assignment(json_file, matching_parameter='ImagingVolum
|
612 | 613 | elif matching_parameter == 'ImagingVolume':
|
613 | 614 | from nibabel import load as nb_load
|
614 | 615 | nifti_file = glob(remove_suffix(json_file, '.json') + '.nii*')
|
| 616 | + assert len(nifti_file) == 1 |
| 617 | + nifti_file = nifti_file[0] |
615 | 618 | nifti_header = nb_load(nifti_file).header
|
616 |
| - key_info = [nifti_header.affine, nifti_header.dim[1:3]] |
| 619 | + key_info = [nifti_header.get_best_affine(), nifti_header.get_data_shape()[:3]] |
617 | 620 | elif matching_parameter == 'AcquisitionLabel':
|
618 | 621 | # Check the acq label for the fmap and the modality for others:
|
619 | 622 | modality = op.basename(op.dirname(json_file))
|
@@ -677,10 +680,9 @@ def find_compatible_fmaps_for_run(json_file, fmap_groups, matching_parameters=['
|
677 | 680 | compatible = False
|
678 | 681 | for param in matching_parameters:
|
679 | 682 | fm_info = get_key_info_for_fmap_assignment(fm_group[0], param)
|
680 |
| - if json_info[param] == fm_info: |
681 |
| - compatible = True |
682 |
| - else: |
683 |
| - compatible = False |
| 683 | + # allow for tiny differences between the affines etc |
| 684 | + compatible = all(np.allclose(x, y) for x, y in zip(json_info[param], fm_info)) |
| 685 | + if not compatible: |
684 | 686 | continue # don't bother checking more params
|
685 | 687 | if compatible:
|
686 | 688 | compatible_fmap_groups[fm_key] = fm_group
|
|
0 commit comments