Пример #1
0
    def test_glob_ephys(self):
        def dict_equals(d1, d2):
            return all([x in d1 for x in d2]) and all([x in d2 for x in d1])

        ef3b = spikeglx.glob_ephys_files(self.dir3b)
        ef3a = spikeglx.glob_ephys_files(self.dir3a)
        ef3b_ch = spikeglx.glob_ephys_files(self.dir3b, ext='ch')
        # test glob
        self.assertTrue(dict_equals(self.dict3a, ef3a))
        self.assertTrue(dict_equals(self.dict3b, ef3b))
        self.assertTrue(dict_equals(self.dict3b_ch, ef3b_ch))
        # test the version from glob
        self.assertTrue(
            spikeglx.get_neuropixel_version_from_files(ef3a) == '3A')
        self.assertTrue(
            spikeglx.get_neuropixel_version_from_files(ef3b) == '3B')
        # test the version from paths
        self.assertTrue(
            spikeglx.get_neuropixel_version_from_folder(self.dir3a) == '3A')
        self.assertTrue(
            spikeglx.get_neuropixel_version_from_folder(self.dir3b) == '3B')
        self.dir3b.joinpath('imec1',
                            'sync_testing_g0_t0.imec1.ap.bin').unlink()
        self.assertEqual(
            spikeglx.glob_ephys_files(self.dir3b.joinpath('imec1')), [])
Пример #2
0
def sync(ses_path, **kwargs):
    """
    Wrapper for sync_probes.version3A and sync_probes.version3B that automatically determines
    the version
    :param ses_path:
    :return: bool True on a a successful sync
    """
    version = spikeglx.get_neuropixel_version_from_folder(ses_path)
    if version == '3A':
        return version3A(ses_path, **kwargs)
    elif version == '3B':
        return version3B(ses_path, **kwargs)
Пример #3
0
def create_alyx_probe_insertions(session_path: str,
                                 force: bool = False,
                                 one: object = None,
                                 model: str = None,
                                 labels: list = None):
    if one is None:
        one = ONE()
    if is_uuid_string(session_path):
        eid = session_path
    else:
        eid = one.eid_from_path(session_path)
    if eid is None:
        print(
            'Session not found on Alyx: please create session before creating insertions'
        )
    if model is None:
        probe_model = spikeglx.get_neuropixel_version_from_folder(session_path)
        pmodel = '3B2' if probe_model == '3B' else probe_model
    else:
        pmodel = model
    raw_ephys_data_path = Path(session_path) / 'raw_ephys_data'
    if labels is None:
        probe_labels = [
            x.name for x in Path(raw_ephys_data_path).glob('*')
            if x.is_dir() and ('00' in x.name or '01' in x.name)
        ]
    else:
        probe_labels = labels
    # create the dictionary
    for plabel in probe_labels:
        insdict = {'session': eid, 'name': plabel, 'model': pmodel}
        # search for the corresponding insertion in Alyx
        alyx_insertion = one.alyx.rest('insertions',
                                       'list',
                                       session=insdict['session'],
                                       name=insdict['name'])
        # if it doesn't exist, create it
        if len(alyx_insertion) == 0:
            alyx_insertion = one.alyx.rest('insertions',
                                           'create',
                                           data=insdict)
        else:
            iid = alyx_insertion[0]['id']
            if force:
                alyx_insertion = one.alyx.rest('insertions',
                                               'update',
                                               id=iid,
                                               data=insdict)
            else:
                alyx_insertion = alyx_insertion[0]
Пример #4
0
def create_alyx_probe_insertions(
    session_path: str,
    force: bool = False,
    one: object = None,
    model: str = None,
    labels: list = None,
):
    if one is None:
        one = ONE()
    if is_uuid_string(session_path):
        eid = session_path
    else:
        eid = one.eid_from_path(session_path)
    if eid is None:
        print(
            "Session not found on Alyx: please create session before creating insertions"
        )
    if model is None:
        probe_model = spikeglx.get_neuropixel_version_from_folder(session_path)
        pmodel = "3B2" if probe_model == "3B" else probe_model
    else:
        pmodel = model
    raw_ephys_data_path = Path(session_path) / "raw_ephys_data"
    if labels is None:
        probe_labels = [
            x.name for x in Path(raw_ephys_data_path).glob("*")
            if x.is_dir() and ("00" in x.name or "01" in x.name)
        ]
    else:
        probe_labels = labels

    # create the qc fields in the json field
    qc_dict = {}
    qc_dict.update({"qc": "NOT_SET"})
    qc_dict.update({"extended_qc": {}})

    # create the dictionary
    for plabel in probe_labels:
        insdict = {
            "session": eid,
            "name": plabel,
            "model": pmodel,
            "json": qc_dict
        }
        # search for the corresponding insertion in Alyx
        alyx_insertion = one.alyx.rest("insertions",
                                       "list",
                                       session=insdict["session"],
                                       name=insdict["name"])
        # if it doesn't exist, create it
        if len(alyx_insertion) == 0:
            alyx_insertion = one.alyx.rest("insertions",
                                           "create",
                                           data=insdict)
        else:
            iid = alyx_insertion[0]["id"]
            if force:
                alyx_insertion = one.alyx.rest("insertions",
                                               "update",
                                               id=iid,
                                               data=insdict)
            else:
                alyx_insertion = alyx_insertion[0]