Пример #1
0
def eid2path(eid: Union[str, Iter], one=None, offline: bool = False) -> Union[Path, List]:
    """
    Returns a local path from an eid, regardless of whether the path exists locally
    :param eid: An experiment uuid
    :param one: An instance of ONE
    :param offline: If True, do not connect to database (not implemented)
    :return: a Path instance

    Examples:
    >>> base = 'https://test.alyx.internationalbrainlab.org'
    >>> one = ONE(username='******', password='******', base_url=base)
    Connected to...
    >>> eid = '4e0b3320-47b7-416e-b842-c34dc9004cf8'
    >>> eid2path(eid, one=one)
    WindowsPath('E:/FlatIron/zadorlab/Subjects/flowers/2018-07-13/001')
    >>> eid2path([eid, '7dc3c44b-225f-4083-be3d-07b8562885f4'], one=one)
    [WindowsPath('E:/FlatIron/zadorlab/Subjects/flowers/2018-07-13/001'),
     WindowsPath('E:/FlatIron/cortexlab/Subjects/KS005/2019-04-11/001')]
    """
    if not one:
        one = ONE()
    if offline:
        raise NotImplementedError
        # path = one.path_from_eid(eid, offline=True)
    else:
        d = one.get_details(eid)
        path = d.get('local_path')
        if not path:
            root = Path(one._get_cache_dir(None)) / d['lab'] / 'Subjects'
            path = root / d['subject'] / d['start_time'][:10] / ('%03d' % d['number'])
    return path
Пример #2
0
def ref2path(ref: Union[str, Mapping, Iter], one=None, offline: bool = False) -> Union[Path, List]:
    """
    Convert one or more experiment references to session path(s)
    :param ref: One or more objects with keys ('subject', 'date', 'sequence'), or strings with the
    form yyyy-mm-dd_n_subject
    :param one: An instance of ONE
    :param offline: Return path without connecting to database (unimplemented)
    :return: a Path object for the experiment session

    Examples:
    >>> base = 'https://test.alyx.internationalbrainlab.org'
    >>> one = ONE(username='******', password='******', base_url=base)
    Connected to...
    >>> ref = {'subject': 'flowers', 'date': datetime(2018, 7, 13).date(), 'sequence': 1}
    >>> ref2path(ref, one=one)
    WindowsPath('E:/FlatIron/zadorlab/Subjects/flowers/2018-07-13/001')
    >>> ref2path(['2018-07-13_1_flowers', '2019-04-11_1_KS005'], one=one)
    [WindowsPath('E:/FlatIron/zadorlab/Subjects/flowers/2018-07-13/001'),
     WindowsPath('E:/FlatIron/cortexlab/Subjects/KS005/2019-04-11/001')]
    """
    if not one:
        one = ONE()
    if offline:
        raise NotImplementedError  # Requires lab name :(
        # root = Path(one._get_cache_dir(None))
        # path = root / ref.subject / str(ref.date) / ('%03d' % ref.sequence)
    else:
        ref = ref2dict(ref, parse=False)
        eid, (d,) = one.search(
            subjects=ref['subject'],
            date_range=(str(ref['date']), str(ref['date'])),
            number=ref['sequence'],
            details=True)
        path = d.get('local_path')
        if not path:
            root = Path(one._get_cache_dir(None)) / 'Subjects' / d['lab']
            return root / d['subject'] / d['start_time'][:10] / ('%03d' % d['number'])
        else:
            return Path(path)