Ejemplo n.º 1
0
def test_ri_bad_type():
    with pytest.raises(TypeError, match=r'.* is not a valid image type..*'):
        ex = ri("tests/data/mri.nii.gz", "Garbage", "T1", "20000123",
                ["x", "y", "z"], [2, 2, 2])
    with pytest.raises(IOError):
        ex = ri("tests/data/blah.nii.gz", "MRI", "T1", "20000123",
                ["x", "y", "z"], [2, 2, 2])
Ejemplo n.º 2
0
def test_ris_acquisition_date_str_filter():
    with pytest.raises(TypeError):
        image1 = ri("tests/data/mri.nii.gz", "MRI", "T1", "20000123", ["x", "y", "z"], [2, 2, 2])
        image2 = ri("tests/data/mri.nii.gz", "MRI", "T2", "20000123", ["x", "y", "z"], [0.5, 0.5, 4])
        image3 = ri("tests/data/mri.nii.gz", "MRI", "T1+GAD", "20000123", ["x", "y", "z"], [1, 1, 1.5])
        image_set = ris([image1, image2, image3])
        image_set.filter_by_acquisition_date(1337)  # 1337 is not a proper string format for date
Ejemplo n.º 3
0
def test_ris_contrast_filter():
    with pytest.raises(TypeError):
        image1 = ri("tests/data/mri.nii.gz", "MRI", "T1", "20000123", ["x", "y", "z"], [2, 2, 2])
        image2 = ri("tests/data/mri.nii.gz", "MRI", "T2", "20000123", ["x", "y", "z"], [0.5, 0.5, 4])
        image3 = ri("tests/data/mri.nii.gz", "MRI", "T1+GAD", "20000123", ["x", "y", "z"], [1, 1, 1.5])
        image_set = ris([image1, image2, image3])
        image_set.filter_by_contrast(1337)  # 1337 is not a proper contrast
Ejemplo n.º 4
0
def test_ris_radiology_type_filter():
    with pytest.raises(TypeError):
        image1 = ri("tests/data/mri.nii.gz", "MRI", "T1", "20000123", ["x", "y", "z"], [2, 2, 2])
        image2 = ri("tests/data/mri.nii.gz", "MRI", "T2", "20000123", ["x", "y", "z"], [0.5, 0.5, 4])
        image3 = ri("tests/data/mri.nii.gz", "MRI", "T1+GAD", "20000123", ["x", "y", "z"], [1, 1, 1.5])
        image_set = ris([image1, image2, image3])
        image_set.filter_by_radiology_type('NIRS')
Ejemplo n.º 5
0
def test_ris_good_input():
    image1 = ri("tests/data/mri.nii.gz", "MRI", "T1", "20000123", ["x", "y", "z"], [2, 2, 2])
    image2 = ri("tests/data/mri.nii.gz", "MRI", "T2", "20000123", ["x", "y", "z"], [0.5, 0.5, 4])
    image3 = ri("tests/data/mri.nii.gz", "MRI", "T1+GAD", "20000123", ["x", "y", "z"], [1, 1, 1.5])
    image_set = ris([image1, image2, image3])

    # Manually create filtered set after filtering by contrast for T2 images only
    filtered_set2 = ris([image2])

    assert image_set.radiology_images == [image1, image2, image3]
    assert image_set.filter_by_radiology_type('MRI').radiology_images == image_set.radiology_images
    assert image_set.filter_by_contrast('T2').radiology_images == filtered_set2.radiology_images
    assert image_set.filter_by_acquisition_date('20000123').radiology_images == image_set.radiology_images
Ejemplo n.º 6
0
def test_ri_good_input():
    ex = ri("tests/data/mri.nii.gz", "MRI", "T1", "20000123", ["x", "y", "z"],
            [2, 2, 2])
    assert ex.radiologic_type == "MRI"
    assert ex.contrast == "T1"
    assert ex.acquisition_date == "20000123"
    assert ex.image_dimensions == ["x", "y", "z"]
    assert ex.image_resolution == [2, 2, 2]
    assert ex.image_units == ['mm', 'mm', 'mm']
