def test_dicom2nifti_rename_dicom2nifti_output():
    dicom_dir = sd.unzip_t1()
    nifti_file = sd.setup_nifti("2_t2_tse_coronal_512.nii.gz", unzip=True)

    type = "dicom2nifti"
    conversion = MagicMock()
    conversion.ext = NIFTI_TYPE

    orig_dir = Path("orig_dir")
    roi_dir = Path(dicom_dir)
    output_dir = Path(sd.WORKING_DIR)

    converter = Converters.BaseConverter.factory(
        type_=type,
        orig_dir=orig_dir,
        roi_dir=roi_dir,
        output_dir=output_dir,
        conversion=conversion,
    )

    converter.rename_dicom2nifti_output("test_output")

    old_file = os.path.join(sd.WORKING_DIR, "2_t2_tse_coronal_512.nii")
    new_file = os.path.join(sd.WORKING_DIR, "test_output.nii")
    assert not os.path.exists(old_file)
    assert os.path.exists(new_file)

    sd.clean_working_dir()
Beispiel #2
0
def test_DicomRoiCollector_get_current_study_series_uid():

    orig_dir = sd.unzip_t1()

    fw_client = MagicMock()
    file_object = MagicMock()
    collector = Collectors.DicomRoiCollector(fw_client=fw_client,
                                             orig_dir=orig_dir,
                                             file_object=file_object)

    studyInstance, seriesInstance = collector.get_current_study_series_uid()
    assert studyInstance == sd.T2_PHANTOM_STUDY_UID
    assert seriesInstance == sd.T2_PHANTOM_SERIES_UID
    sd.clean_working_dir()
Beispiel #3
0
def test_PrepDicom_move_dicoms_to_workdir_zipped():

    prepper = Preppers.PrepDicom(work_dir=sd.WORKING_DIR,
                                 input_file_path=sd.DICOM_TEST_DATA)
    prepper.move_dicoms_to_workdir()

    expected_dir = prepper.orig_dir
    print(expected_dir)
    assert os.path.exists(expected_dir)

    ndicoms = glob.glob(os.path.join(expected_dir, "*.dcm"))
    assert len(ndicoms) == sd.NUM_DICOMS

    sd.clean_working_dir()
def test_dcm2niix_nifti():

    sd.clean_working_dir()

    input_file = sd.get_zipped_t1()
    work_dir = Path(sd.WORKING_DIR) / "work"
    work_dir.mkdir(exist_ok=True)
    output_dir = Path(sd.WORKING_DIR) / "output"
    output_dir.mkdir(exist_ok=True)

    fw = flywheel.Client()
    # Get configuration, acquisition, and file info
    file_id = "626037fe7cc96261fa295c75"
    file_obj = fw.get_file(file_id)

    # destination_type = "nrrd" if config.get("save_NRRD") else "nifti"
    input_file = Path(input_file)
    destination_type = "nifti"
    combine = False
    bitmask = False
    method = "dcm2niix"

    exporter = MeasurementExport(
        fw_client=fw,
        fw_file=file_obj,
        work_dir=work_dir,
        output_dir=output_dir,
        input_file_path=input_file,
        dest_file_type=destination_type,
        combine=combine,
        bitmask=bitmask,
        method=method,
    )

    ohifviewer_info, labels, affine = exporter.process_file()
    globpath = output_dir / "*"
    output_files = glob.glob(globpath.as_posix())
    assert len(output_files) == 3

    output_files = [os.path.basename(a) for a in output_files]
    doggy = [d for d in output_files if d.startswith("ROI_Doggy")]
    potato = [d for d in output_files if d.startswith("ROI_Potato")]
    lesion = [d for d in output_files if d.startswith("ROI_Lesion")]

    assert len(doggy) == 1
    assert len(potato) == 1
    assert len(lesion) == 1

    sd.clean_working_dir()
Beispiel #5
0
def test_PrepDicom_copy_dicoms_for_export():

    unziped_dir = sd.unzip_t1()
    prepper = Preppers.PrepDicom(work_dir=sd.WORKING_DIR,
                                 input_file_path=sd.DICOM_TEST_DATA)
    prepper.orig_dir = unziped_dir
    prepper.copy_dicoms_for_export()

    expected_dir = prepper.output_dir
    ndicoms = glob.glob(os.path.join(expected_dir, "*.dcm"))

    assert expected_dir != unziped_dir
    assert os.path.exists(expected_dir)
    assert len(ndicoms) == sd.NUM_DICOMS

    sd.clean_working_dir()
def test_dicom2nifti_guess_dicom2nifti_outputname():
    dicom_dir = sd.unzip_t1()

    type = "dicom2nifti"
    conversion = MagicMock()
    conversion.ext = "ext"
    output_filename = os.path.join(sd.WORKING_DIR, "output_filename")

    orig_dir = Path("orig_dir")
    roi_dir = Path(dicom_dir)
    output_dir = Path("output_dir")

    converter = Converters.BaseConverter.factory(
        type_=type,
        orig_dir=orig_dir,
        roi_dir=roi_dir,
        output_dir=output_dir,
        conversion=conversion,
    )

    base_filename = converter.guess_dicom2nifti_outputname()
    assert base_filename == "2_t2_tse_coronal_512"
    sd.clean_working_dir()
Beispiel #7
0
def test_cleanup():
    sd.clean_working_dir()