Ejemplo n.º 1
0
def test_sequential_input():
    indices = np.array([4, 5, 9, 10])
    assert_array_equal(diagnostics.extend_diff_outliers(indices),
                       [4, 5, 6, 9, 10, 11])
    indices = np.array([1, 2, 4, 5, 9, 10])
    assert_array_equal(diagnostics.extend_diff_outliers(indices),
                       [1, 2, 3, 4, 5, 6, 9, 10, 11])
    indices = np.array([3, 7, 8, 12, 20])
    assert_array_equal(diagnostics.extend_diff_outliers(indices),
                       [3, 4, 7, 8, 9, 12, 13, 20, 21])
Ejemplo n.º 2
0
    plt.xlabel('Voxel')
    plt.ylabel('Volumn RMS difference values')
    plt.title('Volume RMS difference values_' + i)
    plt.legend(fontsize=8)
    plt.savefig(i + '_vol_rms_outliers.png')
    plt.close()

# plot the extended_vol_rms_outliers

for i in run_img_result.keys():
    img = nib.load(run_img_result[i])
    data = img.get_data()
    rms_dvals = dg.vol_rms_diff(data)
    rms_outliers, rms_thresholds = dg.iqr_outliers(rms_dvals)
    T = data.shape[-1]
    ext_outliers = dg.extend_diff_outliers(rms_outliers)
    x = np.arange(T)
    rms_dvals_ext = np.concatenate((rms_dvals, (0, )), axis=0)
    plt.plot(rms_dvals_ext, label='vol RMS differences')
    plt.plot(x[ext_outliers],
             rms_dvals_ext[ext_outliers],
             'o',
             label='outliers')
    plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]],
             ':',
             label='IQR lo')
    plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]],
             ':',
             label='IQR hi')
    plt.legend(fontsize=8)
    plt.savefig(i + '_extended_vol_rms_outliers.png')
Ejemplo n.º 3
0
""" Use the ``extend_diff_outliers`` to label outliers

Use ``extend_diff_outliers`` on the output from ``iqr_outliers`` on the RMS
difference values.  This gives you indices for labeled outliers.

On the same plot, plot the following:

* The RMS vector with a 0 appended to make it have length the same as the
  number of volumes in the image data array;
* The identified outliers shown with an `o` marker;
* A horizontal dashed line at the lower IRQ threshold;
* A horizontal dashed line at the higher IRQ threshold;

IMPORTANT - save this plot as ``extended_vol_rms_outliers.png``
"""
outliers_rms_label = diagnostics.extend_diff_outliers(outliers_rms_index)
rmsd_append = np.append(rmsd, 0)

plt.plot(rmsd_append, 'r', label='rms extended differences values')
for i in outliers_rms_label:
    plt.plot(i, rmsd_append[i], 'o', color='blue')
plt.axhline(y=thres_rms[0], color='g', ls='dashed', label='low threshold')
plt.axhline(y=thres_rms[1], color='black', ls='dashed', label='high threshold')
plt.legend(loc=3)
plt.xlabel('volume')
plt.ylabel('rms difference')
plt.savefig('extended_vol_rms_outliers.png')
plt.clf()
""" Write the extended outlier indices to a text file.

IMPORTANT: name the text file extended_vol_rms_outliers.txt
Ejemplo n.º 4
0
""" Use the ``extend_diff_outliers`` to label outliers

Use ``extend_diff_outliers`` on the output from ``iqr_outliers`` on the RMS
difference values.  This gives you indices for labeled outliers.

On the same plot, plot the following:

* The RMS vector with a 0 appended to make it have length the same as the
  number of volumes in the image data array;
* The identified outliers shown with an `o` marker;
* A horizontal dashed line at the lower IRQ threshold;
* A horizontal dashed line at the higher IRQ threshold;

