Ejemplo n.º 1
0
def test_bidstree_to_bidstree():
    # Test writing one BIDSTree object to a new empty BIDSTree location.
    with tempfile.TemporaryDirectory() as tmp:
        dest_bf = BIDSTree(tmp, False)
        src_bt = BIDSTree(TESTPATH2)
        dest_bf.add(src_bt)
        assert len(dest_bf.projects) == 1
        assert dest_bf.project('test1').subject('1').subject_data['age'] == 2.0
Ejemplo n.º 2
0
 def _transfer(self):
     """Transfer all the files in each of the sources to the destination."""
     copy_func = BIDSCopy(overwrite=self.force_override.get(),
                          verify=self.verify.get(),
                          file_name_tracker=self.curr_file,
                          file_num_tracker=self.transferred_count,
                          file_prog_tracker=self.curr_file_progress)
     self.curr_file.set('Mapping destination BIDS structure...')
     dst_folder = BIDSTree(self.dst)
     for src in self.srcs:
         dst_folder.add(src, copier=copy_func.copy_files)
         if self.set_copied:
             self._rename_complete(src)
     self.transferred_count.set(self.file_count)
     self.curr_file.set('Complete!')
Ejemplo n.º 3
0
def test_add_new_project_recursively():
    # Add a scan existing in a project that doesn't exist in the dst folder
    # This will recursively add the project, subject and session.
    with tempfile.TemporaryDirectory() as tmp:
        # copy the dst to a temp folder
        shutil.copytree(TESTPATH2, op.join(tmp, 'BIDSTEST2'))
        src_bt = BIDSTree(TESTPATH1)
        dst_bt = BIDSTree(op.join(tmp, 'BIDSTEST2'))
        scan = src_bt.project('test2').subject('3').session('1').scan(
            task='resting', run='1')
        assert scan.emptyroom is not None
        dst_bt.add(scan)
        # make sure the project was added
        assert len(dst_bt.projects) == 2
        assert op.exists(dst_bt.project('test2').readme)
        assert op.exists(dst_bt.project('test2').description)
        # make sure the subject was added and the empty room data was too
        assert len(dst_bt.project('test2').subjects) == 2
        # make sure the scan was added
        scans_tsv = dst_bt.project('test2').subject('3').session('1').scans_tsv
        assert op.exists(scans_tsv)
        dst_bt.project('test2').subject('emptyroom')
Ejemplo n.º 4
0
def test_merge_bidstrees():
    # Test completely merging one BIDS folder into another.
    with tempfile.TemporaryDirectory() as tmp:
        # copy the dst to a temp folder
        shutil.copytree(TESTPATH2, op.join(tmp, 'BIDSTEST2'))
        src_bt = BIDSTree(TESTPATH1)
        dst_bt = BIDSTree(op.join(tmp, 'BIDSTEST2'))
        with pytest.warns(UserWarning):
            dst_bt.add(src_bt)
        assert len(dst_bt.projects) == 2
        # proj:test1, subj:2, sess: 1 will not have been merged
        assert (src_bt.project('test1').subject(2).session(2)
                not in dst_bt.project('test1').subject(2))
        # To rectify this, rename the folder-less session then re-add
        dst_bt.project('test1').subject(2).session('none').rename('1')
        dst_bt.project('test1').subject(2).add(
            src_bt.project('test1').subject(2).session(2))
        assert len(dst_bt.project('test1').subject(2).sessions) == 2
        # check that extra files are brought along
        sess = dst_bt.project('test2').subject(3).session(1)
        assert 'code' in sess.extra_data
        assert 'extradata' in sess.extra_data
        assert op.exists(op.join(sess.path, 'code', 'analysis.py'))
        assert op.exists(op.join(sess.path, 'extradata', 'extra.txt'))