コード例 #1
0
def test_loading_invalid_reference_rt_struct(series_path):
    # This RTStruct references images not found within the series path
    invalid_reference_rt_struct_path = os.path.join(
        series_path, "invalid_reference_rt.dcm")
    assert os.path.exists(invalid_reference_rt_struct_path)
    with pytest.raises(Exception):
        RTStructBuilder.create_from(series_path,
                                    invalid_reference_rt_struct_path)
コード例 #2
0
def test_non_existant_referenced_study_sequence(series_path):
    non_existent_reference_study_rt_struct_path = os.path.join(
        series_path, "non_existent_reference_rt.dcm")
    assert os.path.exists(non_existent_reference_study_rt_struct_path)
    rtstruct = RTStructBuilder.create_from(
        series_path, non_existent_reference_study_rt_struct_path)

    # Test that the attribute does not exist but RTStruct instantiation was still successful
    assert not hasattr(rtstruct.ds.ReferencedFrameOfReferenceSequence[0],
                       "RTReferencedStudySequence")
コード例 #3
0
def test_loading_valid_rt_struct(series_path):
    valid_rt_struct_path = os.path.join(series_path, "rt.dcm")
    assert os.path.exists(valid_rt_struct_path)
    rtstruct = RTStructBuilder.create_from(series_path, valid_rt_struct_path)

    # Tests existing values predefined in the file are found
    assert hasattr(rtstruct.ds, "ROIContourSequence")
    assert hasattr(rtstruct.ds, "StructureSetROISequence")
    assert hasattr(rtstruct.ds, "RTROIObservationsSequence")
    assert len(rtstruct.ds.ROIContourSequence) == 1
    assert len(rtstruct.ds.StructureSetROISequence) == 1
    assert len(rtstruct.ds.RTROIObservationsSequence) == 1

    # Test adding a new ROI
    mask = get_empty_mask(rtstruct)
    mask[50:100, 50:100, 0] = 1
    rtstruct.add_roi(mask)

    assert len(rtstruct.ds.ROIContourSequence) == 2  # 1 should be added
    assert len(rtstruct.ds.StructureSetROISequence) == 2  # 1 should be added
    assert len(rtstruct.ds.RTROIObservationsSequence) == 2  # 1 should be added
    new_roi = rtstruct.ds.StructureSetROISequence[-1]
    assert new_roi.ROIName == "ROI-2"
コード例 #4
0
def test_loading_invalid_rt_struct(series_path):
    invalid_rt_struct_path = os.path.join(series_path, "ct_1.dcm")
    assert os.path.exists(invalid_rt_struct_path)
    with pytest.raises(Exception):
        RTStructBuilder.create_from(series_path, invalid_rt_struct_path)