def IsSessionDir(src: Union[Text, PathLike]) -> bool:
    """
    Returns True if ``src`` points to a session-level directory.

    """
    return basename(src) == find_entity(src, 'ses') \
        if isdir(src) else False
def GetEvents(src: Union[Text, PathLike],
              **kwargs) -> Union[Text, PathLike, Series]:
    """
    Returns the functional scan's associated "events" file.

    Args:
        src: Text or PathLike
            Path of a nifti scan file (generally fMRI).

        kwargs: Dict
            Keyword arguments to override the default options.
            By default, the returned path will match ``src``
            and the following keywords:
                {'bids_suffix': 'events', 'extension': '.tsv'}.
            Any BIDS entity string (short name) is valid.

    Notes:
        Changing the keyword values of ``bids_suffix`` and/or
        ``extension`` SHOULD cause failure to retrieve
        the behavioural file in a BIDS-valid dataset.
    """
    kwargs = kwargs if kwargs else {}
    _task = find_entity(src, 'task', keep_key=False)
    keywords = dict(bids_suffix='events', extension='.tsv', task=_task)
    keywords = {**keywords, **kwargs}

    try:

        assert all((bool(_task), _task not in {'task-rest', 'rest'}))
        events_path = MatchComponents(dirname(src), src=src, **keywords)
        events_path = next(filter(IsEvent, events_path))
        return read_csv(events_path, sep='\t', **kwargs)
    except NIFTI_ERRORS[:-1]:
        return Series([], dtype='string')
Exemple #3
0
    def find_sub_id(src: Union[Text, PathLike]) -> Text:
        """
        Returns a subject's BIDS identifier (``sub-`` prefix included).

        Same output as ```self.sub``` on an
        instantiated ``BIDSPath`` object.
        """
        return find_entity(src, 'sub')
Exemple #4
0
 def find_entity(src: Union[Text, PathLike],
                 entity: Text,
                 keep_key: bool = True) -> Text:
     """{0}\n"""
     return find_entity(src, entity, keep_key)