Ejemplo n.º 7
0
def test_cis_computed_type_filter():
    with pytest.raises(TypeError):
        ri_ex = ri('tests/data/mri.nii.gz', 'MRI', 'T1', '20000123', ['x', 'y', 'z'], [2, 2, 2])
        ci_ex1 = ci('tests/data/seg1.nii.gz', ri_ex, 'SegmentationImage', 'NA', 'NA',
                    command_used_to_generate='run1.sh')
        ci_ex2 = ci('tests/data/seg2.nii.gz', ri_ex, 'RegistrationImage', 'MRI', 'T1',
                    command_used_to_generate='run2.sh')
        image_set = cis([ci_ex1, ci_ex2])
        image_set.filter_by_computed_type('Segmntation')
Ejemplo n.º 8
0
def test_ci_bad_type():
    ri_good = ri('tests/data/mri.nii.gz', 'MRI', 'T1', '20000123', ['x', 'y', 'z'], [2, 2, 2])
    with pytest.raises(IOError):  # Test image_location format
        ci_ex = ci('tests/data/blah.nii.gz', ri_good, 'SegmentationImage', 'NA', 'NA')
    with pytest.raises(TypeError):  # Reference radiologic image parameter with incorrect RadiologicImage input format
        ci_ex = ci('tests/data/seg.nii.gz', 3.0, 'SegmentationImage', 'NA', 'NA')
    with pytest.raises(TypeError):  # Invalid computational type
        ci_ex = ci('tests/data/seg.nii.gz', ri_good, 'Segmntation', 'NA', 'NA')
    with pytest.raises(TypeError):  # Invalid radiologic type
        ci_ex = ci('tests/data/seg.nii.gz', ri_good, 'SegmentationImage', 3.0, 'NA', computation_properties=3.0)
    with pytest.raises(TypeError):  # Invalid computation properties type
        ci_ex = ci('tests/data/seg.nii.gz', ri_good, 'SegmentationImage', 'NA', 'NA', computation_properties=3.0)
Ejemplo n.º 9
0
def test_cis_good_input():
    ri_ex = ri('tests/data/mri.nii.gz', 'MRI', 'T1', '20000123', ['x', 'y', 'z'], [2, 2, 2])

    # Test RadiologicImage passed as reference
    ci_ex1 = ci('tests/data/seg1.nii.gz', ri_ex, 'SegmentationImage', 'NA', 'NA',
                command_used_to_generate='run1.sh')
    ci_ex2 = ci('tests/data/seg2.nii.gz', ri_ex, 'RegistrationImage', 'MRI', 'T1',
                command_used_to_generate='run2.sh')
    image_set = cis([ci_ex1, ci_ex2])

    # Manually create filtered set after filtering by contrast for T2 images only
    filtered_set = cis(ci_ex2)
    assert image_set.computed_images == [ci_ex1, ci_ex2]
    assert image_set.filter_by_radiology_type('MRI').computed_images == filtered_set.computed_images
    assert image_set.filter_by_computed_type('RegistrationImage').computed_images == filtered_set.computed_images
    assert image_set.filter_by_contrast('T1').computed_images == filtered_set.computed_images
Ejemplo n.º 10
0
def test_ci_good_input():
    ri_ex = ri('tests/data/mri.nii.gz', 'MRI', 'T1', '20000123', ['x', 'y', 'z'], [2, 2, 2])

    # Test RadiologicImage passed as reference
    ci_ex = ci('tests/data/seg.nii.gz', ri_ex, 'SegmentationImage', 'NA', 'NA',
               command_used_to_generate='run.sh',
               computation_properties={'notes': 'just a test case'})
    assert ci_ex.computed_type == 'SegmentationImage'
    assert ci_ex.reference_radiologic_image.radiologic_type == 'MRI'
    assert ci_ex.reference_radiologic_image.contrast == 'T1'
    assert ci_ex.reference_radiologic_image.acquisition_date == '20000123'
    assert ci_ex.reference_radiologic_image.image_dimensions == ['x', 'y', 'z']
    assert ci_ex.reference_radiologic_image.image_resolution == [2, 2, 2]
    assert ci_ex.reference_radiologic_image.image_units == ['mm', 'mm', 'mm']

    # Test without command_used_to_generate or computation_properties parameter
    ci_ex = ci('tests/data/seg.nii.gz', ri_ex, 'SegmentationImage', 'NA', 'NA')