예제 #1
0
def test_equal():
    dicom1 = DicomBase.from_dict({
        "Manufacturer": "PyMedPhys",
        "PatientName": "Python^Monte"
    })
    dicom2 = DicomBase.from_dict({
        "Manufacturer": "PyMedPhys",
        "PatientName": "Python^Monte"
    })
    assert dicom1 == dicom2  # Equality from dict

    try:
        fp1 = pydicom.filebase.DicomBytesIO()
        dicom1.to_file(fp1)
        fp2 = pydicom.filebase.DicomBytesIO()
        dicom2.to_file(fp2)

        dicom1_from_file = DicomBase.from_file(fp1)
        dicom2_from_file = DicomBase.from_file(fp2)
        # Equality from file (implicitly also from dataset)
        assert dicom1_from_file == dicom2_from_file

        dicom1_from_file.dataset.PatientName = "test^PatientName change"
        assert dicom1_from_file != dicom2_from_file  # Negative case

        dicom1_from_file.dataset.PatientName = "Python^Monte"
        assert dicom1_from_file == dicom2_from_file  # Equality post re-assignment

        dicom1_from_file_copied = deepcopy(dicom1_from_file)
        assert dicom1_from_file == dicom1_from_file_copied  # Equality from deepcopy
    finally:
        fp1.close()
        fp2.close()
예제 #2
0
def test_to_and_from_file():
    temp_file = io.BytesIO()

    dicom = DicomBase.from_dict({
        "Manufacturer": "PyMedPhys",
        "PatientName": "Python^Monte"
    })

    dicom.to_file(temp_file)

    new_dicom = DicomBase.from_file(temp_file)

    # TODO: Without the str this was passing locally but not on CI. Further
    # investigation needed.
    assert new_dicom == dicom
예제 #3
0
def test_surface_entry_with_fallback():
    should_fail_with_unsupported_gantry = DicomBase.from_dict(
        {"BeamSequence": [{
            "ControlPointSequence": [{
                "GantryAngle": "5.0"
            }]
        }]})

    with pytest.raises(ValueError):
        get_surface_entry_point_with_fallback(
            should_fail_with_unsupported_gantry.dataset)

    plan_dataset = pydicom.read_file(str(DICOM_PLAN_FILEPATH), force=True)
    for beam in plan_dataset.BeamSequence:
        for control_point in beam.ControlPointSequence:
            try:
                del control_point.SurfaceEntryPoint
            except AttributeError:
                pass

    with pytest.raises(DICOMEntryMissing):
        get_surface_entry_point(plan_dataset)

    assert get_surface_entry_point_with_fallback(plan_dataset) == (0.0, -300.0,
                                                                   0.0)
예제 #4
0
def test_copy():
    dont_change_string = "don't change me"
    to_be_changed_string = "do change me"

    new_manufactuer = "george"

    dataset_to_be_copied = dicom_dataset_from_dict(
        {"Manufacturer": dont_change_string})

    dataset_to_be_viewed = dicom_dataset_from_dict(
        {"Manufacturer": to_be_changed_string})

    dicom_base_copy = DicomBase(dataset_to_be_copied)
    dicom_base_view = DicomBase(dataset_to_be_viewed, copy=False)

    dicom_base_copy.dataset.Manufacturer = new_manufactuer
    dicom_base_view.dataset.Manufacturer = new_manufactuer

    assert dataset_to_be_copied.Manufacturer == dont_change_string
    assert dataset_to_be_viewed.Manufacturer == new_manufactuer
예제 #5
0
def test_surface_entry():
    plan = pydicom.read_file(str(DICOM_PLAN_FILEPATH), force=True)

    assert get_surface_entry_point(plan) == (0.0, -300.0, 0.0)

    should_pass = DicomBase.from_dict({
        "BeamSequence": [{
            "ControlPointSequence": [{
                "SurfaceEntryPoint": ["10.0", "20.0", "30.0"]
            }]
        }]
    })

    assert get_surface_entry_point(should_pass.dataset) == (10.0, 20.0, 30.0)

    should_fail_with_no_points = DicomBase.from_dict(
        {"BeamSequence": [{
            "ControlPointSequence": []
        }]})

    with pytest.raises(DICOMEntryMissing):
        get_surface_entry_point(should_fail_with_no_points.dataset)

    should_fail_with_differing_points = DicomBase.from_dict({
        "BeamSequence": [
            {
                "ControlPointSequence": [{
                    "SurfaceEntryPoint": ["10.0", "20.0", "30.0"]
                }]
            },
            {
                "ControlPointSequence": [{
                    "SurfaceEntryPoint": ["20.0", "20.0", "30.0"]
                }]
            },
        ]
    })

    with pytest.raises(ValueError):
        get_surface_entry_point(should_fail_with_differing_points.dataset)
예제 #6
0
def test_anonymise():
    expected_dataset = dicom_dataset_from_dict({
        "Manufacturer": "PyMedPhys",
        "PatientName": "Anonymous"
    })

    dicom = DicomBase.from_dict({
        "Manufacturer": "PyMedPhys",
        "PatientName": "Python^Monte"
    })

    dicom.anonymise(inplace=True)

    assert dicom.dataset == expected_dataset