Exemplo n.º 1
0
def __plot_rF_curve(
	rf,
	patch_width,
	mode,
	p,
	theta,
	ax,
	fixed_axis_x=False,
	interp_smooth=140,
	):
	from receptivefield import convert_rfvector_to_rgbmatrix
	rf_m = convert_rfvector_to_rgbmatrix(rf, patch_width, patch_width, mode, swap=False, flip=False)
	X = N.arange(0, patch_width, 1)
	X_smooth = N.linspace(0, patch_width-1, interp_smooth)

	real_mu = (N.round(p[0]), N.round(p[1]))
	mu = real_mu[0] if fixed_axis_x else real_mu[1]
	
	if fixed_axis_x:
		coords = [(i, mu) for i in xrange(0, patch_width)]
	else:
		coords = [(mu, i) for i in xrange(0, patch_width)]

	r_coords = [rot(theta, (c[0],c[1]), real_mu) for c in coords]
	r_coords = [(round(c[0]),round(c[1])) for c in r_coords]

	def rot_values(channel, rotated_coords):
		return N.array([rf_m.T[channel][c[0],c[1]] for c in rotated_coords])

	from scipy.interpolate import interp1d
	def interp(values):
		return interp1d(X, values, kind='cubic')
	
	plt.ylim(-1., 1.)

	if mode=='rgb':
		ax.plot(X_smooth, interp(rot_values(0, r_coords))(X_smooth), color='red', linewidth=2.0)
		ax.plot(X_smooth, interp(rot_values(1, r_coords))(X_smooth), color='green', linewidth=2.0)
		ax.plot(X_smooth, interp(rot_values(2, r_coords))(X_smooth), color='blue', linewidth=2.0)
	elif mode=='rg' or mode=='rg_vs_b':
		ax.plot(X_smooth, interp(rot_values(0, r_coords))(X_smooth), color='red', linewidth=2.0)
		ax.plot(X_smooth, interp(rot_values(1, r_coords))(X_smooth), color='green', linewidth=2.0)
	elif mode=='lum':
		ax.plot(X_smooth, interp(rot_values(0, r_coords))(X_smooth), color='black', linewidth=2.0)

	ax.set_aspect(patch_width/2)
	return mu
