bids.layout.BIDSFile¶
-
class
BIDSFile
(filename)[source]¶ Represents a single file or directory in a BIDS dataset.
- Parameters
filename (str) – The path to the corresponding file.
- Attributes
- class_
- dirname
- filename
- is_dir
- path
- tags
Methods
copy
(self, path_patterns[, symbolic_link, …])Copy the contents of a file to a new location.
get_associations
(self[, kind, include_parents])Get associated files, optionally limiting by association kind.
get_entities
(self[, metadata, values])Return entity information for the current file.
get_metadata
(self)Return all metadata associated with the current file.
-
__init__
(self, filename)¶
Methods
__init__
(self, filename)copy
(self, path_patterns[, symbolic_link, …])Copy the contents of a file to a new location.
get_associations
(self[, kind, include_parents])Get associated files, optionally limiting by association kind.
get_entities
(self[, metadata, values])Return entity information for the current file.
get_metadata
(self)Return all metadata associated with the current file.
Attributes
class_
dirname
entities
filename
is_dir
metadata
path
tags
-
copy
(self, path_patterns, symbolic_link=False, root=None, conflicts='fail')[source]¶ Copy the contents of a file to a new location.
- Parameters
path_patterns (list) – List of patterns use to construct the new filename. See
build_path
documentation for details.symbolic_link (bool) – If True, use a symbolic link to point to the existing file. If False, creates a new file.
root (str) – Optional path to prepend to the constructed filename.
conflicts (str) –
Defines the desired action when the output path already exists. Must be one of:
’fail’: raises an exception ‘skip’ does nothing ‘overwrite’: overwrites the existing file ‘append’: adds a suffix to each file copy, starting with 1
-
get_associations
(self, kind=None, include_parents=False)[source]¶ Get associated files, optionally limiting by association kind.
- Parameters
kind (str) – The kind of association to return (e.g., “Child”). By default, all associations are returned.
include_parents (bool) – If True, files related through inheritance are included in the returned list. If False, only directly associated files are returned. For example, a file’s JSON sidecar will always be returned, but other JSON files from which the sidecar inherits will only be returned if include_parents=True.
- Returns
A list of BIDSFile instances.
- Return type
list
-
get_entities
(self, metadata=False, values='tags')[source]¶ Return entity information for the current file.
- Parameters
metadata (bool or None) – If False (default), only entities defined for filenames (and not those found in the JSON sidecar) are returned. If True, only entities found in metadata files (and not defined for filenames) are returned. If None, all available entities are returned.
values (str) –
The kind of object to return in the dict’s values. Must be one of:
’tags’: Returns only the tagged value–e.g., if the key
is “subject”, the value might be “01”. * ‘objects’: Returns the corresponding Entity instance.
- Returns
A dict, where keys are entity names and values are Entity instances.
- Return type
dict