Skip to content

Commit

Permalink
added possibility to use asymmetric stimuli in pRF mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MSenden committed Jan 4, 2021
1 parent 6dad7e4 commit d2b8b33
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
26 changes: 26 additions & 0 deletions code/python/cni_tlbx/gadgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ def size(x,length):

return out.astype(int)

def stimpad(stimulus):
'''
Parameters
----------
stimulus: floating point array (height by width by samples)
Returns
-------
padded_stimulus: floating point array (height by width by samples)
zero padded stimulus
'''

height, width, samples = stimulus.shape
res = np.maximum(width,height)

padded_stimulus = np.zeros((res,res,samples))

height_lower = int((res - height) / 2)
height_upper = height_lower + height
width_lower = int((res - width) / 2)
width_upper = width_lower + width
padded_stimulus[height_lower:height_upper,
width_lower:width_upper,:] = stimulus

return padded_stimulus

def regress(Y, X, l = 0.):
'''
Parameters
Expand Down
36 changes: 21 additions & 15 deletions code/python/cni_tlbx/pRF.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tkinter import filedialog
from scipy.stats import zscore
from scipy.fft import fft, ifft
from cni_tlbx.gadgets import two_gamma, gaussian
from cni_tlbx.gadgets import two_gamma, gaussian, stimpad


class pRF:
Expand All @@ -40,7 +40,8 @@ class pRF:
- n_rows : number of rows (in-plane resolution)
- n_cols : number of columns (in-plance resolution)
- n_slices : number of slices
- r_stimulus: resolution (=width=height) of stimulus in pixels
- h_stimulus: height of stimulus in pixels
- w_stimulus: width of stimulus in pixels
Optional inputs are
- hrf : either a vector containing a single hemodynamic response used for every voxel;
Expand Down Expand Up @@ -73,7 +74,9 @@ def __init__(self, parameters, hrf=None):
self.n_cols = parameters['n_cols']
self.n_slices = parameters['n_slices']
self.n_total = self.n_rows * self.n_cols * self.n_slices
self.r_stimulus = parameters['r_stimulus']
self.h_stimulus = parameters['h_stimulus']
self.w_stimulus = parameters['w_stimulus']
self.r_stimulus = np.maximum(self.h_stimulus, self.w_stimulus)

if hrf is not None:
self.l_hrf = hrf.shape[0]
Expand Down Expand Up @@ -165,11 +168,13 @@ def set_stimulus(self, stimulus):
----------
stimulus : floating point array
'''
if stimulus.ndim == 3:
self.stimulus = np.reshape(
stimulus, (self.r_stimulus**2, self.n_samples))
else:
self.stimulus = stimulus
if stimulus.ndim < 3:
stimulus = np.reshape(stimulus,
(self.h_stimulus, self.w_stimulus, self.n_samples))

stimulus = stimpad(stimulus)
self.stimulus = np.reshape(
stimulus, (self.r_stimulus**2, self.n_samples))
self.stimulus = np.hstack((self.stimulus,
np.zeros((self.r_stimulus**2, self.l_hrf))))

Expand All @@ -181,20 +186,21 @@ def import_stimulus(self):

files = glob.glob('%s/*.png' % stimulus_directory)

self.stimulus = np.zeros((self.r_stimulus,
self.r_stimulus,
stimulus = np.zeros((self.h_stimulus,
self.w_stimulus,
self.n_samples))

for f in files:
number = int(''.join([str(s) for s in f if s.isdigit()]))
img = cv2.imread(f)
self.stimulus[:, :, number] = img[:, :, 0]
stimulus[:, :, number] = img[:, :, 0]

mn = np.min(self.stimulus)
mx = np.max(self.stimulus)
self.stimulus = (self.stimulus - mn) / (mx - mn)
mn = np.min(stimulus)
mx = np.max(stimulus)
stimulus = (stimulus - mn) / (mx - mn)
stimulus = stimpad(stimulus)

self.stimulus = np.reshape(self.stimulus,
self.stimulus = np.reshape(stimulus,
(self.r_stimulus**2,
self.n_samples))

Expand Down

0 comments on commit d2b8b33

Please sign in to comment.