Exemplo n.º 2
0
def write_rf_fit_debug_fig(
	outfile,
	rf,
	patch_width,
	mode,
	p=None,
	rf_reconstr=None,
	rf_reconstr_err=None,
	model='dog',
	scale=2,
	s_scale=None,
	alpha=1.,
	dpi=216,
	draw_ellipsoid=True,
	title=None,
	no_title=False,
	ellipsoid_line_width=.5,
	):
	rf_name = title if title != None else 'RF'
	rec_name = title + 'rec. ' if title != None else 'rec.'

	if s_scale == None:	s_scale = scale

	cmap = colormap_for_mode(mode)
	from receptivefield import convert_rfvector_to_rgbmatrix
	from ..analyze.cluster import __transpose_zero_to_one
	rf_mat = convert_rfvector_to_rgbmatrix(rf, patch_width, patch_width, mode, swap=True, flip=False)
	rf_mat = __transpose_zero_to_one(rf_mat)
	dic_rf = {'name':'' if no_title else rf_name, 'value':rf_mat, 'maxmin':False, 'cmap':cmap, 'balance':False}
	mu_x, mu_y = 0, 0
	theta = 0

	if not p is None:
		if model=='dog':
			'''     0     1     2        3       ...
			params: mu_x  mu_y  r_c  	 r_s     ...'''
			mu_x, mu_y = p[1], p[0]
			theta = 0
			rhc, rwc = p[2], p[2]
			rhs, rws = p[3], p[3]
		elif model=='edog':
			'''     0     1     2        3        4             5      ...
			params: mu_x  mu_y  sigma_x  sigma_y  c_to_s_ratio  theta  ...'''			
			if p[4] > 1: rwc=p[2]*scale ; 	   rhc=p[3]*scale ; 	 rws=p[2]*p[4]*s_scale ; 	rhs=p[3]*p[4]*s_scale
			else:		 rwc=p[2]*p[4]*scale ; rhc=p[3]*p[4]*scale ; rws=p[2]*s_scale ; 	   	rhs=p[3]*s_scale
			mu_x, mu_y = p[1], p[0]
			theta = p[5]


		theta = N.pi-180/N.pi*theta
		ellip_c = [mu_x, mu_y, rwc, rhc, -theta, ellipsoid_line_width, [.0,.0,.0], 'none']
		ellip_s = [mu_x, mu_y, rws, rhs, -theta, ellipsoid_line_width, [.0,.0,.0], 'none']
		dic_rf['theta'] = theta
		dic_rf['patch_width'] = patch_width


	plots = [dic_rf]


	if not p is None and draw_ellipsoid:
		nones = N.ones(rf_mat.shape)
		dic_ellip = {'name':'' if no_title else 'fit', 'value':nones, 'maxmin':False, 'cmap':'Greys', 'balance':False, 'invertaxis':True, 
		'theta':theta, 'patch_width':patch_width, 'drawlines':True}
		dic_ellip['ellipsoid_c'] = ellip_c
		dic_ellip['ellipsoid_s'] = ellip_s	
		plots = plots + [dic_ellip]

	if True:
		h_dic_curve = {'name':'' if no_title else 'primary axis', 'value':rf, 'mu_xy':(mu_x,mu_y), 'theta':theta, 'patch_width':patch_width, 'horizontal':False, 'mode':mode, 'drawlines':True}
		plots = plots + [h_dic_curve]
		w_dic_curve = {'name':'' if no_title else 'secondary axis', 'value':rf, 'mu_xy':(mu_x,mu_y), 'theta':theta, 'patch_width':patch_width, 'horizontal':True, 'mode':mode, 'drawlines':True}
		plots = plots + [w_dic_curve]


	if not rf_reconstr is None:
		rec_mat = convert_rfvector_to_rgbmatrix(rf_reconstr, patch_width, patch_width, mode, swap=True, flip=False)
		rec_mat = __transpose_zero_to_one(rec_mat)
		dic_rec = {'name':'' if no_title else rec_name, 'value':rec_mat, 'maxmin':False, 'cmap':cmap, 'balance':False}
		dic_rec['theta'] = theta
		dic_rec['patch_width'] = patch_width

	

		plots = plots + [dic_rec]

		if not rf_reconstr_err is None:
			err_mat = convert_rfvector_to_rgbmatrix(rf_reconstr_err, patch_width, patch_width, mode, swap=True, flip=False)
			err_mat = __transpose_zero_to_one(err_mat)
			str_err = str(N.round(N.max(rf_reconstr_err),6))
			dic_err = {'name':'' if no_title else 'error '+str_err, 'value':err_mat, 'maxmin':False, 'cmap':cmap, 'balance':True, 'invertaxis':True}
			plots = plots + [dic_err]

		if True:
			h_dic_curve = {'name':'' if no_title else 'primary axis', 'value':rf_reconstr, 'mu_xy':(mu_x,mu_y), 'theta':theta, 'patch_width':patch_width, 'horizontal':False, 'mode':mode, 'drawlines':True}
			plots = plots + [h_dic_curve]
			w_dic_curve = {'name':'' if no_title else 'secondary axis', 'value':rf_reconstr, 'mu_xy':(mu_x,mu_y), 'theta':theta, 'patch_width':patch_width, 'horizontal':True, 'mode':mode, 'drawlines':True}
			plots = plots + [w_dic_curve]


	write_row_col_fig(plots, 2, 4, outfile, dpi=dpi, alpha=1.0, fontsize=5.5, no_labels=no_title)
	print 'file:', outfile, 'written.'