Utilities to find files from NIPY data packages
Bomber(name, msg) | Class to raise an informative error when used |
BomberError | Error when trying to access Bomber instance |
DataError | |
Datasource(base_path) | Simple class to add base path to relative path |
VersionedDatasource(base_path[, config_filename]) | Datasource with version information in config file |
datasource_or_bomber(pkg_def, **options) | Return a viable datasource or a Bomber |
find_data_dir(root_dirs, *names) | Find relative path given path prefixes to search |
get_data_path() | Return specified or guessed locations of NIPY data files |
make_datasource(pkg_def, **kwargs) | Return datasource defined by pkg_def as found in data_path |
Bases: nibabel.data.DataError, exceptions.AttributeError
Error when trying to access Bomber instance
Should be instance of AttributeError to allow Python 3 inspect to do various hasattr checks without raising an error
x.__init__(...) initializes x; see help(type(x)) for signature
Bases: object
Simple class to add base path to relative path
Initialize datasource
Parameters: | base_path : str
|
---|
Examples
>>> from os.path import join as pjoin
>>> repo = Datasource(pjoin('a', 'path'))
>>> fname = repo.get_filename('somedir', 'afile.txt')
>>> fname == pjoin('a', 'path', 'somedir', 'afile.txt')
True
Initialize datasource
Parameters: | base_path : str
|
---|
Examples
>>> from os.path import join as pjoin
>>> repo = Datasource(pjoin('a', 'path'))
>>> fname = repo.get_filename('somedir', 'afile.txt')
>>> fname == pjoin('a', 'path', 'somedir', 'afile.txt')
True
Prepend base path to *path_parts
We make no check whether the returned path exists.
Parameters: | *path_parts : sequence of strings |
---|---|
Returns: | fname : str
|
Recursively list the files in the data source directory.
Parameters: | relative: bool, optional :
|
---|---|
Returns: | file_list: list of strings :
|
Bases: nibabel.data.Datasource
Datasource with version information in config file
Initialize versioned datasource
We assume that there is a configuration file with version information in datasource directory tree.
The configuration file contains an entry like:
[DEFAULT]
version = 0.3
The version should have at least a major and a minor version number in the form above.
Parameters: | base_path : str
config_filaname : None or str
|
---|
Initialize versioned datasource
We assume that there is a configuration file with version information in datasource directory tree.
The configuration file contains an entry like:
[DEFAULT]
version = 0.3
The version should have at least a major and a minor version number in the form above.
Parameters: | base_path : str
config_filaname : None or str
|
---|
Return a viable datasource or a Bomber
This is to allow module level creation of datasource objects. We create the objects, so that, if the data exist, and are the correct version, the objects are valid datasources, otherwise, they raise an error on access, warning about the lack of data or the version numbers.
The parameters are as for make_datasource in this module.
Parameters: | pkg_def : dict
data_path : sequence of strings or None, optional |
---|---|
Returns: | ds : datasource or Bomber instance |
Find relative path given path prefixes to search
We raise a DataError if we can’t find the relative path
Parameters: | root_dirs : sequence of strings
*names : sequence of strings
|
---|---|
Returns: | data_dir : str
|
Return specified or guessed locations of NIPY data files
The algorithm is to return paths, extracted from strings, where strings are found in the following order:
Therefore, any paths found in NIPY_DATA_PATH will be searched before paths found in the user directory config.ini
Parameters: | None : |
---|---|
Returns: | paths : sequence of paths |
Notes
We have to add /usr/local/share/nipy if sys.prefix is /usr, because Debian has patched distutils in Python 2.6 to do default distutils installs there:
Examples
>>> pth = get_data_path()
Return datasource defined by pkg_def as found in data_path
data_path is the only allowed keyword argument.
pkg_def is a dictionary with at least one key - ‘relpath’. ‘relpath’ is a relative path with unix forward slash separators.
The relative path to the data is found with:
names = pkg_def['name'].split('/')
rel_path = os.path.join(names)
We search for this relative path in the list of paths given by data_path. By default data_path is given by get_data_path() in this module.
If we can’t find the relative path, raise a DataError
Parameters: | pkg_def : dict
data_path : sequence of strings or None, optional
|
---|---|
Returns: | datasource : VersionedDatasource
|