|
21 | 21 | import numpy as np
|
22 | 22 |
|
23 | 23 | from .arrayproxy import ArrayProxy
|
| 24 | +from .fileholders import FileHolder |
| 25 | +from .filename_parser import (types_filenames, TypesFilenamesError) |
24 | 26 | from .fileslice import strided_scalar
|
25 | 27 | from .keywordonly import kw_only_meth
|
26 | 28 | from .spatialimages import (
|
@@ -527,21 +529,27 @@ def filespec_to_file_map(klass, filespec):
|
527 | 529 | If `filespec` is not recognizable as being a filename for this
|
528 | 530 | image type.
|
529 | 531 | """
|
530 |
| - file_map = super(AFNIImage, klass).filespec_to_file_map(filespec) |
531 |
| - # only BRIK can be compressed; remove potential compression suffixes from HEAD |
532 |
| - head_fname = file_map['header'].filename |
533 |
| - if not os.path.exists(head_fname): |
534 |
| - for ext in klass._compressed_suffixes: |
535 |
| - head_fname = head_fname[:-len(ext)] if head_fname.endswith(ext) else head_fname |
536 |
| - file_map['header'].filename = head_fname |
537 |
| - # if HEAD is read in and BRIK is compressed, function won't detect the |
538 |
| - # compressed format; check for these cases |
539 |
| - if not os.path.exists(file_map['image'].filename): |
540 |
| - for ext in klass._compressed_suffixes: |
541 |
| - im_ext = file_map['image'].filename + ext |
542 |
| - if os.path.exists(im_ext): |
543 |
| - file_map['image'].filename = im_ext |
544 |
| - break |
| 532 | + # copied from filebasedimages.py |
| 533 | + try: |
| 534 | + filenames = types_filenames( |
| 535 | + filespec, klass.files_types, |
| 536 | + trailing_suffixes=klass._compressed_suffixes) |
| 537 | + except TypesFilenamesError: |
| 538 | + raise ImageFileError( |
| 539 | + 'Filespec "{0}" does not look right for class {1}'.format( |
| 540 | + filespec, klass)) |
| 541 | + file_map = {} |
| 542 | + # check for AFNI-specific BRIK/HEAD compression idiosyncracies |
| 543 | + for key, fname in filenames.items(): |
| 544 | + if key == 'header' and not os.path.exists(fname): |
| 545 | + for ext in klass._compressed_suffixes: |
| 546 | + fname = fname[:-len(ext)] if fname.endswith(ext) else fname |
| 547 | + elif key == 'image' and not os.path.exists(fname): |
| 548 | + for ext in klass._compressed_suffixes: |
| 549 | + if os.path.exists(fname + ext): |
| 550 | + fname += ext |
| 551 | + break |
| 552 | + file_map[key] = FileHolder(filename=fname) |
545 | 553 | return file_map
|
546 | 554 |
|
547 | 555 | load = from_filename
|
|
0 commit comments