def make_vague(impulse=False): import os import numpy as np import MotionClouds as mc mc.N_X, mc.N_Y, mc.N_frame = 50, 2, 2048 fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) theta, B_theta = 0., np.pi / 8. alpha, sf_0, B_sf, B_V = 1., .02, .1, .1 seed = 1234565 V_X, V_Y = .1, 0. mc_wave = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha) wave = mc.random_cloud(mc_wave, seed=seed, impulse=impulse) wave -= wave.mean() wave /= np.abs(wave).max() return wave
def MotionCloudNoise(sf_0=0.125, B_sf=3., figure_type='', save=False): mc.N_X, mc.N_Y, mc.N_frame = 128, 128, 1 fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) name = 'static' env = mc.envelope_gabor(fx, fy, ft, sf_0=sf_0, B_sf=B_sf, B_theta=np.inf, V_X=0., V_Y=0., B_V=0, alpha=.5) z = mc.rectif(mc.random_cloud(env)) z = z.reshape((mc.N_X, mc.N_Y)) if figure_type == 'cmap': fig, ax = plt.subplots(figsize=(13, 10.725)) cmap = ax.pcolor(np.arange(-mc.N_X / 2, mc.N_X / 2), np.arange(-mc.N_X / 2, mc.N_X / 2), MotionCloudNoise(), cmap='Greys_r') fig.colorbar(cmap) if save: plt.savefig('motioncloud_noise.pdf') return fig, ax else: return z
def source(dim, bwd): """ Create motion cloud source """ fx, fy, ft = dim z = mc.envelope_gabor(fx, fy, ft, B_sf=bwd[0], B_V=bwd[1], B_theta=bwd[2]) data = mc.rectif(mc.random_cloud(z)) return data
def envelope_gabor_wave(fx, fy, ft, V_X=mc.V_X, V_Y=mc.V_Y, B_V=mc.B_V, B_v=1., sf_0=mc.sf_0, B_sf=mc.B_sf, loggabor=mc.loggabor, theta=mc.theta, B_theta=mc.B_theta, alpha=mc.alpha): """ Returns the Motion Cloud kernel """ envelope = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, sf_0=sf_0, B_sf=B_sf, loggabor=loggabor, theta=theta, B_theta=B_theta, alpha=alpha) envelope *= envelope_gravitational(fx, fy, ft, B_v=B_v) return envelope
def envelope_gabor_wave(fx, fy, ft, B_wave, V_X=mc.V_X, V_Y=mc.V_Y, B_V=mc.B_V, B_v=1., sf_0=mc.sf_0, B_sf=mc.B_sf, loggabor=mc.loggabor, theta=mc.theta, B_theta=mc.B_theta, alpha=mc.alpha): """ Returns the Motion Cloud kernel """ envelope = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, sf_0=sf_0, B_sf=B_sf, loggabor=loggabor, theta=theta, B_theta=B_theta, alpha=alpha) envelope *= envelope_gravity(fx, fy, ft, B_wave=B_wave) return envelope
def generate_random_cloud(theta, B_theta, downscale=1): fx, fy, ft = mc.get_grids(mc.N_X / downscale, mc.N_Y / downscale, 1) mc_i = mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0., B_V=0, theta=theta, B_theta=B_theta) im = mc.random_cloud(mc_i) im = (mc.rectif(im) * 255).astype('uint8') fname = 'tmp/%s_%s.png' % (theta, B_theta) imageio.imwrite(fname, im[:, :, 0]) return fname
def generate_cloud(theta, b_theta, sf_0, N_X, N_Y, seed, contrast=1): fx, fy, ft = mc.get_grids(N_X, N_Y, 1) mc_i = mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0., B_V=0., sf_0=sf_0, B_sf=sf_0, theta=theta, B_theta=b_theta) im_ = mc.rectif(mc.random_cloud(mc_i, seed=seed), contrast=contrast) return im_[:, :, 0]
def make_vague(impulse=False): import os import numpy as np import MotionClouds as mc mc.N_X, mc.N_Y, mc.N_frame = 50, 2, 2048 fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) theta, B_theta = 0., np.pi/8. alpha, sf_0, B_sf, B_V = 1., .02, .1, .1 seed = 1234565 V_X, V_Y = .1, 0. mc_wave = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha) wave = mc.random_cloud(mc_wave, seed=seed, impulse=impulse) wave -= wave.mean() wave /= np.abs(wave).max() return wave
def wave(self): filename = f'{self.cachepath}/{self.opt.tag}_wave.npy' if self.opt.cache and os.path.isfile(filename): z = np.load(filename) else: # A simplistic model of a wave using https://github.com/NeuralEnsemble/MotionClouds import MotionClouds as mc fx, fy, ft = mc.get_grids(self.opt.nx, self.opt.ny, self.opt.nframe) env = mc.envelope_gabor(fx, fy, ft, V_X=self.opt.V_Y, V_Y=self.opt.V_X, B_V=self.opt.B_V, sf_0=self.opt.sf_0, B_sf=self.opt.B_sf, theta=self.opt.theta, B_theta=self.opt.B_theta) z = mc.rectif(mc.random_cloud(env, seed=self.opt.seed)) if self.opt.cache: np.save(filename, z) return z
def creation_stimulus(info, screen, param, name_database='blackwhite'): import MotionClouds as mc from MotionClouds.display import rectif # from libpy import lena if (param.condition == 1): stimulus = (np.random.rand(info[NS_X]/2, info[NS_Y]/2) > .5) # stimulus = (np.random.rand(64, 64) > .5) elif (param.condition == 2): im = Image(ParameterSet({'N_X' : info[NS_X], 'N_Y' : info[NS_Y], 'figpath':'.', 'matpath':'.', 'datapath':'database/', 'do_mask':False, 'seed':None})) stimulus, filename, croparea = im.patch(name_database) # stimulus = lena() stimulus = np.rot90(np.fliplr(stimulus)) stimulus = rectif(stimulus, contrast=1.) else: fx, fy, ft = mc.get_grids(info[NS_X], info[NS_Y], 1) if (param.condition == 3): t, b, B_sf, sf_0 = 0, np.pi/32, 0.1, 0.15 if (param.condition == 4): t, b, B_sf, sf_0= 0, np.pi/8, 0.1, 0.15 if (param.condition == 5): t, b, B_sf, sf_0= 0, np.pi/2, 0.1, 0.15 if (param.condition == 6): t, b, B_sf, sf_0= 0, np.pi/32, 0.1, 0.03 if (param.condition == 7): t, b, B_sf, sf_0= 0, np.pi/32, 0.1, 0.075 if (param.condition == 8): t, b, B_sf, sf_0= 0, np.pi/32, 0.25, 0.15 if (param.condition == 9): t, b, B_sf, sf_0= 0, np.pi/32, 0.5, 0.15 fx, fy, ft = mc.get_grids(info[NS_X], info[NS_Y], 1) cloud = mc.random_cloud(mc.envelope_gabor(fx, fy, ft, sf_0=sf_0, B_sf=B_sf, theta=t, B_theta=b, B_V=1000.)) cloud = rectif(cloud, contrast=1.) stimulus = cloud[:, :, 0] return (stimulus)
import matplotlib.pyplot as plt import Image import math name = 'contrast_methods-' #initialize fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) color = mc.envelope_color(fx, fy, ft) ext = '.zip' contrast = 0.25 B_sf = 0.3 for method in ['Michelson', 'energy']: z = color * mc.envelope_gabor(fx, fy, ft, B_sf=B_sf) name_ = mc.figpath + name + method + '-contrast-' + str(contrast).replace('.', '_') + '-B_sf-' + str(B_sf).replace('.','_') if mc.anim_exist(name_): im = np.ravel(mc.random_cloud(z)) im_norm = mc.rectif(mc.random_cloud(z), contrast, method=method, verbose=True) plt.figure() plt.subplot(111) plt.title('Michelson normalised Histogram Ctr: ' + str(contrast)) plt.ylabel('pixel counts') plt.xlabel('grayscale') bins = int((np.max(im_norm[:])-np.min(im_norm[:])) * 256) plt.xlim([0, 1]) plt.hist(np.ravel(im_norm), bins=bins, normed=False, facecolor='blue', alpha=0.75) plt.savefig(name_)
""" try: if mc.notebook: print('we are in the notebook') except: import os import MotionClouds as mc import numpy as np name = 'grating' #initialize fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) color = mc.envelope_color(fx, fy, ft) z = color * mc.envelope_gabor(fx, fy, ft) mc.figures(z, name) # explore parameters for sigma_div in [1, 2, 3, 5, 8, 13 ]: name_ = name + '-largeband-B_theta-pi-over-' + str(sigma_div).replace('.', '_') z = color * mc.envelope_gabor(fx, fy, ft, B_theta=np.pi/sigma_div) mc.figures(z, name_) for div in [1, 2, 4, 3, 5, 8, 13, 20, 30]: name_ = name + '-theta-pi-over-' + str(div).replace('.', '_') z = color * mc.envelope_gabor(fx, fy, ft, theta=np.pi/div) mc.figures(z, name_) V_X = 1.0 for sigma_div in [1, 2, 3, 5, 8, 13 ]:
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) name = 'MotionPlaid' vext = '.gif' # show example table = """ #acl LaurentPerrinet,LaurentPerrinetGroup:read,write,delete,revert All: #format wiki ----- = MotionPaids : from MotionClouds components to a plaid-like stimulus = """ theta1, theta2, B_theta = np.pi/4., -np.pi/4., np.pi/32 diag1 = mc.envelope_gabor(fx, fy, ft, theta=theta1, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_theta=B_theta) diag2 = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta2), V_Y=np.sin(theta2), B_theta=B_theta) name_ = name + '_comp1' mc.figures(diag1, name_, vext=vext, seed=12234565) table += '||<width="33%">{{attachment:' + name_ + '.png||width=100%}}||<width="33%">{{attachment:' + name_ + '_cube.png||width=100%}}||<width="33%">{{attachment:' + name_ + '.gif||width=100%}}||\n' name_ = name + '_comp2' mc.figures(diag2, name_, vext=vext, seed=12234565) table += '||{{attachment:' + name_ + '.png||width=100%}}||{{attachment:' + name_ + '_cube.png||width=100%}}||{{attachment:' + name_ + '.gif||width=100%}}||\n' name_ = name mc.figures(diag1 + diag2, name, vext=vext, seed=12234565) table += '||{{attachment:' + name_ + '.png||width=100%}}||{{attachment:' + name_ + '_cube.png||width=100%}}||{{attachment:' + name_ + '.gif||width=100%}}||\n' table += '||||||<align="justify"> This figure shows how one can create !MotionCloud stimuli that specifically target component and pattern cell. We show in the different lines of this table respectively: Top) one motion cloud component (with a strong selectivity toward the orientation perpendicular to direction) heading in the upper diagonal Middle) a similar motion cloud component following the lower diagonal Bottom) the addition of both components: perceptually, the horizontal direction is predominant. <<BR>> Columns represent isometric projections of a cube. The left column displays iso-surfaces of the spectral envelope by displaying enclosing volumes at 5 different energy values with respect to the peak amplitude of the Fourier spectrum. The middle column shows an isometric view of the faces of the movie cube. The first frame of the movie lies on the x-y plane, the x-t plane lies on the top face and motion direction is seen as diagonal lines on this face (vertical motion is similarly see in the y-t face). The third column displays the actual movie as an animation. ||\n' table += '\n\n' table += '== exploring different component angles ==\n'
# Setting up the conditions: condList = data.importConditions(conditionsFilePath) grtList = [] for thisCondition in condList: # grating name: grtSz = thisCondition['szL'] thisSf = thisCondition['sfL'] thisBsf = thisCondition['BsfL'] if thisCondition['dirL'] < 0: # this means clockwise or CCW motion thisV = 0 else: # translational motion thisV = thisCondition['vL'] thisBv = thisCondition['BvL'] grtName = precompiledDir + os.sep + 'mc_' + str(thisV) + '_sf' + str(thisSf) + \ '_bsf' + str(thisBsf) + '_bv' + str(thisBv) + '_sz' + str(grtSz) if grtName not in grtList: grtList.append(grtName) # compiling the gratings: szX = grtSz szY = szX fx, fy, ft = mc.get_grids(szX, szY, nFrames) grtCol = mc.envelope_color(fx, fy, ft) z = mc.envelope_gabor(fx, fy, ft, sf_0=thisSf, B_sf=thisBsf, V_X=thisV, B_V=thisBv, B_theta=np.inf) zcl = mc.random_cloud(grtCol * z) grtL = 2*mc.rectif(zcl) - 1 # saving the gratings: np.save(grtName, grtL) # mc.figures(grtL, grtName, vext='.mkv') print 'precompiled ' + grtName
return w # Tukey mask - fading effect tw_x = tukey(n=n_x, r=0.15) tw_y = tukey(n=n_y, r=0.15) w = np.tile(((np.outer(tw_y,tw_x))), (N_frame,1,1)) tukey_mask = w.T # Get Random Clouds name_ = mc.figpath + name for seed in [123456 + step for step in range(seeds)]: name__ = mc.figpath + name + '-seed-' + str(seed) + '-sf0-' + str(sf_0).replace('.', '_') + '-V_X-' + str(V_X).replace('.', '_') # broadband z = mc.envelope_gabor(fx, fy, ft, name_, B_sf=Bsf, sf_0=sf_0, theta=theta, B_V=B_V, B_theta = B_theta, alpha=alpha) movie = mc.figures(z, name=None, vext=vext, seed=seed, masking=True) for label, mask in zip(['_mask', '_tukey_mask'], [gauss, tukey_mask]): name_ = name__ + '-cloud-' + label if anim_exist(name_): movie = mc.rectif(movie*mask) mc.anim_save(movie, name_, display=False, vext=vext) # narrowband z = mc.envelope(fx, fy, ft, name_, B_sf=B_sf/10., sf_0=sf_0, theta=theta, B_V=B_V, B_theta=B_theta, alpha=alpha) movie = mc.figures(z, name=None, vext=vext, seed=seed, masking=True) for label, mask in zip(['_mask', 'tukey_mask'], [gauss, tukey_mask]): name_ = name__ + '-blob-' + label if anim_exist(name_): movie = mc.rectif(movie*mask) mc.anim_save(movie, name_, display=False, vext=vext)
vext = '.gif' B_sf = .3 B_theta = np.pi/32 # show example table = """ #acl LaurentPerrinet,LaurentPerrinetGroup:read,write,delete,revert All:read #format wiki ----- = SlippingClouds: MotionClouds for exploring the aperture problem = """ theta1, theta2 = 0., np.pi/2. diag = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_sf=B_sf, B_theta=B_theta) name_ = name + '_iso' mc.figures(diag, name_, vext=vext, seed=12234565) table += '||{{attachment:' + name_ + '.png||width=100%}}||{{attachment:' + name_ + '_cube.png||width=100%}}||{{attachment:' + name_ + '.gif||width=100%}}||\n' theta1, theta2 = 0., np.pi/4. diag = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_sf=B_sf, B_theta=B_theta) name_ = name + '_diag' mc.figures(diag, name_, vext=vext, seed=12234565) table += '||{{attachment:' + name_ + '.png||width=100%}}||{{attachment:' + name_ + '_cube.png||width=100%}}||{{attachment:' + name_ + '.gif||width=100%}}||\n' theta1, theta2 = 0., np.pi/2. diag = mc.envelope_gabor(fx, fy, ft, theta=theta2, V_X=np.cos(theta1), V_Y=np.sin(theta1), B_sf=B_sf, B_theta=B_theta) name_ = name + '_contra' mc.figures(diag, name_, vext=vext, seed=12234565) table += '||<width="33%">{{attachment:' + name_ + '.png||width=100%}}||<width="33%">{{attachment:' + name_ + '_cube.png||width=100%}}||<width="33%">{{attachment:' + name_ + '.gif||width=100%}}||\n'
info['timeStr'] = time.strftime("%b_%d_%H%M", time.localtime()) fileName = 'data/' + experiment + info['observer'] + '_' + info['timeStr'] + '.pickle' #save to a file for future use (ie storing as defaults) if dlg.OK: misc.toFile(fileName, info) else: print('Interrupted gui... quitting') core.quit() #user cancelled. quit print('generating data') fx, fy, ft = mc.get_grids(info['N_X'], info['N_Y'], info['N_frame_total']) color = mc.envelope_color(fx, fy, ft) up = 2*mc.rectif(mc.random_cloud(color * mc.envelope_gabor(fx, fy, ft, V_X=+.5))) - 1 down = 2*mc.rectif(mc.random_cloud(color * mc.envelope_gabor(fx, fy, ft, V_X=-.5))) - 1 print('go! ') win = visual.Window([info['screen_width'], info['screen_height']], fullscr=True) stim = visual.GratingStim(win, size=(info['screen_height'], info['screen_height']), units='pix', interpolate=True, mask = 'gauss', autoLog=False)#this stim changes too much for autologging to be useful wait_for_response = visual.TextStim(win, text = u"?", units='norm', height=0.15, color='DarkSlateBlue', pos=[0., -0.], alignHoriz='center', alignVert='center' ) wait_for_next = visual.TextStim(win,
# show example table = """ #acl LaurentPerrinet,LaurentPerrinetGroup:read,write,delete,revert All:read #format wiki ----- = Recruiting different population ratios in V1 using MotionClouds' orientation components = """ theta, B_theta_low, B_theta_high = np.pi/4., np.pi/32, 2*np.pi B_V = 10. seed=12234565 mc1 = mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0., theta=theta, B_V=B_V, B_theta=B_theta_low) mc2 = mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0., theta=theta, B_V=B_V, B_theta=B_theta_high) name_ = name + '_comp1' mc.figures(mc1, name_, vext=vext, seed=seed) table += '||<width="33%">{{attachment:' + name_ + '.png||width=100%}}||<width="33%">{{attachment:' + name_ + '_cube.png||width=100%}}||<width="33%">{{attachment:' + name_ + '.gif||width=100%}}||\n' name_ = name + '_comp2' mc.figures(mc2, name_, vext=vext, seed=seed) table += '||{{attachment:' + name_ + '.png||width=100%}}||{{attachment:' + name_ + '_cube.png||width=100%}}||{{attachment:' + name_ + '.gif||width=100%}}||\n' table += '||||||<align="justify"> This figure shows how one can create !MotionCloud stimuli that specifically target different population in V1. We show in the two lines of this table motion cloud component with a (Top) narrow orientation bandwith (Bottom) a wide bandwitdh: perceptually, there is no predominant position or speed, just different orientation contents. <<BR>> Columns represent isometric projections of a cube. The left column displays iso-surfaces of the spectral envelope by displaying enclosing volumes at 5 different energy values with respect to the peak amplitude of the Fourier spectrum. The middle column shows an isometric view of the faces of the movie cube. The first frame of the movie lies on the x-y plane, the x-t plane lies on the top face and motion direction is seen as diagonal lines on this face (vertical motion is similarly see in the y-t face). The third column displays the actual movie as an animation. ||\n' table += '\n\n' table += '== exploring different orientation bandwidths ==\n' # make just a line
name = 'concentric' play = False #True play = True #initialize fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) color = mc.envelope_color(fx, fy, ft) name_ = mc.figpath + name seed = 123456 im = np.zeros((mc.N_X, mc.N_Y, mc.N_frame)) name_ = mc.figpath + name N = 20 if mc.anim_exist(name_): for i_N in xrange(N): im_ = mc.random_cloud(color * mc.envelope_gabor(fx, fy, ft, V_X=0., V_Y=0.), seed=seed+i_N) if i_N == 0: phase = 0.5 + 0. * im_[0, 0, :]#mc.N_X/2, mc.N_Y/2, :] #im += im_ - im_[mc.N_X/2, mc.N_Y/2, :] + phase im += im_ - im_[0, 0, :] + phase if play: mc.play(mc.rectif(im)) else: mc.anim_save(mc.rectif(im), name_) # mplayer figures/concentric.mpg -fs -loop 0
# uncomment to preview movies #ext, display = None, True #initialize fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) #fx, fy, ft = mc.get_grids(256, 256, 256) #fx, fy, ft = mc.get_grids(512, 512, 128) color = mc.envelope_color(fx, fy, ft) name_ = mc.figpath + name # explore parameters for B_sf in [0.025, 0.05, 0.1, 0.2, 0.4, 0.8]: name_ = mc.figpath + name + '-B_sf' + str(B_sf).replace('.', '_') if mc.anim_exist(name_, vext=vext): z = color * mc.envelope_gabor(fx, fy, ft, B_sf=B_sf, B_theta=np.inf) # mc.visualize(z, name=name_ + '_envelope') im = mc.rectif(mc.random_cloud(z)) # mc.cube(im, name=name_ + '_cube') mc.anim_save(im, name_, display=False, vext=vext) # mc.anim_save(im, name_, display=False, vext='.gif') if DEBUG: # control enveloppe's shape z_low = mc.envelope_gabor(fx, fy, ft, B_sf=0.037, loggabor=False) z_high = mc.envelope_gabor(fx, fy, ft, B_sf=0.15, loggabor=False) import pylab, numpy pylab.clf() fig = pylab.figure(figsize=(12, 12))
info['timeStr'] = time.strftime("%b_%d_%H%M", time.localtime()) fileName = 'data/discriminating_v2_' + info['observer'] + '_' + info['timeStr'] + '.pickle' #save to a file for future use (ie storing as defaults) if dlg.OK: misc.toFile(fileName, info) else: print('Interrupted gui... quitting') core.quit() #user cancelled. quit print('generating data') alphas = [-1., -.5, 0., 0.5, 1., 1.5, 2.] fx, fy, ft = mc.get_grids(info['N_X'], info['N_Y'], info['N_frame_total']) colors = [mc.envelope_color(fx, fy, ft, alpha=alpha) for alpha in alphas] slows = [2*mc.rectif(mc.random_cloud(color * mc.envelope_gabor(fx, fy, ft, V_Y=0., V_X = 1.1, B_sf = 10.))) - 1 for color in colors] fasts = [2*mc.rectif(mc.random_cloud(color * mc.envelope_gabor(fx, fy, ft, V_Y=0., V_X = 0.9, B_sf = 10.))) - 1 for color in colors] print('go! ') win = visual.Window([info['screen_width'], info['screen_height']], fullscr=True) stimLeft = visual.GratingStim(win, size=(info['screen_width']/2, info['screen_width']/2), pos=(-info['screen_width']/4, 0), units='pix', interpolate=True, mask = 'gauss', autoLog=False)#this stim changes too much for autologging to be useful stimRight = visual.GratingStim(win, size=(info['screen_width']/2, info['screen_width']/2),
fx, fy, ft = mc.get_grids(512, 512, 128) # L'envelope gabor du stimulus est généré, avec les paramètres : # * theta l'angle du stimulus # * b_theta l'ouverture des gabors (donc le niveau de bruit) # * sf_0 et b_sf les fréquences spatiales # In[3]: envelope = mc.envelope_gabor(fx, fy, ft, V_X=1., V_Y=0., B_V=.1, sf_0=.15, B_sf=.1, theta=np.pi / 3, B_theta=np.pi / 12, alpha=1.) # On génère le cloud # In[4]: movie = mc.random_cloud(envelope) movie = mc.rectif(movie) # Une image instantanée à t = 0
colOdd = [150,1,1] # green colEven = [330,sat,1] # red is adjusted and is assigned to gratings in even frames # initiating the gratings if precompileMode: grtL = np.load(precompiledDir + os.sep + 'mc_' + '{0:.1f}'.format(vL) + '_sf' + str(sfL) + '_bsf' + str(BsfL) + '_bv' + str(BvL) + '_sz' + str(szL) + '.npy') grtR = np.load(precompiledDir + os.sep + 'mc_' + '{0:.1f}'.format(vR) + '_sf' + str(sfR) + '_bsf' + str(BsfR) + '_bv' + str(BvR) + '_sz' + str(szR) + '.npy') else: fx, fy, ft = mc.get_grids(szL, szL, nFrames) grtCol = mc.envelope_color(fx, fy, ft) grtL = 2*mc.rectif(mc.random_cloud(grtCol * mc.envelope_gabor(fx, fy, ft, sf_0=sfL, B_sf=BsfL, B_V=BvL, V_X=vL, B_theta=np.inf))) - 1 fx, fy, ft = mc.get_grids(szR, szR, nFrames) grtCol = mc.envelope_color(fx, fy, ft) grtR = 2*mc.rectif(mc.random_cloud(grtCol * mc.envelope_gabor(fx, fy, ft, sf_0=sfR, B_sf=BsfR, B_V=BvR, V_X=vR, B_theta=np.inf))) - 1 # Creating a mask, which is fixed for a given trial: curMask = combinedMask(fovGap, fovFade, periGap, periFade) # Using the mask to assign both the greyscale values and the mask for our color masks: colMaskL.tex = (curMask + 1)/2 colMaskL.mask = curMask colMaskR.tex = (curMask + 1)/2 colMaskR.mask = curMask
import libpy as lb import numpy as np import sys, os import MotionClouds as mc h = 400 w = 200 f = 64 fx, fy, ft = mc.get_grids(h, w, f) color = mc.envelope_color(fx, fy, ft) env = color * mc.envelope_speed(fx, fy, ft) env = mc.envelope_gabor(fx, fy, ft) env = mc.random_cloud(env) env = mc.rectif(env, contrast=1.) tomat = env env = env * 255 stimulus = np.zeros([h, w, f, 3]).astype(int) i = 0 while (i != f): if (i % 2 == 0): stimulus[:, :, i, 0] = env[:, :, i] stimulus[:, :, i, 1] = 0 # 128 #env[:, :, i] stimulus[:, :, i, 2] = 0 # 255 - env[:, :, i] else: #stimulus[:, :, i, 0] = 255 - env[:, :, i] stimulus[:, :, i, 1] = 255 - env[:, :, i] stimulus[:, :, i, 0] = 0 #128 #env[:, :, i] stimulus[:, :, i, 2] = 0 #env[:, :, i] # stimulus[:, :, i, :] = 255 - env[:, :, i, np.newaxis]
#!/usr/bin/env python """ Superposition of MotionClouds to generate competing motions. (c) Laurent Perrinet - INT/CNRS """ import numpy import MotionClouds as mc fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) name = 'competing' name_ = mc.figpath + name if mc.anim_exist(name_): z = (.5*mc.envelope_gabor(fx, fy, ft, sf_0=0.2, V_X=-1.5) + .1*mc.envelope_gabor(fx, fy, ft, sf_0=0.4, V_X=.5)#, theta=numpy.pi/2.) ) mc.figures(z, name_) name = 'two_bands' name_ = mc.figpath + name if mc.anim_exist(name_): # and now selecting blobs: # one band one = mc.envelope_gabor(fx, fy, ft, B_theta=10.) # a second band two = mc.envelope_gabor(fx, fy, ft, sf_0=.9, B_theta=10.) mc.figures(one + two, name_)
# %% # %% hzn1 = mc.np.zeros((N_orient * N_X, N_orient * N_X, N_frame)) for i, x_i in enumerate(np.linspace(-1, 1., N_orient)): for j, x_j in enumerate(np.linspace(-1, 1., N_orient)): V_X = 2 * x_i / (1 + x_i**2) V_Y = 2 * x_j / (1 + x_j**2) # f_0 = ... # theta = np.arctan2(V_Y, V_X) env = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_theta=np.inf, B_sf=np.inf) speed2 = mc.random_cloud(env, seed=seed) hzn1[i * N_X:(i + 1) * N_X, j * N_Y:(j + 1) * N_Y, :] = speed2 # %% # since mc.rectif brings values in range 0 to 1, we need to multiply by 2 and # subtract 1 in order to get range -1 to 1, which psychopy needsZ z = 2 * mc.rectif(hzn1, contrast=1.0) - 1. # reverse z in third dimension z = z[:, :, ::-1]
# width and height of your screen w, h = 1920, 1200 w, h = 2560, 1440 # width and height of the stimulus w_stim, h_stim = 1024, 1024 loops = 1 import MotionClouds as mc print 'started get_grids' fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame) print 'started color' color = mc.envelope_color(fx, fy, ft) print 'started enveope' env = color *(mc.envelope_gabor(fx, fy, ft, V_X=1.) + mc.envelope_gabor(fx, fy, ft, V_X=-1.)) print 'started rectif' z = 2*mc.rectif(mc.random_cloud(env), contrast=.5) -1. print 'ended motion clouds' #from pyglet.gl import gl_info from psychopy import visual, core, event, logging logging.console.setLevel(logging.DEBUG) print 'started stim' win = visual.Window([w, h], fullscr=True) stim = visual.GratingStim(win, size=(w_stim, h_stim), units='pix', interpolate=True, mask='gauss', autoLog=False)#this stim changes too much for autologging to be useful
#import psychopy #import vispy #from vispy import scene #print(dir(mc)) #from vispy.visuals.transforms import STTransform,MatrixTransform # params: sf0 = 0.1 bsf = .05 vX = 9.6 vY = 0 bV = .5 theta = 60 bTheta = 1.27 #4/3.14 # define Fourier domain fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, 10) #mc.N_frame) # define an envelope envelope = mc.envelope_gabor(fx, fy, ft, V_X=vX, V_Y=vY, B_V=bV, sf_0=sf0, B_sf=bsf, theta=theta, B_theta=bTheta, alpha=1.) # Visualize the Fourier Spectrum #mc.visualize(envelope) #mc.figures(envelope,'test') movie=mc.random_cloud(envelope) movie=mc.rectif(movie) name = 'sf' + str(sf0) + '_bsf' + str(bsf) + '_vX' + str(vX) + '_vY' + str(vY) + '_bV' + str(bV) + '_th' + str(theta) + '_bTh' + str(bTheta) print name mypath = '/c/Users/Egor/Dropbox/Projects/mc/mc/test' #mc.cube(movie, name=name+'_cube') mc.anim_save(movie, name, display=False, vext='.mp4') #prev .mp4