Deepreg: Nifti data as .nii (instead of .nii.gz) is not accepted

Created on 25 Jul 2020  路  8Comments  路  Source: DeepRegNet/DeepReg

Issue description

Nifti input data as .nii is not accepted, it only accepts .nii.gz.

Type of Issue

Please delete options that are not relevant.

  • [X] Bug report
  • [x] New feature request
  • [x] Documentation update
  • [x] Test request
  • [ ] Linting request

For bug report or feature request, steps to reproduce the issue, including (but not limited to):

  1. OS
    Ubuntu
  2. Environment to reproduce
  3. What commands run / sample script used:

What's the expected result?

Accept .nii data as input

What's the actual result?

Additional details / screenshot

-

bug

Most helpful comment

no after the discussion with @s-sd he will focus on the demo first, i will do this

All 8 comments

This issue will need to extend nifti_loader.py, we now have the following code

arr = np.asarray(nib.load(filepath).dataobj, dtype=np.float32)

So we will need a helper function to load the data depending on the suffix of the path.

if file_path.endswith("nii"):
    # load nii
elif file_path.endswith("nii.gz"):
    # load nii.gz
else:
    # raise error and provide the full path for debugging

The test is also required to test all cases including failures, so you might need at least one .nii file in the repo

@YipengHu

nib.load

it should be tested fairly easily, but i thought ni.load() reads both?
see: https://nipy.org/nibabel/reference/nibabel.html

@YipengHu @mathpluscode I suspect the problem is in lines 17-19 of the nifti_loader.py:

        self.file_paths = get_sorted_filenames_in_dir(
            dir_path=os.path.join(dir_path, name), suffix="nii.gz"
        )

Only files with suffix "nii.gz" are being added to self.file_paths

@YipengHu @mathpluscode I suspect the problem is in lines 17-19 of the nifti_loader.py:

        self.file_paths = get_sorted_filenames_in_dir(
            dir_path=os.path.join(dir_path, name), suffix="nii.gz"
        )

Only files with suffix "nii.gz" are being added to self.file_paths

I might be it. Will test this out later. But if you are up for it, fix this I will review.

@YipengHu, I'll try to make the change and if it works I'll create a pull request

reopen this issue as mentioned in #240

@mathpluscode are you assigning yourself to this, or you want @s-sd to add test et al?

no after the discussion with @s-sd he will focus on the demo first, i will do this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YipengHu picture YipengHu  路  6Comments

s-sd picture s-sd  路  5Comments

NMontanaBrown picture NMontanaBrown  路  5Comments

mathpluscode picture mathpluscode  路  6Comments

zacbaum picture zacbaum  路  3Comments