Skip to content

Commit

Permalink
Fix output name for .nii.gz inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Mar 31, 2022
1 parent b07cf7a commit f392a8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
File renamed without changes
File renamed without changes.
13 changes: 12 additions & 1 deletion mri_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,21 @@ def multi_mapper(inputdir: Path, outputdir: Path, file_extensions: str) -> Itera
for file_extension in file_extensions.split(','):
yield from PathMapper(
inputdir, outputdir,
glob=f'**/*{file_extension}', suffix='.out', fail_if_empty=False
glob=f'**/*{file_extension}',
name_mapper=_gz_aware_placeholder_mapper,
fail_if_empty=False
)


def _gz_aware_placeholder_mapper(input_file: Path, output_dir: Path) -> Path:
filename = str(input_file.name)
if filename.endswith('.gz'):
filename = filename[:-3] + '_gz'
if '.' not in filename:
raise ValueError(f'Unrecognized file extension in: {input_file}')
return (output_dir / filename).with_suffix('.out')


def save_as(img, output: Path, num_voxels: int, total_vol: float, units: str) -> None:
if output.name.endswith('.txt'):
with output.open('w') as f:
Expand Down

0 comments on commit f392a8a

Please sign in to comment.