Ejemplo n.º 1
0
def testNumIncrementals(oneImageBidsI):
    run = BidsRun()
    assert run.numIncrementals() == 0

    NUM_APPENDS = 20
    for i in range(NUM_APPENDS):
        run.appendIncremental(oneImageBidsI)
        assert run.numIncrementals() == i + 1
Ejemplo n.º 2
0
def testAppendConflictingMetadata(oneImageBidsI):
    bidsInc2 = BidsIncremental(oneImageBidsI.image,
                               oneImageBidsI.getImageMetadata())
    bidsInc2.setMetadataField('subject', 'definitely_invalid_name')

    run = BidsRun()
    run.appendIncremental(oneImageBidsI)
    with pytest.raises(MetadataMismatchError):
        run.appendIncremental(bidsInc2)

    # Append should work now with validateAppend turned off
    numIncrementalsBefore = run.numIncrementals()
    run.appendIncremental(bidsInc2, validateAppend=False)
    assert run.numIncrementals() == (numIncrementalsBefore + 1)
Ejemplo n.º 3
0
def testAppendConflictingNiftiHeaders(oneImageBidsI, imageMetadata):
    # Change the pixel dimensions (zooms) to make the image append-incompatible
    image2 = nib.Nifti1Image(oneImageBidsI.image.dataobj,
                             oneImageBidsI.image.affine,
                             oneImageBidsI.image.header)
    new_data_shape = tuple(i * 2 for i in image2.header.get_zooms())
    image2.header.set_zooms(new_data_shape)
    bidsInc2 = BidsIncremental(image2, imageMetadata)

    run = BidsRun()
    run.appendIncremental(oneImageBidsI)
    with pytest.raises(MetadataMismatchError):
        run.appendIncremental(bidsInc2)

    # Append should work now with validateAppend turned off
    numIncrementalsBefore = run.numIncrementals()
    run.appendIncremental(bidsInc2, validateAppend=False)
    assert run.numIncrementals() == (numIncrementalsBefore + 1)
Ejemplo n.º 4
0
    def appendBidsRun(self, run: BidsRun) -> None:
        """
        Append a BIDS Run to this archive.

        Args:
            run: Run to append to the archvie.

        Examples:
            >>> archive1 = BidsArchive('/tmp/dataset1')
            >>> archive2 = BidsArchive('/tmp/dataset2')
            >>> archive1.getRuns()
            [1, 2]
            >>> archive2.getRuns()
            [1]
            >>> run2 = archive1.getBidsRun(subject='01', task='test', run=2)
            >>> archive2.appendBidsRun(run2)
            >>> archive2.getRuns()
            [1, 2]
        """
        if run.numIncrementals() == 0:
            return

        self._appendIncremental(run.asSingleIncremental())
Ejemplo n.º 5
0
def testAppendEmptyIncrementals(oneImageBidsI, sampleBidsEntities):
    run = BidsRun(**sampleBidsEntities)
    run.appendIncremental(oneImageBidsI)
    assert run.numIncrementals() == 1