示例#1
0
def test_base_object():
    empty = Delivery._empty()

    assert empty.monitor_units == tuple()

    collection = {field: getattr(empty, field) for field in empty._fields}

    dummy = Delivery(**collection)
示例#2
0
def test_object_consistency():
    empty = Delivery._empty()
    filtered = empty._filter_cps()

    assert isinstance(filtered.monitor_units, tuple)

    filtered._metersets(0, 0)
示例#3
0
def test_round_trip_dcm2dd2dcm(loaded_dicom_dataset):
    original = loaded_dicom_dataset
    delivery_data = Delivery.from_dicom(original, FRACTION_GROUP)
    processed = delivery_data.to_dicom(original)

    single_fraction_group = convert_to_one_fraction_group(
        original, FRACTION_GROUP)

    original_gantry_angles = get_gantry_angles_from_dicom(
        single_fraction_group)

    assert num_of_control_points(
        single_fraction_group) == num_of_control_points(processed)

    assert maintain_order_unique(
        delivery_data.gantry) == original_gantry_angles

    processed_gantry_angles = get_gantry_angles_from_dicom(processed)

    assert original_gantry_angles == processed_gantry_angles

    assert source_to_surface_distances(
        single_fraction_group) == source_to_surface_distances(processed)

    assert first_mlc_positions(single_fraction_group) == first_mlc_positions(
        processed)

    assert str(single_fraction_group) == str(processed)
示例#4
0
def test_fraction_group_number(loaded_dicom_dataset,
                               logfile_delivery_data: Delivery):
    expected = FRACTION_GROUP

    result = logfile_delivery_data._fraction_number(loaded_dicom_dataset)

    assert result == expected
示例#5
0
def test_mudensity_agreement(loaded_dicom_dataset, logfile_delivery_data):
    dicom_delivery_data = Delivery.from_dicom(loaded_dicom_dataset, FRACTION_GROUP)

    dicom_mu_density = dicom_delivery_data.mudensity(grid_resolution=5)
    logfile_mu_density = logfile_delivery_data.mudensity(grid_resolution=5)

    diff = logfile_mu_density - dicom_mu_density
    max_diff = np.max(np.abs(diff))
    std_diff = np.std(diff)
    try:
        assert max_diff < 4.1
        assert std_diff < 0.4
    except AssertionError:
        max_val = np.max([np.max(logfile_mu_density), np.max(dicom_mu_density)])

        plt.figure()
        plt.pcolormesh(dicom_mu_density, vmin=0, vmax=max_val)
        plt.colorbar()

        plt.figure()
        plt.pcolormesh(logfile_mu_density, vmin=0, vmax=max_val)
        plt.colorbar()

        plt.figure()
        plt.pcolormesh(
            logfile_mu_density - dicom_mu_density,
            vmin=-max_diff,
            vmax=max_diff,
            cmap="bwr",
        )
        plt.colorbar()
        plt.show()
        raise
示例#6
0
def test_round_trip_dd2dcm2dd(loaded_dicom_dataset, logfile_delivery_data: Delivery):
    original = logfile_delivery_data._filter_cps()
    template = loaded_dicom_dataset

    dicom = original.to_dicom(template)
    processed = Delivery.from_dicom(dicom, FRACTION_GROUP)

    assert np.all(
        np.around(original.monitor_units, 2) == np.around(processed.monitor_units, 2)
    )

    assert np.all(np.around(original.gantry, 2) == np.around(processed.gantry, 2))

    assert np.all(np.around(original.mlc, 2) == np.around(processed.mlc, 2))

    assert np.all(np.around(original.jaw, 2) == np.around(processed.jaw, 2))

    # Collimator not currently handled appropriately
    assert np.all(
        np.around(original.collimator, 2) == np.around(processed.collimator, 2)
    )
示例#7
0
from pymedphys.dicom import get_gantry_angles_from_dicom

input_directory = 'input'
output_directory = 'output'
grid_resolution = 5 / 3
gantry_angle_tolerance = 3
image_dpi = 254

trf_filepaths = glob(os.path.join(input_directory, '*.trf'))
dicom_filepaths = glob(os.path.join(input_directory, '*.dcm'))

filepath_mu_density_map: Dict[str, np.ndarray] = {}
filepath_mu_density_diff_map: Dict[str, np.ndarray] = {}

for trf_filepath in trf_filepaths:
    trf_delivery: Delivery = Delivery.from_logfile(trf_filepath).filter_cps()
    trf_filename = os.path.basename(trf_filepath)

    for dicom_filepath in dicom_filepaths:
        dicom_dataset = pydicom.dcmread(dicom_filepath,
                                        force=True,
                                        stop_before_pixels=True)
        try:
            dicom_deliveries = Delivery.load_all_fractions(dicom_dataset)
        except AttributeError:
            print("{} does not appear to be an RT DICOM plan, "
                  "skipping...".format(dicom_filepath))
            continue

        for fraction_number, dicom_delivery_raw in dicom_deliveries.items():
            dicom_delivery = dicom_delivery_raw.filter_cps()
示例#8
0
from pymedphys import Delivery

input_directory = "input"
output_directory = "output"

trf_filepaths = glob(os.path.join(input_directory, "*.trf"))
dicom_filepaths = glob(os.path.join(input_directory, "*.dcm"))

for filepath in trf_filepaths:
    print("Preparing to convert {}".format(filepath))
    filename = os.path.basename(filepath)
    output_filepath = os.path.join(output_directory, "{}.dcm".format(filename))

    print("Loading log file")
    delivery_data = Delivery.from_logfile(filepath)

    print("Converting log file to RT Plan DICOM")
    for dicom_filepath in dicom_filepaths:
        dicom_template = pydicom.dcmread(dicom_filepath, force=True)
        try:
            created_dicom = delivery_data.to_dicom(dicom_template)
            print("{} appears to be an RT DICOM plan with appropriate "
                  "angle meterset combination, using this one.".format(
                      dicom_filepath))
            continue
        except AttributeError:
            print("{} does not appear to be an RT DICOM plan, "
                  "skipping...".format(dicom_filepath))

    print("Saving newly created RT Plan DICOM")
示例#9
0
def mu_density_from_delivery_data(delivery_data: pymedphys.Delivery, grid_resolution=1):
    grid_xx, grid_yy = pymedphys.mudensity.grid(grid_resolution=grid_resolution)
    mu_density = delivery_data.mudensity(grid_resolution=grid_resolution)

    return grid_xx, grid_yy, mu_density
示例#10
0
def logfile_delivery_data():
    return Delivery.from_logfile(LOGFILE_FILEPATH)
示例#11
0
def logfile_delivery_data():
    path = get_file_in_dir(DIR_TO_TEST, "imrt.trf")

    return Delivery.from_logfile(path)
示例#12
0
import pymedphys
from pymedphys import Delivery

# trf file read
trf_file = 'C:/GitFolder/VMAT-QA-metrics/MU intensity/MonacoHDMLC.trf'
delivery = Delivery.from_logfile(trf_file)
trf_mu_density = delivery.mudensity()  # This is the "fluence"
grid = pymedphys.mudensity.grid()

pymedphys.mudensity.display(grid, trf_mu_density)  # plot the MU density

# dicom file read
# dicom_rtplan_filepath = 'C:/GitFolder/VMAT-QA-metrics/example/test_case/VMAT1Arc/0028_VMAT202003181arc.dcm'
# fraction_number = 28
# delivery = Delivery.from_dicom_file(dicom_rtplan_filepath, fraction_number)
# dcm_mudensity = delivery.mudensity()  # This is the "fluence"

# plot the comparison
# subplot(1,2,1)
# plt.imshow(trf_mu_density)
# plt.title('TRF file (Elekta Log file)')
# subplot(1,2,2)
# plt.imshow(dcm_mudensity)
# plt.title('DCM file (Monaco Plan file)')
# plt.colorbar()
# plt.show()