Exemple #1
0
def compute_dvr_image(pet_file,
                      gtmpvc_dir,
                      frame_start_times,
                      time_window_start_end,
                      ref_roi,
                      weighted_merge,
                      output_image,
                      spm_path=None):
    """
    Computes the DVR for each input PET's voxel, and saves the result as a nifti image.
    """
    spm_path = get_spm_path(spm_path)
    unzipped_output_image = output_image
    if output_image.suffix == '.gz':
        unzipped_output_image = output_image[:-3]

    matlab_output = matlab.run(
        f"addpath {spm_path}; addpath {MATLAB_SRC_DIR}; compute_dvr_image('{pet_file}', '{gtmpvc_dir}', '{frame_start_times}', '{time_window_start_end}', '{ref_roi}', '{weighted_merge}', '{unzipped_output_image}')"
    )

    if output_image.suffix == '.gz':
        from plumbum.cmd import gzip
        gzip(unzipped_output_image)

    return matlab_output
Exemple #2
0
def compute_roi_dvrs(gtmpvc_dir,
                     frame_start_times,
                     time_window_start_end,
                     ref_roi,
                     weighted_merge,
                     output_csv,
                     spm_path=None):
    """
    Computes the DVR for each Freesurfer gtmpvc ROI as well for each left and right hemisphere
    combined ROI, and saves the result to a csv file.
    """
    spm_path = get_spm_path(spm_path)
    return matlab.run(
        f"addpath {spm_path}; addpath {MATLAB_SRC_DIR}; compute_roi_dvrs('{gtmpvc_dir}', '{frame_start_times}', '{time_window_start_end}', '{ref_roi}', '{weighted_merge}', '{output_csv}')"
    )
Exemple #3
0
def ecat2nifti(ecat_filepath, output_dir, spm_path=None):
    spm_path = find_spm_path(spm_path)
    ecat_filepath_full = os.path.realpath(ecat_filepath)

    matlab_command = [
        f"addpath('{spm_path}')", f"spm_ecat2nifti('{ecat_filepath_full}')"
    ]

    with local.cwd(output_dir):
        retcode, stdout, stderr = matlab.run(matlab_command)

    if not output_dir // '*.nii':
        print(stdout)
        print(stderr)
        raise Exception(f"No niftis generated from ecat {ecat_filepath}")

    return retcode, stdout, stderr
def test_list_command():
    (retcode, stderr, _) = matlab.run(["disp('hello')", "disp('world')"])
    assert retcode == 0
    assert stderr.split('\n')[-3:] == ['hello', 'world', '']
def test_str_command():
    (retcode, _, _) = matlab.run('disp([1 2 3])')
    assert retcode == 0