def _getstimtype(self):
        sortedstim = asc.stimulisorter(self.exp)

        for key, val in sortedstim.items():
            if self.stimnr in val:
                stimtype = key
        self.stimtype = stimtype
Exemple #2
0
from stripesurround import stripesurround
from checkerflickerplusanalyzer import checkerflickerplusanalyzer
from OMSpatchesanalyzer import OMSpatchesanalyzer
from OMBanalyzer import OMBanalyzer
from ombtexturestas import ombtexturesta
from saccadegratingsanalyzer import saccadegratingsanalyzer

# Attempt to read from stdin
try:
    exp_name = str(sys.argv[1])
except IndexError:
    exp_name = input('Enter the experiment name to be analyzed: ')

start_time = datetime.datetime.now().strftime('%A %X')
print(f'Analysis started on {start_time}')
sorted_stimuli = asc.stimulisorter(exp_name)

spontaneous = sorted_stimuli['spontaneous']
fullfieldflicker = sorted_stimuli['fff']
onoffsteps = sorted_stimuli['onoffsteps']
checkerflicker = sorted_stimuli['checkerflicker']
stripeflicker = sorted_stimuli['stripeflicker']
checkerflickerplus = sorted_stimuli['frozennoise'] + sorted_stimuli['checkerflickerplusmovie']
OMSpatches = sorted_stimuli['OMSpatches']
OMB = sorted_stimuli['OMB']
saccadegrating = sorted_stimuli['saccadegrating']

asc.saveframetimes(exp_name)

# %%
spontanalyzer(exp_name, spontaneous)
Exemple #3
0
def loadstim(exp, stim_nr, maxframenr=10000):
    """
    Recreate the stimulus based on the seed for a given stimulus type.

    Each type of stimulus requires a different way of handling the
    random numbers from the PRNG.
    """
    sortedstim = asc.stimulisorter(exp)
    clusters, metadata = asc.read_spikesheet(exp)
    pars = asc.read_parameters(exp, stim_nr)

    for key, val in sortedstim.items():
        if stim_nr in val:
            stimtype = key
    if stimtype in ['fff', 'stripeflicker', 'checkerflicker', 'frozennoise']:
        seed = pars.get('seed', -10000)
        bw = pars.get('blackwhite', False)
        filter_length, frametimings = asc.ft_nblinks(exp, stim_nr)
        total_frames = frametimings.shape[0]

        if stimtype == 'fff':
            if bw:
                randnrs, seed = randpy.ranb(seed, total_frames)
                # Since ranb returns zeros and ones, we need to convert
                # the zeros into -1s.
                stimulus = np.array(randnrs) * 2 - 1
            else:
                randnrs, seed = randpy.gasdev(seed, total_frames)
                stimulus = np.array(randnrs)
        elif stimtype in ['checkerflicker', 'frozennoise']:
            scr_width = metadata['screen_width']
            scr_height = metadata['screen_height']
            stx_h = pars['stixelheight']
            stx_w = pars['stixelwidth']
            # Check whether any parameters are given for margins, calculate
            # screen dimensions.
            marginkeys = ['tmargin', 'bmargin', 'rmargin', 'lmargin']
            margins = []
            for key in marginkeys:
                margins.append(pars.get(key, 0))
            # Subtract bottom and top from vertical dimension; left and right
            # from horizontal dimension
            scr_width = scr_width - sum(margins[2:])
            scr_height = scr_height - sum(margins[:2])
            sx, sy = scr_height / stx_h, scr_width / stx_w
            # Make sure that the number of stimulus pixels are integers
            # Rounding down is also possible but might require
            # other considerations.
            if sx % 1 == 0 and sy % 1 == 0:
                sx, sy = int(sx), int(sy)
            else:
                raise ValueError('sx and sy must be integers')

            # HINT: fixing stimulus length for now because of memory
            # capacity
            total_frames = maxframenr

            randnrs, seed = randpy.ranb(seed, sx * sy * total_frames)
            # Reshape and change 0's to -1's
            stimulus = np.reshape(randnrs,
                                  (sx, sy, total_frames), order='F') * 2 - 1
        return stimulus
    if stimtype == 'OMB':
        stimframes = pars.get('stimFrames', 108000)
        preframes = pars.get('preFrames', 200)
        nblinks = pars.get('Nblinks', 2)

        seed = pars.get('seed', -10000)
        seed2 = pars.get('objseed', -1000)

        stepsize = pars.get('stepsize', 2)

        ntotal = int(stimframes / nblinks)

        clusters, metadata = asc.read_spikesheet(exp)

        refresh_rate = metadata['refresh_rate']
        filter_length, frametimings = asc.ft_nblinks(exp, stim_nr, nblinks,
                                                     refresh_rate)
        frame_duration = np.ediff1d(frametimings).mean()
        frametimings = frametimings[:-1]
        if ntotal != frametimings.shape[0]:
            print(
                f'For {exp}\nstimulus {iof.getstimname(exp, stim_nr)} :\n'
                f'Number of frames specified in the parameters file ({ntotal}'
                f' frames) and frametimings ({frametimings.shape[0]}) do not'
                ' agree!'
                ' The stimulus was possibly interrupted during recording.'
                ' ntotal is changed to match actual frametimings.')
            ntotal = frametimings.shape[0]

        randnrs, seed = randpy.gasdev(seed, ntotal * 2)
        randnrs = np.array(randnrs) * stepsize

        xsteps = randnrs[::2]
        ysteps = randnrs[1::2]

        return np.vstack((xsteps, ysteps))
    return None
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt

