コード例 #1
0
def test_streamlit_gui():
    pymedphys.zip_data_paths("mu-density-gui-e2e-data.zip",
                             extract_directory=HERE)

    with process("poetry run pymedphys gui", cwd=HERE, shell=True) as _:
        subprocess.check_call("yarn", cwd=HERE, shell=True)
        subprocess.check_call("yarn cypress run", cwd=HERE, shell=True)
コード例 #2
0
ファイル: test_cypress.py プロジェクト: lc52520/pymedphys
def test_cypress():
    pymedphys.zip_data_paths("mu-density-gui-e2e-data.zip",
                             extract_directory=HERE)

    pymedphys.zip_data_paths(
        "dummy-ct-and-struct.zip",
        extract_directory=HERE.joinpath("cypress", "fixtures"),
    )

    with process("poetry run pymedphys gui", cwd=HERE, shell=True) as _:
        subprocess.check_call("yarn", cwd=HERE, shell=True)

        subprocess.check_call("yarn cypress run", cwd=HERE, shell=True)
コード例 #3
0
def test_delivery_from_monaco():
    data_paths = pymedphys.zip_data_paths("tel-dicom-pairs.zip")
    dir_names = {path.parent.name for path in data_paths}

    assert len(dir_names) >= 2

    for dir_name in dir_names:
        if dir_name in DIRS_TO_SKIP:
            continue

        current_paths = [
            path for path in data_paths if path.parent.name == dir_name
        ]

        tel_path = get_file_type(current_paths, "tel.1", exact_match=True)
        dcm_path = get_file_type(current_paths, "dcm")

        delivery_dcm = pymedphys.Delivery.from_dicom(pydicom.read_file(
            str(dcm_path), force=True),
                                                     fraction_number=1)

        delivery_monaco = pymedphys.Delivery.from_monaco(tel_path)

        assert np.allclose(delivery_monaco.mu, delivery_dcm.mu, atol=0.01)
        assert np.allclose(delivery_monaco.gantry,
                           delivery_dcm.gantry,
                           atol=0.01)
        assert np.allclose(delivery_monaco.collimator,
                           delivery_dcm.collimator,
                           atol=0.01)
        assert np.allclose(delivery_monaco.mlc, delivery_dcm.mlc, atol=0.1)
        assert np.allclose(delivery_monaco.jaw, delivery_dcm.jaw, atol=0.01)
コード例 #4
0
def test_structure_dedupe():
    data_paths = pymedphys.zip_data_paths("structure-deduplication.zip")

    input_paths = [path for path in data_paths if path.parent.name == "input"]

    for input_path in input_paths:
        input_dcm = pydicom.read_file(str(input_path), force=True)

        baseline_path = input_path.parent.parent.joinpath(
            "baseline", input_path.name)
        baseline_dcm = pydicom.read_file(str(baseline_path), force=True)

        assert str(input_dcm) != str(baseline_dcm)

        roi_contour_sequences = input_dcm.ROIContourSequence

        for item in roi_contour_sequences:
            pymedphys.dicom.merge_contours(item, inplace=True)

        assert str(input_dcm) == str(baseline_dcm)

        with tempfile.TemporaryDirectory() as temp_dir:
            output_filename = str(pathlib.Path(temp_dir).joinpath("temp.dcm"))

            command = "pymedphys dicom merge-contours".split() + [
                str(input_path),
                output_filename,
            ]
            subprocess.check_call(command)

            cli_dcm = pydicom.read_file(output_filename, force=True)

        assert str(cli_dcm) == str(baseline_dcm)
コード例 #5
0
def get_file_within_data_zip(zip_name, file_name):
    dose_data_files = pymedphys.zip_data_paths(zip_name)
    path_match = [path for path in dose_data_files if path.name == file_name]

    assert len(path_match) == 1

    return str(path_match[0])
コード例 #6
0
def get_file_in_dir(directory, filename):
    all_paths = pymedphys.zip_data_paths("delivery_test_data.zip")
    filtered = [
        path
        for path in all_paths
        if path.parent.name == directory and path.name == filename
    ]

    assert len(filtered) == 1

    return str(filtered[0])
コード例 #7
0
def test_lossless_jpeg():
    testing_data = pymedphys.zip_data_paths("lossless_jpeg_test.zip")

    input_jpg = [path for path in testing_data if path.name == "input.jpg"][0]
    output_ppm = [path for path in testing_data
                  if path.name == "output.ppm"][0]

    reference = imageio.imread(output_ppm)

    with tempfile.TemporaryDirectory() as tmpdirname:
        output_file = pathlib.Path(tmpdirname).joinpath("output.ppm")
        pymedphys._losslessjpeg.convert_lossless_jpeg(  # pylint: disable = protected-access
            input_jpg, output_file)

        result = imageio.imread(output_file)

    assert np.all(reference == result)
コード例 #8
0
def test_end_to_end():
    edge_lengths = [20, 20]

    image_paths = pymedphys.zip_data_paths("wlutz_images.zip")
    results = pymedphys._wlutz.iview.batch_process(  # pylint:disable = protected-access
        image_paths,
        edge_lengths,
        display_figure=False)

    reference_dataframe = pd.read_csv(HERE.joinpath("end_to_end.csv"))

    assert np.max(
        np.abs(results["Rotation"] - reference_dataframe["Rotation"])) <= 0.1
    assert (np.max(
        np.max(
            np.abs(
                results.drop(columns=["Rotation"]) -
                reference_dataframe.drop(columns=["Rotation"])))) <= 0.05)
コード例 #9
0
ファイル: test_decode.py プロジェクト: lc52520/pymedphys
def test_conversions():
    data_paths = pymedphys.zip_data_paths("trf-references-and-baselines.zip")

    files_with_references = [
        path for path in data_paths
        if path.parent.name == "with_reference" and path.suffix == ".trf"
    ]

    assert len(files_with_references) >= 5

    files_without_references = [
        path for path in data_paths
        if path.parent.name == "with_baseline" and path.suffix == ".trf"
    ]

    assert len(files_without_references) >= 4

    with tempfile.TemporaryDirectory() as output_directory:
        for filepath in files_with_references:
            convert_and_check_against_reference(filepath, output_directory)

        for filepath in files_without_references:
            convert_and_check_against_baseline(filepath, output_directory)
コード例 #10
0
def download_and_extract_demo_data(cwd):
    pymedphys.zip_data_paths("mu-density-gui-e2e-data.zip",
                             extract_directory=cwd)
コード例 #11
0
ファイル: test_from_dicom.py プロジェクト: lc52520/pymedphys
def dataset():
    path = pymedphys.zip_data_paths("dicom-to-delivery-issue-#1047.zip")[0]

    return pydicom.dcmread(path)