def test_qap_functional_temporal():

    import os
    import pkg_resources as p
    
    from qap.qap_workflows_utils import qap_functional_temporal

    mask_path = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                    "rest_1", \
                                    "functional_brain_mask", \
                                    "rest_calc_tshift_resample_volreg" \
                                    "_mask.nii.gz"))

    func_path = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                    "rest_1", \
                                    "func_motion_correct", \
                                    "rest_calc_tshift_resample_" \
                                    "volreg.nii.gz"))
    
    matrix = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                 "rest_1", \
                                 "coordinate_transformation", \
                                 "rest_calc_tshift_resample.aff12.1D"))
    
    subject = "1019436"
    session = "session_1"
    scan = "rest_1"

    qc = qap_functional_temporal(func_path, mask_path, matrix, subject, \
                                     session, scan)

    assert (len(qc.keys()) == 10) and (None not in qc.values())
def test_qap_functional_temporal():

    import os
    import pkg_resources as p

    from qap.qap_workflows_utils import qap_functional_temporal

    mask_path = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                    "rest_1", \
                                    "functional_brain_mask", \
                                    "rest_calc_tshift_resample_volreg" \
                                    "_mask.nii.gz"))

    func_path = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                    "rest_1", \
                                    "func_motion_correct", \
                                    "rest_calc_tshift_resample_" \
                                    "volreg.nii.gz"))

    matrix = p.resource_filename("qap", os.path.join(test_sub_dir, \
                                 "rest_1", \
                                 "coordinate_transformation", \
                                 "rest_calc_tshift_resample.aff12.1D"))

    subject = "1019436"
    session = "session_1"
    scan = "rest_1"

    qc = qap_functional_temporal(func_path, mask_path, matrix, subject, \
                                     session, scan)

    assert (len(qc.keys()) == 10) and (None not in qc.values())
Esempio n. 3
0
tsnr = tsnr.aggregate_outputs()
os.chdir(cwd)
for out_name in ["tsnr_file", "mean_file", "stddev_file"]:
    path = getattr(tsnr, out_name)
    tmp_path = os.path.join(subjectdir, "tmp_" + os.path.basename(path))
    shutil.copyfile(path, tmp_path)
    im = nibabel.load(tmp_path)
    data_array = im.get_data()
    data_array[numpy.isnan(data_array)] = 0
    nibabel.save(im, path)
    os.remove(tmp_path)


# > compute functional temporal scores from QAP library
qc = qap_functional_temporal(funcrealign_file, args.maskrealign,
                             tsnr.tsnr_file,
                             fd_file, args.subjectid, "mysession", "myscan",
                             site_name="mysite", motion_threshold=1.0)
# > compute snaps
tsnr_snap = os.path.join(subjectdir, "tsnr_volume.pdf")
figures.append(tsnr_snap)
fig = plot_mosaic(getattr(tsnr, "tsnr_file"), title="tSNR volume")
fig.savefig(tsnr_snap, dpi=300)
fd_snap = os.path.join(subjectdir, "plot_fd.pdf")
figures.append(fd_snap)
fig = plot_fd(fd_file, title="FD plot")
fig.savefig(fd_snap, dpi=300)

# > save scores as a CSV file
scores_json = os.path.join(subjectdir, "qap_functional_temporal.json")
qc.pop("session")
qc.pop("scan")
Esempio n. 4
0
for out_name in ["tsnr_file", "mean_file", "stddev_file"]:
    path = getattr(tsnr, out_name)
    tmp_path = os.path.join(subjectdir, "tmp_" + os.path.basename(path))
    shutil.copyfile(path, tmp_path)
    im = nibabel.load(tmp_path)
    data_array = im.get_data()
    data_array[numpy.isnan(data_array)] = 0
    nibabel.save(im, path)
    os.remove(tmp_path)

# > compute functional temporal scores from QAP library
qc = qap_functional_temporal(funcrealign_file,
                             args.maskrealign,
                             tsnr.tsnr_file,
                             fd_file,
                             args.subjectid,
                             "mysession",
                             "myscan",
                             site_name="mysite",
                             motion_threshold=args.motion_threshold)
# > compute snaps
tsnr_snap = os.path.join(subjectdir, "tsnr_volume.pdf")
figures.append(tsnr_snap)
fig = plot_mosaic(getattr(tsnr, "tsnr_file"), title="tSNR volume")
fig.savefig(tsnr_snap, dpi=300)
fd_snap = os.path.join(subjectdir, "plot_fd.pdf")
figures.append(fd_snap)
fig = plot_fd(fd_file, title="FD plot")
fig.savefig(fd_snap, dpi=300)

# > save scores as a CSV file