def testAppendConflictingEntities(oneImageBidsI): differentBidsInc = BidsIncremental(oneImageBidsI.image, oneImageBidsI.getImageMetadata()) differentBidsInc.setMetadataField("subject", "new-subject") run = BidsRun() run.appendIncremental(oneImageBidsI) with pytest.raises(MetadataMismatchError): run.appendIncremental(differentBidsInc)
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)
def incrementAcquisitionValues(incremental: BidsIncremental) -> None: """ Increment the acquisition values in an image metadata dictionary to prepare for append an incremental to an archive built with the same source image. """ trTime = incremental.getMetadataField("RepetitionTime") trTime = 1.0 if trTime is None else float(trTime) fieldToIncrement = {'AcquisitionTime': trTime, 'AcquisitionNumber': 1.0} for field, increment in fieldToIncrement.items(): previousValue = incremental.getMetadataField(field) if previousValue is None: continue else: previousValue = float(previousValue) incremental.setMetadataField(field, previousValue + increment)