i
port numpy as np
import numpy.linalg as npl
import matplotlib.pyplot as plt
import nibabel as nib

def load_data(fname, tr):
	# Load the image as an image object
	img = nib.load(fname + '.nii')
	# Load the image data as an array
	# Drop the first 4 3D volumes from the array
	data = img.get_data()[..., 4:]
	# Load the pre-written convolved time course
	convolved = np.loadtxt(fname + '_conv.txt')[4:]

	return(data, convolved)

def reg_voxels_4d(data, convolved):
	design = np.ones((len(convolved), 2))
	design[:, 1] = convolved
	data_2d = np.reshape(data, (-1, data.shape[-1]))
	betas = npl.pinv(design).dot(data_2d.T)
	betas_4d = np.reshape(betas.T, img.shape[:-1] + (-1,))

	return betas_4d
if __name__ == '__main__':
	from sys import argv

	fname = argv[1]
	data, convolved = load_data(fname, 2.5)
	beta_hat = reg_voxels_4d(data, convolved)
	plt.imshow(beta_hat[:, :, 14, 0], interpolation = 'nearest', cmap = 'gray')
	plt.show()

@@ -1,10 +1,10 @@
 i
-%0A
+m
 port num
@@ -117,16 +117,297 @@
 name
-, tr):%0A%09
+):%0A    %22%22%22%0A    Return the image data as an array and the convolved time course%0A%0A    Parameters%0A    ----------%0A    fname : string%0A        The name of data to process%0A%0A    Returns%0A    -------%0A    tuple:%0A        Contains the image data as an array and the convolved time course%0A%0A%0A    %22%22%22%0A    
 # Lo
@@ -438,17 +438,20 @@
  object%0A
-%09
+    
 img = ni
@@ -473,17 +473,20 @@
 '.nii')%0A
-%09
+    
 # Load t
@@ -511,17 +511,20 @@
 n array%0A
-%09
+    
 # Drop t
@@ -560,17 +560,20 @@
 e array%0A
-%09
+    
 data = i
@@ -595,17 +595,20 @@
 .., 4:%5D%0A
-%09
+    
 # Load t
@@ -644,17 +644,20 @@
  course%0A
-%09
+    
 convolve
@@ -697,17 +697,20 @@
 ')%5B4:%5D%0A%0A
-%09
+    
 return(d
@@ -762,17 +762,20 @@
 olved):%0A
-%09
+    
 design =
@@ -804,17 +804,20 @@
 d), 2))%0A
-%09
+    
 design%5B:
@@ -833,17 +833,20 @@
 nvolved%0A
-%09
+    
 data_2d 
@@ -886,17 +886,20 @@
 e%5B-1%5D))%0A
-%09
+    
 betas = 
@@ -930,17 +930,20 @@
 a_2d.T)%0A
-%09
+    
 betas_4d
@@ -990,17 +990,20 @@
 (-1,))%0A%0A
-%09
+    
 return b
@@ -1010,16 +1010,17 @@
 etas_4d%0A
+%0A
 if __nam
@@ -1038,17 +1038,20 @@
 ain__':%0A
-%09
+    
 from sys
@@ -1063,18 +1063,20 @@
 rt argv%0A
-%0A%09
+    
 fname = 
@@ -1083,17 +1083,20 @@
 argv%5B1%5D%0A
-%09
+    
 data, co
@@ -1124,16 +1124,14 @@
 name
-, 2.5)%0A%09
+)%0A    
 beta
@@ -1168,17 +1168,20 @@
 volved)%0A
-%09
+    
 plt.imsh
@@ -1252,9 +1252,12 @@
 y')%0A
-%09
+    
 plt.

delete unnecessary parameter and add docstrings to the first function