IMPORTANT - save this plot as ``extended_vol_rms_outliers.png``
"""
outliers_rms_label = diagnostics.extend_diff_outliers(outliers_rms_index)
rmsd_append = np.append(rmsd, 0)

plt.plot(rmsd_append, "r", label="rms extended differences values")
for i in outliers_rms_label:
    plt.plot(i, rmsd_append[i], "o", color="blue")
plt.axhline(y=thres_rms[0], color="g", ls="dashed", label="low threshold")
plt.axhline(y=thres_rms[1], color="black", ls="dashed", label="high threshold")
plt.legend(loc=3)
plt.xlabel("volume")
plt.ylabel("rms difference")
plt.savefig("extended_vol_rms_outliers.png")
plt.clf()


""" Write the extended outlier indices to a text file.
Ejemplo n.º 5
0
def test_extend_diff_outliers():
    # Test function to extend difference outlier indices
    indices = np.array([3, 7, 12, 20])
    assert_array_equal(diagnostics.extend_diff_outliers(indices),
                       [3, 4, 7, 8, 12, 13, 20, 21])
    #Plot
    N = len(rms_dvals)
    x = np.arange(N)
    plt.plot(rms_dvals, label='vol RMS differences ' + str(name))
    plt.plot(x[rms_outliers], rms_dvals[rms_outliers], 'o', label='outliers')
    plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]], ':', label='IQR lo')
    plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]], ':', label='IQR hi')
    plt.title('voxels rms difference ' + str(name))
    plt.xlabel('time')
    plt.legend(fontsize=11, \
    ncol=2, loc=9, borderaxespad=0.2)
    plt.savefig(project_path+'fig/outliers/%s_vol_rms_outliers.png'%str(name))
    plt.close()
    #Label the outliers
    T = data.shape[-1]
    ext_outliers = diagnostics.extend_diff_outliers(rms_outliers)
    np.savetxt(project_path+'txt_output/outliers/%s_extended_vol_rms_outliers.png' \
      %str(name), ext_outliers)
    x = np.arange(T)
    rms_dvals_ext = np.concatenate((rms_dvals, (0,)), axis=0)
    plt.plot(rms_dvals_ext, label='vol RMS differences ' + str(name))
    plt.plot(x[ext_outliers], rms_dvals_ext[ext_outliers], 'o', label='outliers')
    plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]], ':', label='IQR lo')
    plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]], ':', label='IQR hi')
    plt.xlabel('time')
    plt.legend(fontsize=11, \
    ncol=2, loc=9, borderaxespad=0.2)
    plt.savefig(project_path+\
    'fig/outliers/%s_extended_vol_rms_outliers.png'%str(name))
    plt.close()
Ejemplo n.º 7
0
 plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]],
          ':',
          label='IQR lo')
 plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]],
          ':',
          label='IQR hi')
 plt.title('voxels rms difference ' + str(name))
 plt.xlabel('time')
 plt.legend(fontsize=11, \
 ncol=2, loc=9, borderaxespad=0.2)
 plt.savefig(project_path +
             'fig/outliers/%s_vol_rms_outliers.png' % str(name))
 plt.close()
 #Label the outliers
 T = data.shape[-1]
 ext_outliers = diagnostics.extend_diff_outliers(rms_outliers)
 np.savetxt(project_path+'txt_output/outliers/%s_extended_vol_rms_outliers.png' \
   %str(name), ext_outliers)
 x = np.arange(T)
 rms_dvals_ext = np.concatenate((rms_dvals, (0, )), axis=0)
 plt.plot(rms_dvals_ext, label='vol RMS differences ' + str(name))
 plt.plot(x[ext_outliers],
          rms_dvals_ext[ext_outliers],
          'o',
          label='outliers')
 plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]],
          ':',
          label='IQR lo')
 plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]],
          ':',
          label='IQR hi')
Ejemplo n.º 8
0
	plt.xlabel('Voxel')
	plt.ylabel('Volumn RMS difference values')
	plt.title('Volume RMS difference values_' + i)
	plt.legend(fontsize = 8)
	plt.savefig( i + '_vol_rms_outliers.png')
	plt.close()

# plot the extended_vol_rms_outliers

for i in run_img_result.keys():
	img = nib.load(run_img_result[i])
	data = img.get_data()
	rms_dvals = dg.vol_rms_diff(data)
	rms_outliers, rms_thresholds = dg.iqr_outliers(rms_dvals)
	T = data.shape[-1]
	ext_outliers = dg.extend_diff_outliers(rms_outliers)
	x = np.arange(T)
	rms_dvals_ext = np.concatenate((rms_dvals, (0,)), axis=0)
	plt.plot(rms_dvals_ext, label='vol RMS differences')
	plt.plot(x[ext_outliers], rms_dvals_ext[ext_outliers], 'o', label='outliers')
	plt.plot([0, N], [rms_thresholds[0], rms_thresholds[0]], ':', label='IQR lo')
	plt.plot([0, N], [rms_thresholds[1], rms_thresholds[1]], ':', label='IQR hi')
	plt.legend(fontsize = 8)
	plt.savefig(i + '_extended_vol_rms_outliers.png')
	plt.close()