Skip to content

Commit

Permalink
fix for checking file with different extensions in tf_2dunet
Browse files Browse the repository at this point in the history
Signed-off-by: yes <[email protected]>
  • Loading branch information
tanwarsh committed Nov 29, 2024
1 parent a26bdb2 commit 95d7a68
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions openfl-workspace/tf_2dunet/src/nii_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,29 @@ def nii_reader(brain_path, task, channels_last=True,

# check that all appropriate files are present
file_root = brain_path.split('/')[-1] + '_'
extension = '.nii.gz'
# check for all possible extensions
extensions = ['.nii.gz', '.nii']

# record files needed
# needed mask files are currntly independent of task
need_files_oneof = list_files(file_root, extension, msk_names)
if normalization != 'modes_together':
need_files_all = list_files(file_root, extension, task_to_img_modes[task])
else:
need_files_all = list_files(file_root, extension, img_modes)

correct_files = np.all([
(reqd in files)
for reqd in need_files_all
]) and np.sum([
(reqd in files)
for reqd in need_files_oneof
]) == 1

need_files_oneof = None
need_files_all = None
for extension in extensions:
need_files_oneof = list_files(file_root, extension, msk_names)
if normalization != 'modes_together':
need_files_all = list_files(file_root, extension, task_to_img_modes[task])
else:
need_files_all = list_files(file_root, extension, img_modes)

correct_files = np.all([
(reqd in files)
for reqd in need_files_all
]) and np.sum([
(reqd in files)
for reqd in need_files_oneof
]) == 1
if correct_files:
break
if not correct_files:
return None, None

Expand Down

0 comments on commit 95d7a68

Please sign in to comment.