Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guess ITK-type with extension on load: .tfm, .mat, .h5 #87

Closed
oesteban opened this issue Mar 27, 2020 · 1 comment · Fixed by #160
Closed

Guess ITK-type with extension on load: .tfm, .mat, .h5 #87

oesteban opened this issue Mar 27, 2020 · 1 comment · Fixed by #160
Assignees
Milestone

Comments

@oesteban
Copy link
Collaborator

Permit calling load without fmt argument and still use the right loader.

@oesteban oesteban added this to the 20.0.0rc2 milestone Mar 27, 2020
@oesteban oesteban self-assigned this Mar 27, 2020
@effigies
Copy link
Member

I think .mat is also common for FSL and SPM affines, so I would have a look at:

https://github.com/nipy/nibabel/blob/65d5fc61545f55a50a45a07fbbaeb99c2dbe6bbb/nibabel/loadsave.py#L48-L53

Each class can provide a method:

def path_maybe_image(cls, fname, sniff=None):
    if sniff is None or len(sniff) < cls.sniff_size:
        with open(fname, 'rb') as fobj:
            sniff = fobj.read(cls.sniff_size)
    is_valid = ... # some check
    return is_valid, sniff

It defines a sniff_size class variable and some criterion to determine whether it's valid.

@oesteban oesteban modified the milestones: 20.0.0rc4, CZI month 5 Jun 18, 2021
oesteban added a commit that referenced this issue Mar 1, 2022
EAFP implementation of loading linear transforms without specifying the
format of the file.

Resolves: #86.
Resolves: #87.
Resolves: #107.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants