#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ """ import numpy as np import matplotlib.pyplot as plt import genlinmod as glm import OMB_texturegenerator as ombtg exp = '20180710' stimnr = 8 steps = glm.loadstim(exp, stimnr) texture = ombtg.texture_generator() noiselim = ombtg.noiselim #texture = np.flipud(texture) #%% def clip_trajectory(stimulus, squaredim): pos_filter = np.where(stimulus > 0) neg_filter = not pos_filter out = np.zeros(stimulus.shape) out = np.fmod(stimulus, squaredim[:, np.newaxis] * 1.5, where=pos_filter) out = np.fmod(-stimulus, squaredim[:, np.newaxis] * 1.5, where=neg_filter) return out #clipped = clip_trajectory(stimulus, np.array([200, 200]))
#def conv(k, x): # return np.convolve(k, x, 'full')[:-k.shape[0]+1] def normalizestas(stas): stas = np.array(stas) b = np.abs(stas).max(axis=1) stas_normalized = stas / b.repeat(stas.shape[1]).reshape(stas.shape) return stas_normalized #%% exp_name = '20180802' stim_nr = 1 data = iof.load(exp_name, stim_nr) stimulus = glm.loadstim(exp_name, stim_nr) clusters = data['clusters'] #%% #stas = np.array(data['stas']) #stas_normalized = np.abs(stas).max(axis=1) #stas_normalized = a / stas_normalized.repeat(stas.shape[1]).reshape(stas.shape) frametimes = asc.ft_nblinks(exp_name, stim_nr)[1] #stas = normalizestas(data['stas']) stas = np.array(data['stas']) predstas = np.zeros(stas.shape) predmus = np.zeros(stas.shape[0]) start = dt.datetime.now() allspikes = np.zeros((stas.shape[0], frametimes.shape[0]), dtype=np.int8)
import analysis_scripts as asc expstim = ('20180802', 1) data = iof.load(*expstim) _, metadata = asc.read_spikesheet(expstim[0]) sta = data['stas'][3] filter_length = sta.shape[0] frame_rate = metadata['refresh_rate'] time_res = 1 / frame_rate tstop = data['total_frames'] * time_res t = np.arange(0, tstop, time_res) k_in = sta stim = glm.loadstim(*expstim) else: filter_length = 40 frame_rate = 60 time_res = (1 / frame_rate) tstop = 100 # simulation length in seconds t = np.arange(0, tstop, time_res) # Set the seed for PRNG for reproducibility np.random.seed(12221) # np.random.seed(45212) # sum is 0.01 for tstop=500 stim = np.random.normal(size=t.shape) tmini = t[:filter_length]
cross_corrs = np.zeros((fff.nclusters, xval_splits)) t = np.linspace(0, fff.filter_length * fff.frame_duration * 1000, fff.filter_length) plotlabels = ['Contrast'] # Temporary hack until FFF gets its own class. fff.readpars() if fff.param_file['Nblinks'] == 1: t_fff = np.linspace(0, fff.filter_length * fff.frame_duration * 1000, fff.filter_length * 2) else: t_fff = t stimulus = glm.loadstim(exp, fff_stimnr) for i, cluster in enumerate(fff.clusters): for xvi in range(xval_splits): sp_tr, sp_te, stim_tr, stim_te = train_test_split( all_spikes[i], stimulus, test_size=xval_fraction, split_pos=xval_fraction * xvi) res = glm.minimize_loglhd(np.zeros(fff.filter_length), 0, stim_tr, fff.frame_duration, sp_tr,