import iofuncs as iof
import analysis_scripts as asc
import nonlinearity as nlt
import genlinmod as glm

from omb import OMB
from stimulus import Stimulus

#exp, stim_nr  = '20180710', 8
#exp, stim_nr  = 'Kuehn', 13

fff_stimnr = asc.stimulisorter(exp)['fff'][0]

st = OMB(exp, stim_nr)
fff = Stimulus(exp, fff_stimnr)

# Get rid of list of numpy arrays
fff_stas = np.array(fff.read_datafile()['stas'])

glmlabel = 'GLM_contrast'

savepath = os.path.join(st.stim_dir, glmlabel)
os.makedirs(savepath, exist_ok=True)

texture_data = st.read_texture_analysis()

all_spikes = st.allspikes()
def mirrorexpand(x, times=1):
    """
    Rxpands a matrix by mirroring at all sides, to mimic OpenGL
    texture wrapping (GL_MIRORED_REPEAT) behaviour.

    """
    for i in range(times):
        x = np.vstack((np.flipud(x), x, np.flipud(x)))
        x = np.hstack((np.fliplr(x), x, np.fliplr(x)))
    return x


#%%
exp, stim_nr = ('20180710', 8)

sortedstim = asc.stimulisorter(exp)
clusters, metadata = asc.read_spikesheet(exp)
pars = asc.read_parameters(exp, stim_nr)

for key, val in sortedstim.items():
    if stim_nr in val:
        stimtype = key

if stimtype != 'OMB':
    ValueError('The stimulus is not OMB.')

bgnoise = pars.get('bgnoise', 4)
if bgnoise != 1:
    bgstixel = pars.get('bgstixel', 5)
else:
    bgstixel = pars.get('bgstixel', 10)
Exemple #6
0
sys.path.append(str(Path.home() / 'repos/pymer/cca/'))
sys.path.append(str(Path.home() / 'repos/pymer/modules/'))
sys.path.append(str(Path.home() / 'repos/pymer/classes/'))
sys.path.append(str(Path.home() / 'repos/pymer/external_libs/'))
import analysis_scripts as asc
import cca_withpyrcca
import importlib
importlib.reload(cca_withpyrcca)

cca_omb_components = cca_withpyrcca.cca_omb_components

exps = ['20180712*kilosorted', '20180719_kilosorted', '20180815*_kilosorted']
exp_stimnr_pairs = []
# Find all the OMB stimuli in the experiment
for exp in exps:
    ombstimnrs = asc.stimulisorter(exp)['OMB']
    for ombstimnr in ombstimnrs:
        exp_stimnr_pairs.append((exp, ombstimnr))
# exp, stimnr = '20180815*_kilosorted', 10
#%%
for exp, stimnr in exp_stimnr_pairs:

    temp_save_folder = None
    maxframes = None

    cca_omb_components(
        exp,
        stimnr,
        n_components=6,
        regularization=100,
        maxframes=maxframes,
Created on Wed Oct 17 14:24:09 2018

@author: ycan
"""
import warnings
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

import gaussfitter as gfit
import iofuncs as iof
import analysis_scripts as asc
import miscfuncs as msc

exp = '20180710'
sorted_stimuli = asc.stimulisorter(exp)
checker = sorted_stimuli['frozennoise'][0]
data = iof.load(exp, checker)
parameters = asc.read_parameters(exp, checker)

stas = data['stas']
max_inds = data['max_inds']

i = 0
sta = stas[i]
max_i = max_inds[i]
bound = 1.5

#%%
def fitgaussian(sta, f_size=10):
    max_i = np.unravel_index(np.argmax(np.abs(sta)), sta.shape)