def generate_task_kinematics(tasks=None, mv={}, n_bins=100): '''Creates simulated positional data for a set of tasks. ''' assert tasks.shape[1] % 2 == 0 mv_defaults = {'curvature' : 1., 'center' : 0.5, 'fwhm' : 0.2} mv = myutils.dparse(mv_defaults, mv) speed = generate_speed_profile(n_bins=n_bins, fwhm=mv['fwhm'], center=mv['center']) pos = calc_pos_along_movement(speed, tasks, mv['curvature'], mv['center']) return pos
def do_tasks2(tasks=None, model='kds', mv={}, k={}, tau={}, PD=None, PG=None, PDb=None, n_bins=200, full_output=True): '''Creates firing rates for each direction requested. Parameters ---------- tasks : array_like (n_tasks, 2 * n_dims) array of start positions and targets, n lots of [x_s, y_s, z_s, x_t, y_t, z_t] model : string code for model to use, see module docstring for description mv : dictionary optional movement parameters curvature, float, default 1.0 center, float, default 0.5 fwhm, float, default 0.2 k : dictionary coefficients of model term coefficients tau : dictionary lags of firing rate components PD : sequence, shape (3,) or None, default None preferred direction of the cell PG : sequence, shape (3,) or None, default None positional gradient of the cell PDb : sequence, shape (3,) or None, default None final preferred direction, used for changing PD n_bins : int, default 200 number of time points to model in each movement full_output : bool, default True display lots of output during computation Returns ------- speed : ndarray, shape = (n_pts,) dirnames : list string codes for each direction, in order found in frs frs, masked array, shape = (n_dirs, n_pts - 1) firing rates in each of the directions all_pos : ndarray, shape = (n_dirs, n_pts, 3) positions during movements in each of the directions ''' assert type(tasks) == np.ndarray assert type(model) == str assert type(k) == type(tau) == dict assert tasks.shape[1] % 2 == 0 mv_defaults = {'curvature' : 1., 'center' : 0.5, 'fwhm' : 0.2} mv = myutils.dparse(mv_defaults, mv) k_defaults = {'k' : 1., 'p' : 1., 'd' : 1., 'v' : 1., 's' : 1., 'n' : 100, 'F' : 1.} k = myutils.dparse(k_defaults, k) tau_defaults = {'p' : 0} tau = myutils.dparse(tau_defaults, tau) # global properties speed = generate_speed_profile(n_bins=n_bins, fwhm=mv['fwhm'], center=mv['center']) n_dirs = tasks.shape[0] #n_dims = tasks.shape[1] / 2 # preferred direction if PD == None: PD = generate_cell_property('PD') if PG == None: PG = generate_cell_property('PG') if ('X' in model): if PDb == None: PDb = generate_cell_property('PDb') PD = sim_rates.generate_changing_PD(PD, PDb, n_bins) pds = PD.repeat(n_dirs).reshape(n_bins, 3, n_dirs).transpose([2,0,1]) else: pds = PD.repeat(n_dirs * n_bins).reshape(3, n_dirs, n_bins).transpose([1,2,0]) # initialize storage variables frs = np.ma.empty((n_dirs, n_bins)) #all_pos = np.empty((n_dirs, n_bins, 3)) + np.nan starts = np.tile(tasks[:,:3], n_bins).reshape(n_dirs, n_bins, 3) stops = np.tile(tasks[:,3:], n_bins).reshape(n_dirs, n_bins, 3) pos = calc_pos_along_movement(speed, tasks, mv['curvature'], mv['center']) #pos_mids = calc_pos_along_movement(speed_mids, tasks, # mv['curvature'], mv['center']) # loop over targets for i_dir, task in enumerate(tasks): if ('N' in model) and ('k' in model): k['k'] *= np.random.normal(loc=1., scale=k['N']) frs[i_dir] = sim_rates.generate_firing_rate2(pos[i_dir], #dirs_inst[i_dir], speed, PD, PG, k=k, tau=tau, model=model) if full_output: return speed, frs, pos, pds, starts, stops else: return speed, frs, pos