def perform_analysis_and_visualization(data_store):
    if True:
        
        analog_ids = param_filter_query(data_store,sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
        analog_ids_inh = param_filter_query(data_store,sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()

        #find neuron with preference closet to 0  
        NeuronAnnotationsToPerNeuronValues(data_store,ParameterSet({})).analyse()
        l4_exc_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Exc_L4')
        l4_exc_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Exc_L4')
        l4_exc = analog_ids[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),l4_exc_phase[0].get_value_by_id(analog_ids))])]
        l4_inh_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Inh_L4')
        l4_inh_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Inh_L4')
        l4_inh = analog_ids_inh[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),l4_inh_phase[0].get_value_by_id(analog_ids_inh))])]
        l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(numpy.array([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_exc_or[0].values,l4_exc_phase[0].values)]) < 0.1)[0]]

        print "Prefered orientation of plotted exc neurons:"
        print 'index ' + str(l4_exc)
        print "Prefered phase of plotted exc neurons:"
        print l4_exc_phase[0].get_value_by_id(l4_exc)
        print "Prefered orientation of plotted inh neurons:"
        print l4_inh_phase[0].get_value_by_id(l4_inh)
        print 'index ' + str(l4_inh)
        print "Prefered phase of plotted inh neurons:"
        print l4_exc_phase[0].get_value_by_id(l4_exc)
    
        #dsv = param_filter_query(data_store,sheet_name='V1_Exc_L4')
        #TrialAveragedFiringRate(param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4'],st_name="FullfieldDriftingSinusoidalGrating"),ParameterSet({})).analyse()
                    
        dsv = param_filter_query(data_store,st_name=['InternalStimulus'])        
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[0], 'sheet_activity' : {},'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name='SSExcAnalog.png').plot()
        RetinalInputMovie(dsv, ParameterSet({}), fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name='video').plot()
Exemple #2
0
def trial_averaged_raster(sheet,
                          folder,
                          stimulus,
                          parameter,
                          opposite=False,
                          box=None,
                          radius=None,
                          addon=""):
    print inspect.stack()[0][3]
    print "folder: ", folder
    print "sheet: ", sheet
    data_store = PickledDataStore(load=True,
                                  parameters=ParameterSet({
                                      'root_directory':
                                      folder,
                                      'store_stimuli':
                                      False
                                  }),
                                  replace=True)
    data_store.print_content(full_recordings=False)

    spike_ids = param_filter_query(
        data_store,
        sheet_name=sheet).get_segments()[0].get_stored_spike_train_ids()
    if spike_ids == None:
        print "No spikes recorded.\n"
        return
    print "Recorded neurons:", len(spike_ids)

    if sheet == 'V1_Exc_L4' or sheet == 'V1_Inh_L4':
        NeuronAnnotationsToPerNeuronValues(data_store,
                                           ParameterSet({})).analyse()
        l4_exc_or = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentOrientation',
            sheet_name=sheet)[0]
        if opposite:
            addon = addon + "_opposite"
            l4_exc_or_many = numpy.array(spike_ids)[numpy.nonzero(
                numpy.array([
                    circular_dist(l4_exc_or.get_value_by_id(i), numpy.pi /
                                  2, numpy.pi) for i in spike_ids
                ]) < .1)[0]]
        else:
            addon = addon + "_same"
            l4_exc_or_many = numpy.array(spike_ids)[numpy.nonzero(
                numpy.array([
                    circular_dist(l4_exc_or.get_value_by_id(i), 0, numpy.pi)
                    for i in spike_ids
                ]) < .1)[0]]
        spike_ids = list(l4_exc_or_many)

    if radius or box:
        sheet_ids = data_store.get_sheet_indexes(sheet_name=sheet,
                                                 neuron_ids=spike_ids)
        positions = data_store.get_neuron_postions()[sheet]
        if box:
            ids1 = select_ids_by_position(positions, sheet_ids, box=box)
        if radius:
            ids1 = select_ids_by_position(positions, sheet_ids, radius=radius)
        spike_ids = data_store.get_sheet_ids(sheet_name=sheet, indexes=ids1)

    print "Selected neurons:", len(spike_ids)
    if len(spike_ids) < 1:
        return

    dsv = param_filter_query(data_store, sheet_name=sheet, st_name=stimulus)
    dist = box if not radius else radius

    # Raster + Histogram
    RasterPlot(dsv,
               ParameterSet({
                   'sheet_name': sheet,
                   'neurons': list(spike_ids),
                   'trial_averaged_histogram': True,
                   'spontaneous': True
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (100, 50)
               },
               plot_file_name=folder + "/HistRaster_" + parameter + "_" +
               str(sheet) + "_radius" + str(dist) + "_" + addon + ".svg").plot(
                   {'SpikeRasterPlot.group_trials': True})
Exemple #3
0
def trial_averaged_Vm(sheet,
                      folder,
                      stimulus,
                      parameter,
                      opposite=False,
                      box=None,
                      radius=None,
                      addon=""):
    print inspect.stack()[0][3]
    print "folder: ", folder
    print "sheet: ", sheet
    data_store = PickledDataStore(load=True,
                                  parameters=ParameterSet({
                                      'root_directory':
                                      folder,
                                      'store_stimuli':
                                      False
                                  }),
                                  replace=True)
    data_store.print_content(full_recordings=False)

    analog_ids = param_filter_query(
        data_store, sheet_name=sheet).get_segments()[0].get_stored_vm_ids()
    if analog_ids == None:
        print "No Vm recorded.\n"
        return
    print "Recorded neurons:", len(analog_ids)

    if sheet == 'V1_Exc_L4' or sheet == 'V1_Inh_L4':
        NeuronAnnotationsToPerNeuronValues(data_store,
                                           ParameterSet({})).analyse()
        l4_exc_or = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentOrientation',
            sheet_name=sheet)[0]
        if opposite:
            addon = addon + "_opposite"
            l4_exc_or_many = numpy.array(analog_ids)[numpy.nonzero(
                numpy.array([
                    circular_dist(l4_exc_or.get_value_by_id(i), numpy.pi /
                                  2, numpy.pi) for i in analog_ids
                ]) < .1)[0]]
        else:
            addon = addon + "_same"
            l4_exc_or_many = numpy.array(analog_ids)[numpy.nonzero(
                numpy.array([
                    circular_dist(l4_exc_or.get_value_by_id(i), 0, numpy.pi)
                    for i in analog_ids
                ]) < .1)[0]]
        analog_ids = list(l4_exc_or_many)

    if radius or box:
        sheet_ids = data_store.get_sheet_indexes(sheet_name=sheet,
                                                 neuron_ids=analog_ids)
        positions = data_store.get_neuron_postions()[sheet]
        if box:
            ids1 = select_ids_by_position(positions, sheet_ids, box=box)
        if radius:
            ids1 = select_ids_by_position(positions, sheet_ids, radius=radius)
        analog_ids = data_store.get_sheet_ids(sheet_name=sheet, indexes=ids1)

    print "Selected neurons:", len(analog_ids)
    if len(analog_ids) < 1:
        return

    dsv = param_filter_query(data_store, sheet_name=sheet, st_name=stimulus)

    dist = box if not radius else radius
    for n in analog_ids:
        VmPlot(
            dsv,
            ParameterSet({
                'neuron': n,
                'sheet_name': sheet,
                'spontaneous': True,
            }),
            fig_param={
                'dpi': 300,
                'figsize': (40, 5)
            },
            # plot_file_name=folder+"/Vm_"+parameter+"_"+str(sheet)+"_"+str(dist)+"_"+str(n)+"_"+addon+".png"
            plot_file_name=folder + "/Vm_" + parameter + "_" + str(sheet) +
            "_radius" + str(dist) + "_" + str(n) + "_" + addon + ".svg"
        ).plot({
            # '*.y_lim':(0,60),
            # '*.x_scale':'log', '*.x_scale_base':2,
            # '*.y_ticks':[5, 10, 25, 50, 60],
            # # '*.y_scale':'linear',
            # '*.y_scale':'log', '*.y_scale_base':2,
            # '*.fontsize':24
        })
Exemple #4
0
def perform_analysis_and_visualization_bar(data_store):

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()

    analog_ids = param_filter_query(
        data_store, sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(
        data_store,
        sheet_name="X_ON").get_segments()[0].get_stored_spike_train_ids()

    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[0],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog1.png').plot()
    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[1],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog2.png').plot()
    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[2],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog3.png').plot()

    RasterPlot(data_store,
               ParameterSet({
                   'sheet_name': 'X_ON',
                   'neurons': spike_ids,
                   'trial_averaged_histogram': False,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='ONRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})
    RasterPlot(data_store,
               ParameterSet({
                   'sheet_name': 'X_OFF',
                   'neurons': lgn_off_ids,
                   'trial_averaged_histogram': False,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='ONRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})

    dsv = param_filter_query(data_store,
                             st_name=['FlashedBar'],
                             st_relative_luminance=1)
    RasterPlot(dsv,
               ParameterSet({
                   'sheet_name': 'X_ON',
                   'neurons': lgn_on_ids,
                   'trial_averaged_histogram': True,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='ONBar_ONRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})

    dsv = param_filter_query(data_store,
                             st_name=['FlashedBar'],
                             st_relative_luminance=1)
    RasterPlot(dsv,
               ParameterSet({
                   'sheet_name': 'X_OFF',
                   'neurons': lgn_off_ids,
                   'trial_averaged_histogram': True,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='ONBar_OFFRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})

    dsv = param_filter_query(data_store,
                             st_name=['FlashedBar'],
                             st_relative_luminance=0)
    RasterPlot(dsv,
               ParameterSet({
                   'sheet_name': 'X_ON',
                   'neurons': lgn_on_ids,
                   'trial_averaged_histogram': True,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='OFFBar_ONRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})

    dsv = param_filter_query(data_store,
                             st_name=['FlashedBar'],
                             st_relative_luminance=0)
    RasterPlot(dsv,
               ParameterSet({
                   'sheet_name': 'X_OFF',
                   'neurons': lgn_off_ids,
                   'trial_averaged_histogram': True,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='OFFBar_OFFRaster.png').plot(
                   {'SpikeRasterPlot.group_trials': True})
Exemple #5
0
def perform_analysis_and_visualization_small(data_store):

    dsv = queries.param_filter_query(data_store, st_name='FlashedBar')
    for ads in dsv.get_analysis_result():
        sid = MozaikParametrized.idd(ads.stimulus_id)
        sid.x = 0
        ads.stimulus_id = str(sid)

    for seg in dsv.get_segments():
        sid = MozaikParametrized.idd(seg.annotations['stimulus'])
        sid.x = 0
        seg.annotations['stimulus'] = str(sid)

    PSTH(
        param_filter_query(data_store,
                           sheet_name=['X_ON', 'X_OFF'],
                           st_name='FlashedBar'),
        ParameterSet({'bin_length': 10})).analyse()

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()

    dsv = param_filter_query(data_store, sheet_name=['X_ON', 'X_OFF'])
    ActionPotentialRemoval(dsv, ParameterSet({'window_length': 5.0})).analyse()

    TrialVariability(
        data_store,
        ParameterSet({
            'vm': False,
            'cond_exc': False,
            'cond_inh': False
        })).analyse()
    TrialMean(
        data_store,
        ParameterSet({
            'vm': False,
            'cond_exc': False,
            'cond_inh': False
        })).analyse()

    analog_ids_on = param_filter_query(
        data_store, sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids()
    analog_ids_off = param_filter_query(
        data_store,
        sheet_name="X_OFF").get_segments()[0].get_stored_esyn_ids()

    lgn_on_ids = param_filter_query(
        data_store,
        sheet_name="X_ON").get_segments()[0].get_stored_spike_train_ids()
    lgn_off_ids = param_filter_query(
        data_store,
        sheet_name="X_OFF").get_segments()[0].get_stored_spike_train_ids()

    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids_on[0],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='ONAnalog.png').plot()
    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_OFF',
                     'neuron': analog_ids_off[0],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='OFFAnalog.png').plot()

    dsv = queries.param_filter_query(data_store,
                                     st_name='FlashedBar',
                                     y_axis_name=[
                                         'psth (bin=10) trial-to-trial mean',
                                         'Vm (no AP) trial-to-trial mean'
                                     ],
                                     sheet_name='X_ON',
                                     analysis_algorithm=['TrialMean', 'PSTH'],
                                     st_relative_luminance=1)
    PlotTemporalTuningCurve(
        dsv,
        ParameterSet({
            'parameter_name': 'y',
            'neurons': list(lgn_on_ids),
            'sheet_name': 'X_ON',
            'mean': False
        }),
        fig_param={
            'dpi': 100,
            'figsize': (20, 10)
        },
        plot_file_name='AnalogSignalEvolutionOnBar_X_ON.png').plot({
            '*.y_label':
            'offset',
            '*.interpolation':
            'nearest'
        })

    dsv = queries.param_filter_query(data_store,
                                     st_name='FlashedBar',
                                     y_axis_name=[
                                         'psth (bin=10) trial-to-trial mean',
                                         'Vm (no AP) trial-to-trial mean'
                                     ],
                                     sheet_name='X_OFF',
                                     analysis_algorithm=['TrialMean', 'PSTH'],
                                     st_relative_luminance=1)
    PlotTemporalTuningCurve(
        dsv,
        ParameterSet({
            'parameter_name': 'y',
            'neurons': list(lgn_off_ids),
            'sheet_name': 'X_OFF',
            'mean': False
        }),
        fig_param={
            'dpi': 100,
            'figsize': (20, 10)
        },
        plot_file_name='AnalogSignalEvolutionOnBar_X_OFF.png').plot({
            '*.y_label':
            'offset',
            '*.interpolation':
            'nearest'
        })

    dsv = queries.param_filter_query(data_store,
                                     st_name='FlashedBar',
                                     y_axis_name=[
                                         'psth (bin=10) trial-to-trial mean',
                                         'Vm (no AP) trial-to-trial mean'
                                     ],
                                     sheet_name='X_ON',
                                     analysis_algorithm=['TrialMean', 'PSTH'],
                                     st_relative_luminance=0)
    PlotTemporalTuningCurve(
        dsv,
        ParameterSet({
            'parameter_name': 'y',
            'neurons': list(lgn_on_ids),
            'sheet_name': 'X_ON',
            'mean': False
        }),
        fig_param={
            'dpi': 100,
            'figsize': (20, 10)
        },
        plot_file_name='AnalogSignalEvolutionOffBar_X_ON.png').plot({
            '*.y_label':
            'offset',
            '*.interpolation':
            'nearest'
        })

    dsv = queries.param_filter_query(data_store,
                                     st_name='FlashedBar',
                                     y_axis_name=[
                                         'psth (bin=10) trial-to-trial mean',
                                         'Vm (no AP) trial-to-trial mean'
                                     ],
                                     sheet_name='X_OFF',
                                     analysis_algorithm=['TrialMean', 'PSTH'],
                                     st_relative_luminance=0)
    PlotTemporalTuningCurve(
        dsv,
        ParameterSet({
            'parameter_name': 'y',
            'neurons': list(lgn_off_ids),
            'sheet_name': 'X_OFF',
            'mean': False
        }),
        fig_param={
            'dpi': 100,
            'figsize': (20, 10)
        },
        plot_file_name='AnalogSignalEvolutionOffBar_X_OFF.png').plot({
            '*.y_label':
            'offset',
            '*.interpolation':
            'nearest'
        })
Exemple #6
0
def perform_analysis_and_visualization(data_store):

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()

    analog_ids = param_filter_query(
        data_store, sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(
        data_store,
        sheet_name="X_ON").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_off = param_filter_query(
        data_store,
        sheet_name="X_OFF").get_segments()[0].get_stored_spike_train_ids()

    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[0],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog1.png').plot()
    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[1],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog2.png').plot()
    OverviewPlot(data_store,
                 ParameterSet({
                     'sheet_name': 'X_ON',
                     'neuron': analog_ids[2],
                     'sheet_activity': {},
                     'spontaneous': True
                 }),
                 fig_param={
                     'dpi': 100,
                     'figsize': (28, 12)
                 },
                 plot_file_name='SSX_ONAnalog3.png').plot()

    RasterPlot(data_store,
               ParameterSet({
                   'sheet_name': 'X_ON',
                   'neurons': spike_ids,
                   'trial_averaged_histogram': False,
                   'spontaneous': False
               }),
               fig_param={
                   'dpi': 100,
                   'figsize': (28, 12)
               },
               plot_file_name='SSExcRasterL4.png').plot(
                   {'SpikeRasterPlot.group_trials': True})
def perform_analysis_and_visualization(data_store):
    if True:

        analog_ids = param_filter_query(
            data_store,
            sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
        analog_ids_inh = param_filter_query(
            data_store,
            sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()

        #find neuron with preference closet to 0
        NeuronAnnotationsToPerNeuronValues(data_store,
                                           ParameterSet({})).analyse()
        l4_exc_or = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentOrientation',
            sheet_name='V1_Exc_L4')
        l4_exc_phase = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentPhase',
            sheet_name='V1_Exc_L4')
        l4_exc = analog_ids[numpy.argmin([
            circular_dist(o, numpy.pi / 2, numpy.pi)
            for (o, p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),
                              l4_exc_phase[0].get_value_by_id(analog_ids))
        ])]
        l4_inh_or = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentOrientation',
            sheet_name='V1_Inh_L4')
        l4_inh_phase = data_store.get_analysis_result(
            identifier='PerNeuronValue',
            value_name='LGNAfferentPhase',
            sheet_name='V1_Inh_L4')
        l4_inh = analog_ids_inh[numpy.argmin([
            circular_dist(o, numpy.pi / 2, numpy.pi)
            for (o, p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),
                              l4_inh_phase[0].get_value_by_id(analog_ids_inh))
        ])]
        l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(
            numpy.array([
                circular_dist(o, numpy.pi / 2, numpy.pi)
                for (o, p) in zip(l4_exc_or[0].values, l4_exc_phase[0].values)
            ]) < 0.1)[0]]

        print "Prefered orientation of plotted exc neurons:"
        print 'index ' + str(l4_exc)
        print "Prefered phase of plotted exc neurons:"
        print l4_exc_phase[0].get_value_by_id(l4_exc)
        print "Prefered orientation of plotted inh neurons:"
        print l4_inh_phase[0].get_value_by_id(l4_inh)
        print 'index ' + str(l4_inh)
        print "Prefered phase of plotted inh neurons:"
        print l4_exc_phase[0].get_value_by_id(l4_exc)

    if False:
        #data_store.remove_ads_from_datastore()

        dsv = param_filter_query(data_store, sheet_name='V1_Exc_L4')
        ActionPotentialRemoval(dsv, ParameterSet({'window_length':
                                                  10.0})).analyse()
        TrialAveragedFiringRate(
            param_filter_query(data_store,
                               sheet_name=['V1_Exc_L4', 'V1_Inh_L4'],
                               st_name="FullfieldDriftingSinusoidalGrating"),
            ParameterSet({})).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 analysis_algorithm='TrialAveragedFiringRate',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        GaussianTuningCurveFit(dsv,
                               ParameterSet({'parameter_name':
                                             'orientation'})).analyse()
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        Analog_F0andF1(dsv, ParameterSet({})).analyse()
        data_store.save()

        Analog_MeanSTDAndFanoFactor(data_store, ParameterSet({})).analyse()
        #data_store.save()
        PSTH(param_filter_query(data_store, sheet_name='V1_Exc_L4'),
             ParameterSet({'bin_length': 2.0})).analyse()

        GSTA(param_filter_query(data_store,
                                sheet_name='V1_Exc_L4',
                                st_name='InternalStimulus',
                                direct_stimulation_name='None'),
             ParameterSet({
                 'neurons': [l4_exc],
                 'length': 250.0
             }),
             tags=['GSTA']).analyse()
        GSTA(param_filter_query(data_store,
                                sheet_name='V1_Exc_L4',
                                st_name='FullfieldDriftingSinusoidalGrating',
                                st_orientation=[0, numpy.pi / 2]),
             ParameterSet({
                 'neurons': [l4_exc],
                 'length': 250.0
             }),
             tags=['GSTA']).analyse()
        GSTA(param_filter_query(data_store,
                                sheet_name='V1_Inh_L4',
                                st_name='FullfieldDriftingSinusoidalGrating',
                                st_orientation=[0, numpy.pi / 2]),
             ParameterSet({
                 'neurons': [l4_inh],
                 'length': 250.0
             }),
             tags=['GSTA']).analyse()
        GSTA(param_filter_query(data_store,
                                sheet_name='V1_Exc_L4',
                                st_name='NaturalImageWithEyeMovement'),
             ParameterSet({
                 'neurons': [l4_exc],
                 'length': 250.0
             }),
             tags=['GSTA']).analyse()

        #data_store.print_content(full_ADS=True)

        #Precision(param_filter_query(data_store,sheet_name='V1_Exc_L4'),ParameterSet({'neurons' : [l4_exc], 'bin_length' : 10.0 })).analyse()

        #dsv = param_filter_query(data_store,st_name='NaturalImageWithEyeMovement',sheet_name='V1_Exc_L4',analysis_algorithm='ActionPotentialRemoval')
        #TrialVariability(dsv,ParameterSet({'vm': False,  'cond_exc': False, 'cond_inh': False})).analyse()
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 st_contrast=100,
                                 analysis_algorithm='ActionPotentialRemoval')
        TrialVariability(
            dsv,
            ParameterSet({
                'vm': False,
                'cond_exc': False,
                'cond_inh': False
            })).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 analysis_algorithm='TrialAveragedFiringRate',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage(
            dsv, ParameterSet({'parameter_name': 'orientation'})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(ECond)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Exc_Cond')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(ICond)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Inh_Cond')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(VM)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Vm')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()

        TrialToTrialCrossCorrelationOfAnalogSignalList(
            param_filter_query(data_store,
                               sheet_name='V1_Exc_L4',
                               st_name="NaturalImageWithEyeMovement",
                               analysis_algorithm='ActionPotentialRemoval'),
            ParameterSet({'neurons': list(analog_ids)})).analyse()
        TrialToTrialCrossCorrelationOfAnalogSignalList(
            param_filter_query(data_store,
                               sheet_name='V1_Exc_L4',
                               st_name="NaturalImageWithEyeMovement",
                               analysis_algorithm='PSTH'),
            ParameterSet({'neurons': list(analog_ids)})).analyse()

        data_store.save()

    dsv = param_filter_query(
        data_store,
        analysis_algorithm='TrialToTrialCrossCorrelationOfAnalogSignalList')
    dsv.print_content(full_ADS=True)

    if True:  # PLOTTING
        #TrialCrossCorrelationAnalysis(data_store,ParameterSet({'neurons' : list(analog_ids)}),fig_param={"dpi" : 100,"figsize": (25,12)},plot_file_name="trial-to-trial-cross-correlation.png").plot()
        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[0]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR1.png').plot()
        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[1]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR2.png').plot()
        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[2]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR3.png').plot()

        dsv = param_filter_query(data_store, st_name=['InternalStimulus'])
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[0],
                         'sheet_activity': {},
                         'spontaneous': True
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (28, 12)
                     },
                     plot_file_name='SSExcAnalog.png').plot()
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Inh_L4',
                         'neuron': analog_ids_inh[0],
                         'sheet_activity': {},
                         'spontaneous': True
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (28, 12)
                     },
                     plot_file_name='SSInhAnalog.png').plot()

        #dsv = param_filter_query(data_store,st_orientation=[0,numpy.pi/2],st_name='FullfieldDriftingSinusoidalGrating',st_trial=0)
        #VmPlot(dsv,ParameterSet({'neuron' : l4_exc,'sheet_name' : 'V1_Exc_L4'})).plot({'Vm_plot.y_lim' : (-67,-56)})
        #dsv = param_filter_query(data_store,st_orientation=[0,numpy.pi/2],st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm='ActionPotentialRemoval',st_trial=0)
        #AnalogSignalListPlot(dsv,ParameterSet({'neurons' : [l4_exc],'sheet_name' : 'V1_Exc_L4'})).plot({'AnalogSignalPlot.y_lim' : (-67,-56)})

        #RetinalInputMovie(data_store,ParameterSet({'frame_rate' : 10})).plot()

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4'],value_name='LGNAfferentOrientation')
        #PerNeuronValuePlot(dsv,ParameterSet({}),plot_file_name="LGNAfferentOrientation.png").plot()

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4'],value_name='orientation preference',analysis_algorithm='PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage',st_contrast=100)
        #PerNeuronValuePlot(dsv,ParameterSet({})).plot()

        #dsv = param_filter_query(data_store,value_name=['orientation HWHH'],sheet_name=['V1_Exc_L4','V1_Inh_L4'])
        #PerNeuronValueScatterPlot(dsv,ParameterSet({})).plot({ 'ScatterPlot.x_lim' : (0,90), 'ScatterPlot.y_lim' : (0,90), 'ScatterPlot.identity_line' : True})

        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[0]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR1.png').plot()
        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[1]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR2.png').plot()
        #SNRAnalysis(data_store,ParameterSet({"neuron" : analog_ids[2]}),fig_param={'dpi' : 100,'figsize': (25,12)},plot_file_name='SNR3.png').plot()

        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[0],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison1.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[1],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison2.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[2],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison3.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[3],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison4.png').plot()
        #TrialToTrialVariabilityComparison(data_store,ParameterSet({}),plot_file_name='TtTVar.png').plot()

        #ConductanceAndVmTuningSummary(data_store,ParameterSet({'many' : True,'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (25,16)},plot_file_name='Cond&VMTuning.png').plot()

        #dsv = param_filter_query(data_store,st_name='NaturalImageWithEyeMovement')
        #KremkowOverviewFigure(dsv,ParameterSet({'neuron' : l4_exc,'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='NMOverview.png').plot()

        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : l4_exc,'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='StimulusResponseComparison.png').plot()
        #OrientationTuningSummary(data_store,ParameterSet({}),fig_param={'dpi' : 100,'figsize': (20,12)},plot_file_name='OrientationTuningSummary.png').plot()

        if True:
            #OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name="All.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

            #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',st_orientation=[0,numpy.pi/2])
            #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name="Exc1.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

            dsv = param_filter_query(
                data_store,
                st_name='FullfieldDriftingSinusoidalGrating',
                st_contrast=100)
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': l4_exc,
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc2.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[0],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc3.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[1],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc4.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[2],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc5.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[3],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc6.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[4],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc7.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[5],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc8.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[6],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc9.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[7],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="Exc10.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })

            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Inh_L4',
                             'neuron': l4_inh,
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (14, 12)
                         },
                         plot_file_name="Inh.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(
                dsv,
                ParameterSet({
                    'sheet_name':
                    'X_ON',
                    'neuron':
                    sorted(
                        param_filter_query(data_store,
                                           sheet_name="X_ON").get_segments()
                        [0].get_stored_esyn_ids())[0],
                    'sheet_activity': {},
                    'spontaneous':
                    True
                }),
                fig_param={
                    'dpi': 100,
                    'figsize': (14, 12)
                },
                plot_file_name="LGN0On.png").plot()
            OverviewPlot(
                dsv,
                ParameterSet({
                    'sheet_name':
                    'X_OFF',
                    'neuron':
                    sorted(
                        param_filter_query(data_store,
                                           sheet_name="X_OFF").get_segments()
                        [0].get_stored_esyn_ids())[0],
                    'sheet_activity': {},
                    'spontaneous':
                    True
                }),
                fig_param={
                    'dpi': 100,
                    'figsize': (14, 12)
                },
                plot_file_name="LGN0Off.png").plot()
            OverviewPlot(
                dsv,
                ParameterSet({
                    'sheet_name':
                    'X_ON',
                    'neuron':
                    sorted(
                        param_filter_query(data_store,
                                           sheet_name="X_ON").get_segments()
                        [0].get_stored_esyn_ids())[1],
                    'sheet_activity': {},
                    'spontaneous':
                    True
                }),
                fig_param={
                    'dpi': 100,
                    'figsize': (14, 12)
                },
                plot_file_name="LGN1On.png").plot()
            OverviewPlot(
                dsv,
                ParameterSet({
                    'sheet_name':
                    'X_OFF',
                    'neuron':
                    sorted(
                        param_filter_query(data_store,
                                           sheet_name="X_OFF").get_segments()
                        [0].get_stored_esyn_ids())[1],
                    'sheet_activity': {},
                    'spontaneous':
                    True
                }),
                fig_param={
                    'dpi': 100,
                    'figsize': (14, 12)
                },
                plot_file_name="LGN1Off.png").plot()

            #TrialAveragedFiringRate(param_filter_query(data_store,sheet_name=['X_ON'],st_name="DriftingSinusoidalGratingDisk"),ParameterSet({})).analyse()

            ##dsv = param_filter_query(data_store,st_name='DriftingSinusoidalGratingDisk',analysis_algorithm=['TrialAveragedFiringRate'])
            #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'spatial_frequency', 'neurons': list(sorted(param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids())), 'sheet_name' : 'X_ON','centered'  : False,'mean' : False})).plot({'TuningCurve F0_Inh_Cond.y_lim' : (0,180) , 'TuningCurve F0_Exc_Cond.y_lim' : (0,80)})

            #import pylab
            #pylab.show()

        if True:
            dsv = param_filter_query(data_store,
                                     st_name='NaturalImageWithEyeMovement')
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': l4_exc,
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc2.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[0],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc3.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[1],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc4.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[2],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc5.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[3],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc6.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[4],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc7.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[5],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc8.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[6],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc9.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[7],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="NatExc10.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })

            OverviewPlot(
                dsv,
                ParameterSet({
                    'sheet_name':
                    'X_ON',
                    'neuron':
                    sorted(
                        param_filter_query(data_store,
                                           sheet_name="X_ON").get_segments()
                        [0].get_stored_esyn_ids())[0],
                    'sheet_activity': {}
                }),
                fig_param={
                    'dpi': 100,
                    'figsize': (14, 12)
                },
                plot_file_name="LGN0On.png").plot()
            import pylab
            pylab.show()

        if False:
            dsv = param_filter_query(
                data_store, st_name='DriftingSineGratingWithEyeMovement')
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': l4_exc,
                             'sheet_activity': {}
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc2.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[0],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc3.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[1],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc4.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[2],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc5.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[3],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc6.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[4],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc7.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[5],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc8.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[6],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc9.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })
            OverviewPlot(dsv,
                         ParameterSet({
                             'sheet_name': 'V1_Exc_L4',
                             'neuron': analog_ids[7],
                             'sheet_activity': {},
                             'spontaneous': True
                         }),
                         fig_param={
                             'dpi': 100,
                             'figsize': (19, 12)
                         },
                         plot_file_name="DGExc10.png").plot({
                             'Vm_plot.y_lim': (-67, -56),
                             'Conductance_plot.y_lim': (0, 35.0)
                         })

        # tuninc curves
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            analysis_algorithm=['TrialAveragedFiringRate', 'Analog_F0andF1'])
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids),
                            'sheet_name': 'V1_Exc_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        fig_param={
                            'dpi': 100,
                            'figsize': (25, 12)
                        },
                        plot_file_name="TCExc.png").plot({
                            'TuningCurve F0_Inh_Cond.y_lim': (0, 180),
                            'TuningCurve F0_Exc_Cond.y_lim': (0, 80)
                        })
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids_inh),
                            'sheet_name': 'V1_Inh_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        fig_param={
                            'dpi': 100,
                            'figsize': (25, 12)
                        },
                        plot_file_name="TCInh.png").plot({
                            'TuningCurve F0_Inh_Cond.y_lim': (0, 180),
                            'TuningCurve F0_Exc_Cond.y_lim': (0, 80)
                        })

        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'])
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids),
                            'sheet_name': 'V1_Exc_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        fig_param={
                            'dpi': 100,
                            'figsize': (25, 12)
                        },
                        plot_file_name="TCExcA.png").plot()
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids_inh),
                            'sheet_name': 'V1_Inh_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        fig_param={
                            'dpi': 100,
                            'figsize': (25, 12)
                        },
                        plot_file_name="TCInhA.png").plot()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialVariability'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(analog_ids), 'sheet_name' : 'V1_Exc_L4'})).plot()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialVariability'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(analog_ids_inh), 'sheet_name' : 'V1_Inh_L4'})).plot()

        import pylab
        pylab.show()
def perform_analysis_and_visualization(data_store):
    analog_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_spike_train_ids()

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Exc_L4')
    l4_exc_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentPhase',
        sheet_name='V1_Exc_L4')
    l4_exc = analog_ids[numpy.argmin([
        circular_dist(o, numpy.pi / 2, numpy.pi)
        for (o, p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),
                          l4_exc_phase[0].get_value_by_id(analog_ids))
    ])]
    l4_inh_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Inh_L4')
    l4_inh_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentPhase',
        sheet_name='V1_Inh_L4')
    l4_inh = analog_ids_inh[numpy.argmin([
        circular_dist(o, numpy.pi / 2, numpy.pi)
        for (o, p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),
                          l4_inh_phase[0].get_value_by_id(analog_ids_inh))
    ])]
    l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(
        numpy.array([
            circular_dist(o, numpy.pi / 2, numpy.pi)
            for (o, p) in zip(l4_exc_or[0].values, l4_exc_phase[0].values)
        ]) < 0.1)[0]]

    if False:  #ANALYSIS
        TrialAveragedFiringRate(
            param_filter_query(data_store,
                               sheet_name=['V1_Exc_L4', 'V1_Inh_L4'],
                               st_name='FullfieldDriftingSinusoidalGrating'),
            ParameterSet({})).analyse()
        TrialAveragedFiringRate(
            param_filter_query(data_store,
                               st_direct_stimulation_name="None",
                               st_name='InternalStimulus'),
            ParameterSet({})).analyse()
        #Irregularity(param_filter_query(data_store,st_direct_stimulation_name="None",st_name='InternalStimulus'),ParameterSet({})).analyse()
        PopulationMean(
            param_filter_query(data_store,
                               st_direct_stimulation_name="None",
                               st_name='InternalStimulus'),
            ParameterSet({})).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 analysis_algorithm='TrialAveragedFiringRate',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        GaussianTuningCurveFit(dsv,
                               ParameterSet({'parameter_name':
                                             'orientation'})).analyse()
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        Analog_F0andF1(dsv, ParameterSet({})).analyse()

        GSTA(param_filter_query(data_store, sheet_name='V1_Exc_L4'),
             ParameterSet({
                 'neurons': list(analog_ids),
                 'length': 250.0
             }),
             tags=['GSTA']).analyse()
        #Precision(param_filter_query(data_store,sheet_name='V1_Exc_L4'),ParameterSet({'neurons' : [l4_exc], 'bin_length' : 10.0 })).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 analysis_algorithm='TrialAveragedFiringRate',
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage(
            dsv, ParameterSet({'parameter_name': 'orientation'})).analyse()

        dsv = param_filter_query(data_store, sheet_name='V1_Exc_L4')
        ActionPotentialRemoval(dsv, ParameterSet({'window_length':
                                                  5.0})).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='NaturalImageWithEyeMovement',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm='ActionPotentialRemoval')
        TrialVariability(
            dsv,
            ParameterSet({
                'vm': True,
                'cond_exc': False,
                'cond_inh': False
            })).analyse()
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 st_contrast=100,
                                 analysis_algorithm='ActionPotentialRemoval')
        TrialVariability(
            dsv,
            ParameterSet({
                'vm': True,
                'cond_exc': False,
                'cond_inh': False
            })).analyse()

        dsv = param_filter_query(data_store,
                                 st_name='InternalStimulus',
                                 sheet_name='V1_Exc_L4')
        Analog_MeanSTDAndFanoFactor(dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(ECond)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Exc_Cond')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(ICond)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Inh_Cond')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(
            data_store,
            st_name='InternalStimulus',
            sheet_name='V1_Exc_L4',
            analysis_algorithm=['Analog_MeanSTDAndFanoFactor'],
            value_name='Mean(VM)',
            st_direct_stimulation_name='None').get_analysis_result()[0]
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 sheet_name='V1_Exc_L4',
                                 analysis_algorithm=['Analog_F0andF1'],
                                 value_name='F0_Vm')
        SubtractPNVfromPNVS(pnv, dsv, ParameterSet({})).analyse()
        data_store.save()

    if True:  # PLOTTING
        activity_plot_param = {
            'frame_rate': 5,
            'bin_width': 5.0,
            'scatter': True,
            'resolution': 0
        }

        Kremkow_plots.ConductanceAndVmTuningSummary(
            data_store,
            ParameterSet({'many': False}),
            fig_param={
                'dpi': 100,
                'figsize': (25, 16)
            },
            plot_file_name='Cond&VMTuning.png').plot()

        # self sustained plotting
        dsv = param_filter_query(data_store, st_name=['InternalStimulus'])
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[0],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (28, 12)
                     },
                     plot_file_name='SSExcAnalog.png').plot()
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[1], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name='SSExcAnalog1.png').plot()
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[2], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name='SSExcAnalog2.png').plot()

        RasterPlot(dsv,
                   ParameterSet({
                       'sheet_name': 'V1_Exc_L4',
                       'neurons': spike_ids,
                       'trial_averaged_histogram': False
                   }),
                   fig_param={
                       'dpi': 100,
                       'figsize': (28, 12)
                   },
                   plot_file_name='SSExcRaster.png').plot(
                       {'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv,
                   ParameterSet({
                       'sheet_name': 'V1_Inh_L4',
                       'neurons': spike_ids_inh,
                       'trial_averaged_histogram': False
                   }),
                   fig_param={
                       'dpi': 100,
                       'figsize': (28, 12)
                   },
                   plot_file_name='SSInhRaster.png').plot(
                       {'SpikeRasterPlot.group_trials': True})

        orr = list(
            set([
                MozaikParametrized.idd(s).orientation
                for s in queries.param_filter_query(
                    data_store,
                    st_name='FullfieldDriftingSinusoidalGrating',
                    st_contrast=100).get_stimuli()
            ]))

        SNRAnalysis(data_store,
                    ParameterSet({"neuron": analog_ids[0]}),
                    fig_param={
                        'dpi': 100,
                        'figsize': (25, 12)
                    },
                    plot_file_name='SNR1.png').plot()
        SNRAnalysis(data_store,
                    ParameterSet({"neuron": analog_ids[1]}),
                    fig_param={
                        'dpi': 100,
                        'figsize': (25, 12)
                    },
                    plot_file_name='SNR2.png').plot()
        SNRAnalysis(data_store,
                    ParameterSet({"neuron": analog_ids[2]}),
                    fig_param={
                        'dpi': 100,
                        'figsize': (25, 12)
                    },
                    plot_file_name='SNR3.png').plot()

        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[0],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison1.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[1],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison2.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[2],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison3.png').plot()
        #StimulusResponseComparison(data_store,ParameterSet({'neuron' : analog_ids[3],'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (10,12)},plot_file_name='StimulusResponseComparison4.png').plot()

        TrialToTrialVariabilityComparison(data_store,
                                          ParameterSet({}),
                                          plot_file_name='TtTVar.png').plot()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating',
                                 st_orientation=numpy.pi / 2,
                                 st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': l4_exc,
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[0]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[0],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview1.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[1]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[1],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview2.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[2]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[2],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview3.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[3]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[3],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview4.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[4]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[4],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview5.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[5]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[5],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview6.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[5]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[6],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview7.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[6]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[7],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview8.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[7]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[8],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview9.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[8]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[9],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview10.png').plot()
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            st_orientation=orr[numpy.argmin([
                circular_dist(o, l4_exc_or[0].get_value_by_id(analog_ids[9]),
                              numpy.pi) for o in orr
            ])],
            st_contrast=100)
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': analog_ids[10],
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='ExcOverview11.png').plot()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',st_orientation=numpy.pi/2,st_contrast=100)
        #KremkowOverviewFigure(dsv,ParameterSet({'neuron' : l4_exc,'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='ExcOverview.png').plot()

        dsv = param_filter_query(data_store,
                                 st_name='NaturalImageWithEyeMovement')
        KremkowOverviewFigure(dsv,
                              ParameterSet({
                                  'neuron': l4_exc,
                                  'sheet_name': 'V1_Exc_L4'
                              }),
                              fig_param={
                                  'dpi': 100,
                                  'figsize': (19, 12)
                              },
                              plot_file_name='NMOverview.png').plot()

        #Kremkow_plots.StimulusResponseComparison(data_store,ParameterSet({'neuron' : l4_exc,'sheet_name' : 'V1_Exc_L4'}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='StimulusResponseComparison.png').plot()
        Kremkow_plots.OrientationTuningSummary(
            data_store,
            ParameterSet({}),
            fig_param={
                'dpi': 100,
                'figsize': (20, 12)
            },
            plot_file_name='OrientationTuningSummary.png').plot()

        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating')
        RasterPlot(dsv,
                   ParameterSet({
                       'sheet_name': 'V1_Exc_L4',
                       'neurons': spike_ids,
                       'trial_averaged_histogram': False
                   }),
                   fig_param={
                       'dpi': 100,
                       'figsize': (28, 12)
                   },
                   plot_file_name='EvokedExcRaster.png').plot(
                       {'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv,
                   ParameterSet({
                       'sheet_name': 'V1_Inh_L4',
                       'neurons': spike_ids_inh,
                       'trial_averaged_histogram': False
                   }),
                   fig_param={
                       'dpi': 100,
                       'figsize': (28, 12)
                   },
                   plot_file_name='EvokedInhRaster.png').plot(
                       {'SpikeRasterPlot.group_trials': True})

        #OverviewPlot(data_store,ParameterSet({'sheet_name' : 'X_ON', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids())[0], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN0On.png").plot()
        #OverviewPlot(data_store,ParameterSet({'sheet_name' : 'X_OFF', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_OFF").get_segments()[0].get_stored_esyn_ids())[0], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN0Off.png").plot()

        # orientation tuning plotting
        dsv = param_filter_query(data_store,
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'],
                                 value_name='LGNAfferentOrientation')
        PerNeuronValuePlot(dsv,
                           ParameterSet({"cortical_view": True}),
                           plot_file_name='ORSet.png').plot()

        dsv = param_filter_query(
            data_store,
            sheet_name=['V1_Exc_L4', 'V1_Inh_L4'],
            value_name='orientation preference',
            analysis_algorithm=
            'PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage',
            st_contrast=100)
        PerNeuronValuePlot(dsv,
                           ParameterSet({"cortical_view": True}),
                           plot_file_name='ORComputed.png').plot()

        dsv = param_filter_query(data_store,
                                 value_name=['orientation HWHH'],
                                 sheet_name=['V1_Exc_L4', 'V1_Inh_L4'])
        PerNeuronValueScatterPlot(dsv,
                                  ParameterSet({}),
                                  plot_file_name='HWHH.png',
                                  fig_param={
                                      'dpi': 100,
                                      'figsize': (28, 12)
                                  }).plot({
                                      'ScatterPlot.x_lim': (0, 90),
                                      'ScatterPlot.y_lim': (0, 90),
                                      'ScatterPlot.identity_line': True
                                  })
        dsv = param_filter_query(data_store,
                                 st_name='FullfieldDriftingSinusoidalGrating')
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': l4_exc,
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Inh_L4',
                         'neuron': l4_inh,
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Inh.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})

        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[0],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc1.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[1],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc2.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[2],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc3.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[3],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc4.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': analog_ids[4],
                         'sheet_activity': {}
                     }),
                     fig_param={
                         'dpi': 100,
                         'figsize': (14, 12)
                     },
                     plot_file_name="Exc5.png").plot(
                         {'Vm_plot.y_lim': (-90, -50)})

        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'X_ON', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids())[0], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN0On.png").plot()
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'X_OFF', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_OFF").get_segments()[0].get_stored_esyn_ids())[0], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN0Off.png").plot()
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'X_ON', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_esyn_ids())[1], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN1On.png").plot()
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'X_OFF', 'neuron' : sorted(param_filter_query(data_store,sheet_name="X_OFF").get_segments()[0].get_stored_esyn_ids())[1], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="LGN1Off.png").plot()

        # tuninc curves
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            analysis_algorithm=['TrialAveragedFiringRate', 'Analog_F0andF1'])
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids),
                            'sheet_name': 'V1_Exc_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        plot_file_name='TCsExc.png',
                        fig_param={
                            'dpi': 100,
                            'figsize': (28, 12)
                        }).plot({
                            'TuningCurve F0_Inh_Cond.y_lim': (0, 180),
                            'TuningCurve F0_Exc_Cond.y_lim': (0, 80)
                        })
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'orientation',
                            'neurons': list(analog_ids_inh),
                            'sheet_name': 'V1_Inh_L4',
                            'centered': True,
                            'mean': False,
                            'polar': False,
                            'pool': False
                        }),
                        plot_file_name='TCsInh.png',
                        fig_param={
                            'dpi': 100,
                            'figsize': (28, 12)
                        }).plot({
                            'TuningCurve F0_Inh_Cond.y_lim': (0, 180),
                            'TuningCurve F0_Exc_Cond.y_lim': (0, 80)
                        })

        dsv = param_filter_query(data_store,
                                 st_name='NaturalImageWithEyeMovement')
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Exc_L4',
                         'neuron': l4_exc,
                         'sheet_activity': {}
                     }),
                     plot_file_name='NMExc.png',
                     fig_param={
                         'dpi': 100,
                         'figsize': (28, 12)
                     }).plot({
                         'Vm_plot.y_lim': (-70, -50),
                         'Conductance_plot.y_lim': (0, 50.0)
                     })
        OverviewPlot(dsv,
                     ParameterSet({
                         'sheet_name': 'V1_Inh_L4',
                         'neuron': l4_inh,
                         'sheet_activity': {}
                     }),
                     plot_file_name='NMInh.png',
                     fig_param={
                         'dpi': 100,
                         'figsize': (28, 12)
                     }).plot({
                         'Vm_plot.y_lim': (-70, -50),
                         'Conductance_plot.y_lim': (0, 50.0)
                     })
        pylab.show()
def perform_analysis_and_visualization(data_store):
    pref_or = numpy.pi / 2
    #find neuron with preference closet to pref_or
    l4_analog_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
    l4_analog_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    l23_analog_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_esyn_ids()
    l23_analog_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_esyn_ids()
    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Exc_L4')
    l4_exc = l4_analog_ids[numpy.argmin([
        circular_dist(o, pref_or, numpy.pi)
        for o in l4_exc_or[0].get_value_by_id(l4_analog_ids)
    ])]
    l4_inh_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Inh_L4')
    l4_inh = l4_analog_ids_inh[numpy.argmin([
        circular_dist(o, pref_or, numpy.pi)
        for o in l4_inh_or[0].get_value_by_id(l4_analog_ids_inh)
    ])]
    l23_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Exc_L2/3')
    l23_exc = l23_analog_ids[numpy.argmin([
        circular_dist(o, pref_or, numpy.pi)
        for o in l23_exc_or[0].get_value_by_id(l23_analog_ids)
    ])]
    l23_inh_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Inh_L2/3')
    l23_inh = l23_analog_ids_inh[numpy.argmin([
        circular_dist(o, pref_or, numpy.pi)
        for o in l23_inh_or[0].get_value_by_id(l23_analog_ids_inh)
    ])]
    #l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(numpy.array([circular_dist(o,pref_or,numpy.pi)  for (o,p) in zip(l4_exc_or[0].values,l4_exc_phase[0].values)]) < 0.1)[0]]

    # Find neurons for which spikes were recorded and whose orientation is close to pref_or
    l4_spike_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_spike_train_ids()
    l4_spike_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_spike_train_ids()
    l23_spike_ids = param_filter_query(data_store,
                                       sheet_name="V1_Exc_L2/3").get_segments(
                                       )[0].get_stored_spike_train_ids()
    l23_spike_ids_inh = param_filter_query(
        data_store, sheet_name="V1_Inh_L2/3").get_segments(
        )[0].get_stored_spike_train_ids()

    l4_spike_exc_or_close_to_pi_half = numpy.array(l4_spike_ids)[numpy.nonzero(
        numpy.array([
            circular_dist(o, pref_or, numpy.pi)
            for o in l4_exc_or[0].get_value_by_id(l4_spike_ids)
        ]) < 0.1)[0]].tolist()
    l4_spike_inh_or_close_to_pi_half = numpy.array(l4_spike_ids_inh)[
        numpy.nonzero(
            numpy.array([
                circular_dist(o, pref_or, numpy.pi)
                for o in l4_inh_or[0].get_value_by_id(l4_spike_ids_inh)
            ]) < 0.1)[0]].tolist()
    l23_spike_exc_or_close_to_pi_half = numpy.array(l23_spike_ids)[
        numpy.nonzero(
            numpy.array([
                circular_dist(o, pref_or, numpy.pi)
                for o in l23_exc_or[0].get_value_by_id(l23_spike_ids)
            ]) < 0.1)[0]].tolist()
    l23_spike_inh_or_close_to_pi_half = numpy.array(l23_spike_ids_inh)[
        numpy.nonzero(
            numpy.array([
                circular_dist(o, pref_or, numpy.pi)
                for o in l23_inh_or[0].get_value_by_id(l23_spike_ids_inh)
            ]) < 0.1)[0]].tolist()

    print "Prefered orientation of plotted exc neurons:"
    print 'id: ' + str(l4_exc)
    print "Prefered orientation of plotted inh neurons:"
    print 'id: ' + str(l4_inh)

    if True:  #ANALYSIS
        #TrialAveragedFiringRate(data_store,ParameterSet({'stimulus_type':"DriftingSinusoidalGratingCenterSurroundStimulus"})).analyse()
        TrialAveragedFiringRate(data_store, ParameterSet({})).analyse()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm='TrialAveragedFiringRate')
        #GaussianTuningCurveFit(dsv,ParameterSet({'parameter_name' : 'orientation'})).analyse()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'])
        #Analog_F0andF1(dsv,ParameterSet({})).analyse()
        #TrialVariability(dsv,ParameterSet({'vm': True,  'cond_exc': False, 'cond_inh': False})).analyse()
        #TrialMean(dsv,ParameterSet({'vm': True,  'cond_exc': False, 'cond_inh': False})).analyse()

        #GSTA(param_filter_query(data_store,sheet_name='V1_Exc_L4'),ParameterSet({'neurons' : [l4_exc], 'length' : 250.0 }),tags=['GSTA']).analyse()
        #Precision(param_filter_query(data_store,sheet_name='V1_Exc_L4'),ParameterSet({'neurons' : [l4_exc], 'bin_length' : 10.0 })).analyse()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'])
        #PSTH(dsv,ParameterSet({'bin_length' : 10.0})).analyse()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'],y_axis_name='psth (bin=10.0)',st_contrast=100,analysis_algorithm='PSTH')
        #dsv1 = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'],value_name='orientation preference',st_contrast=100,analysis_algorithm='PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage')
        #ModulationRatio(dsv+dsv1,ParameterSet({})).analyse()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm='TrialAveragedFiringRate',sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'])
        #PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage(dsv,ParameterSet({'parameter_name' : 'orientation'})).analyse()
        #PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage(dsv,ParameterSet({'parameter_name' : 'phase'})).analyse()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',sheet_name=['V1_Exc_L4'],value_name='orientation preference',st_contrast=100,analysis_algorithm='PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage')
        #LocalHomogeneityIndex(dsv,ParameterSet({'sigma' : 0.1})).analyse()
        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],value_name='LGNAfferentOrientation')
        #LocalHomogeneityIndex(dsv,ParameterSet({'sigma' : 100.0})).analyse()

        data_store.save()

    if True:  # PLOTTING
        #verify_connectivity(data_store)

        activity_plot_param = {
            'frame_rate': 5,
            'bin_width': 20.0,
            'scatter': True,
            'resolution': 0
        }

        #dsv = param_filter_query(data_store,st_name='NaturalImageWithEyeMovement')
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : l23_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : l23_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

        #dsv = param_filter_query(data_store,st_name='DriftingGratingWithEyeMovement')
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : l23_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : l23_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],value_name='LocalHomogeneityIndex' + '(0.1:orientation preference)')
        #PerNeuronValuePlot(dsv,ParameterSet({})).plot({'*.colorbar' : False,'*.x_axis' : None, '*.y_axis' : None})

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],value_name='LocalHomogeneityIndex' + '(100.0:LGNAfferentOrientation)')
        #PerNeuronValuePlot(dsv,ParameterSet({})).plot({'*.colorbar' : False,'*.x_axis' : None, '*.y_axis' : None})

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'],value_name='LGNAfferentOrientation')
        #PerNeuronValuePlot(dsv,ParameterSet({})).plot({'*.colorbar' : False,'*.x_axis' : None, '*.y_axis' : None})
        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'],value_name='orientation preference',analysis_algorithm='PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage',st_contrast=100)
        #PerNeuronValuePlot(dsv,ParameterSet({})).plot({'*.colorbar' : False, '*.x_axis' : None, '*.y_axis' : None})

        #TuningComparison(data_store,ParameterSet({}),fig_param={'dpi' : 100,'figsize': (17,7.5)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/TuningComparison.png").plot({'*.colorbar' : False,'*.x_axis' : None, '*.y_axis' : None})

        #dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4'],analysis_algorithm='TrialVariability',st_orientation = 0)
        #PerNeuronValueScatterPlot(dsv,ParameterSet({})).plot({'ScatterPlot.identity_line' : True, 'ScatterPlot.mark_means' : True})

        #dsv = param_filter_query(data_store,value_name=['orientation HWHH'],sheet_name=['V1_Exc_L4','V1_Inh_L4','V1_Exc_L2/3','V1_Inh_L2/3'])
        #PerNeuronValueScatterPlot(dsv,ParameterSet({}),plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/MR.png").plot({ 'ScatterPlot.x_lim' : (0,90), 'ScatterPlot.y_lim' : (0,90), 'ScatterPlot.identity_line' : True})

        #HWHH(data_store,ParameterSet({}),fig_param={'dpi' : 100,'figsize': (8,12)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/HWHH.png").plot({ '*.x_lim' : (0,90), '*.y_lim' : (0,90), '*.identity_line' : True, '*.title' : None})

        # LHI orientation selectivity correlation
        #dsv1 = param_filter_query(data_store,value_name='orientation selectivity',sheet_name=['V1_Exc_L4'],analysis_algorithm='PeriodicTuningCurvePreferenceAndSelectivity_VectorAverage',st_contrast=100)
        #dsv2 = param_filter_query(data_store,value_name='LocalHomogeneityIndex' + '(0.1:orientation preference)',sheet_name=['V1_Exc_L4'])
        #PerNeuronValueScatterPlot(dsv1+dsv2,ParameterSet({}),plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/LHIvsSelectivity.png").plot()

        #dsv = param_filter_query(data_store,st_orientation=[0,numpy.pi/2],st_name='DriftingSinusoidalGratingDisk',st_contrast=100)
        #dsv = param_filter_query(data_store,st_orientation=[0,numpy.pi/2],st_name=['FullfieldDriftingSinusoidalGrating'],st_contrast=100)
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (16,12)},plot_file_name="OverviewEXCL4.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : l23_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (16,12)},plot_file_name="OverviewEXCL23.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (16,12)},plot_file_name="OverviewINHL4.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : l23_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (16,12)},plot_file_name="OverviewINHL23.png").plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

        #dsv = param_filter_query(data_store,st_name='Null')
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : l23_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : l23_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : l23_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})
        #OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : l23_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (14,12)}).plot({'Vm_plot.y_lim' : (-67,-56),'Conductance_plot.y_lim' : (0,35.0)})

        #  PLOT ORIENTATION TUNING
        dsv = param_filter_query(
            data_store,
            st_name='FullfieldDriftingSinusoidalGrating',
            analysis_algorithm=['TrialAveragedFiringRate'])
        PlotTuningCurve(dsv,
                        ParameterSet({
                            'parameter_name': 'contrast',
                            'neurons': l4_spike_exc_or_close_to_pi_half,
                            'sheet_name': 'V1_Exc_L4'
                        }),
                        plot_file_name="CTC.png",
                        fig_param={
                            'dpi': 200,
                            'figsize': (14, 3)
                        }).plot({'TuningCurve_firing_rate.y_lim': (0, 50)})
        CTC(dsv,
            ParameterSet({
                'l4_exc_neurons':
                numpy.array(l4_spike_exc_or_close_to_pi_half)[:4].tolist(),
                'l4_inh_neurons':
                numpy.array(l4_spike_inh_or_close_to_pi_half)[:4].tolist(),
                'l23_exc_neurons':
                numpy.array(l23_spike_exc_or_close_to_pi_half)[:4].tolist(),
                'l23_inh_neurons':
                numpy.array(l23_spike_inh_or_close_to_pi_half)[:4].tolist()
            }),
            fig_param={
                'dpi': 100,
                'figsize': (14, 12)
            },
            plot_file_name="CTC.svg").plot({'*.title': None})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'contrast', 'neurons': l4_spike_inh_or_close_to_pi_half, 'sheet_name' : 'V1_Inh_L4'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'contrast', 'neurons': l23_spike_exc_or_close_to_pi_half, 'sheet_name' : 'V1_Exc_L2/3'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'contrast', 'neurons': l23_spike_inh_or_close_to_pi_half, 'sheet_name' : 'V1_Inh_L2/3'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})

        #  PLOT SIZETUNING
        #dsv = param_filter_query(data_store,st_name='DriftingSinusoidalGratingDisk',analysis_algorithm=['TrialAveragedFiringRate'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'radius', 'neurons': l4_spike_exc_or_close_to_pi_half, 'sheet_name' : 'V1_Exc_L4'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'radius', 'neurons': l4_spike_inh_or_close_to_pi_half, 'sheet_name' : 'V1_Inh_L4'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'radius', 'neurons': l23_spike_exc_or_close_to_pi_half, 'sheet_name' : 'V1_Exc_L2/3'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'radius', 'neurons': l23_spike_inh_or_close_to_pi_half, 'sheet_name' : 'V1_Inh_L2/3'})).plot({'TuningCurve_firing_rate.y_lim' : (0,50)})
        #STC(dsv,ParameterSet({'l4_exc_neurons' : numpy.array(l4_spike_exc_or_close_to_pi_half)[:6].tolist(),'l4_inh_neurons' : numpy.array(l4_spike_inh_or_close_to_pi_half)[:6].tolist(),'l23_exc_neurons' : numpy.array(l23_spike_exc_or_close_to_pi_half)[:6].tolist(),'l23_inh_neurons' : numpy.array(l23_spike_inh_or_close_to_pi_half)[:6].tolist()}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/STC.png").plot({'*.title' : None})

        # PLOT OCTC
        #dsv = param_filter_query(data_store,st_name='DriftingSinusoidalGratingCenterSurroundStimulus',analysis_algorithm=['TrialAveragedFiringRate'])
        #OCTC(dsv,ParameterSet({'l4_exc_neurons' : numpy.array(l4_spike_exc_or_close_to_pi_half)[:5].tolist(),'l4_inh_neurons' : numpy.array(l4_spike_inh_or_close_to_pi_half)[:5].tolist(),'l23_exc_neurons' : numpy.array(l23_spike_exc_or_close_to_pi_half).tolist()[:5],'l23_inh_neurons' : numpy.array(l23_spike_inh_or_close_to_pi_half)[:5].tolist()}),fig_param={'dpi' : 100,'figsize': (14,12)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/OCTC.png").plot({'*.title' : None})

        # tuninc curves
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialAveragedFiringRate','Analog_F0andF1'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l4_analog_ids), 'sheet_name' : 'V1_Exc_L4'})).plot()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialAveragedFiringRate','Analog_F0andF1'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l23_analog_ids), 'sheet_name' : 'V1_Exc_L2/3'})).plot()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialAveragedFiringRate','Analog_F0andF1'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l4_analog_ids_inh), 'sheet_name' : 'V1_Inh_L4'})).plot()
        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialAveragedFiringRate','Analog_F0andF1'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l23_analog_ids_inh), 'sheet_name' : 'V1_Inh_L2/3'})).plot()
        #OR(dsv,ParameterSet({'l4_exc_neurons' : numpy.array(l4_spike_exc_or_close_to_pi_half)[:4].tolist(),'l4_inh_neurons' : numpy.array(l4_spike_inh_or_close_to_pi_half)[:4].tolist(),'l23_exc_neurons' : numpy.array(l23_spike_exc_or_close_to_pi_half)[:4].tolist(),'l23_inh_neurons' : numpy.array(l23_spike_inh_or_close_to_pi_half)[:4].tolist()}),fig_param={'dpi' : 100,'figsize': (16,12)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/OR.png").plot({'*.title' : None})

        #MRfig(data_store,ParameterSet({'SimpleSheetName' : 'V1_Exc_L4', 'ComplexSheetName' : 'V1_Exc_L2/3',}),fig_param={'dpi' : 100,'figsize': (8,6)},plot_file_name="/home/antolikjan/Doc/Talks/JCUnicMar2013/MR.png").plot()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialVariability'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l4_analog_ids), 'sheet_name' : 'V1_Exc_L4'})).plot()

        #dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGrating',analysis_algorithm=['TrialVariability'])
        #PlotTuningCurve(dsv,ParameterSet({'parameter_name' : 'orientation', 'neurons': list(l4_analog_ids_inh), 'sheet_name' : 'V1_Inh_L4'})).plot()

        import pylab
        pylab.show()
def perform_analysis_and_visualization(data_store):
    analog_ids = param_filter_query(data_store,sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(data_store,sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(data_store,sheet_name="V1_Exc_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(data_store,sheet_name="V1_Inh_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_on = param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_off = param_filter_query(data_store,sheet_name="X_OFF").get_segments()[0].get_stored_spike_train_ids()
    
    
    if True: # PLOTTING
            activity_plot_param =    {
                   'frame_rate' : 5,  
                   'bin_width' : 5.0, 
                   'scatter' :  True,
                   'resolution' : 0
            }       
            
            
            #PSTH(param_filter_query(data_store,st_direct_stimulation_name="None",st_name=['Null']),ParameterSet({'bin_length' : 5.0})).analyse()
            #TrialAveragedFiringRate(param_filter_query(data_store,st_direct_stimulation_name="None",st_name=['Null']),ParameterSet({})).analyse()
            #Irregularity(param_filter_query(data_store,st_direct_stimulation_name="None",st_name=['Null']),ParameterSet({})).analyse()
            #NeuronToNeuronAnalogSignalCorrelations(param_filter_query(data_store,analysis_algorithm='PSTH'),ParameterSet({'convert_nan_to_zero' : True})).analyse()
            #PopulationMean(data_store,ParameterSet({})).analyse()
            
            #data_store.print_content(full_ADS=True)
    
    
            #find neuron with preference closet to 0  
            NeuronAnnotationsToPerNeuronValues(data_store,ParameterSet({})).analyse()
            l4_exc_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Exc_L4')
            l4_exc_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Exc_L4')
            l4_exc = analog_ids[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),l4_exc_phase[0].get_value_by_id(analog_ids))])]
            l4_inh_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Inh_L4')
            l4_inh_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Inh_L4')
            l4_inh = analog_ids_inh[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),l4_inh_phase[0].get_value_by_id(analog_ids_inh))])]
            l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(numpy.array([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_exc_or[0].values,l4_exc_phase[0].values)]) < 0.1)[0]]

            print "Prefered orientation of plotted exc neurons:"
            print 'index ' + str(l4_exc)
            print "Prefered phase of plotted exc neurons:"
            print l4_exc_phase[0].get_value_by_id(l4_exc)
            print "Prefered orientation of plotted inh neurons:"
            print l4_inh_phase[0].get_value_by_id(l4_inh)
            print 'index ' + str(l4_inh)
            print "Prefered phase of plotted inh neurons:"
            print l4_exc_phase[0].get_value_by_id(l4_exc)


            
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='ExcAnalog.png').plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[1], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)}).plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})    
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[2], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)}).plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})
            
            
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)},plot_file_name='InhAnalog.png').plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : analog_ids_inh[1], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)}).plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})
            OverviewPlot(data_store,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : analog_ids_inh[2], 'sheet_activity' : {}}),fig_param={'dpi' : 100,'figsize': (19,12)}).plot({'Vm_plot.y_lim' : (-80,-50),'Conductance_plot.y_lim' : (0,100.0)})
            
            
            
            
            RasterPlot(param_filter_query(data_store,st_name=['Null']),ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neurons' : spike_ids,'trial_averaged_histogram': False}),fig_param={'dpi' : 100,'figsize': (17,5)},plot_file_name='ExcRaster.png').plot({'SpikeRasterPlot.group_trials':True})
            RasterPlot(param_filter_query(data_store,st_name=['Null']),ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neurons' : spike_ids_inh,'trial_averaged_histogram': False}),fig_param={'dpi' : 100,'figsize': (17,5)},plot_file_name='InhRaster.png').plot({'SpikeRasterPlot.group_trials':True})
            RasterPlot(param_filter_query(data_store,st_name=['Null']),ParameterSet({'sheet_name' : 'X_ON', 'neurons' : spike_ids_on,'trial_averaged_histogram': False}),fig_param={'dpi' : 100,'figsize': (17,5)},plot_file_name='ExcRaster.png').plot({'SpikeRasterPlot.group_trials':True})
            RasterPlot(param_filter_query(data_store,st_name=['Null']),ParameterSet({'sheet_name' : 'X_OFF', 'neurons' : spike_ids_off,'trial_averaged_histogram': False}),fig_param={'dpi' : 100,'figsize': (17,5)},plot_file_name='InhRaster.png').plot({'SpikeRasterPlot.group_trials':True})
            
            import pylab
            pylab.show()
from mozaik.storage import queries
from mozaik.controller import Global
Global.root_directory = sys.argv[1] + '/'

setup_logging()

data_store = PickledDataStore(load=True,
                              parameters=ParameterSet({
                                  'root_directory':
                                  sys.argv[1],
                                  'store_stimuli':
                                  False
                              }),
                              replace=True)

NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
analog_ids = queries.param_filter_query(
    data_store,
    sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()

dsv = queries.param_filter_query(data_store, st_name='FlashedBar')
for ads in dsv.get_analysis_result():
    sid = MozaikParametrized.idd(ads.stimulus_id)
    sid.x = 0
    ads.stimulus_id = str(sid)
for seg in dsv.get_segments():
    sid = MozaikParametrized.idd(seg.annotations['stimulus'])
    sid.x = 0
    seg.annotations['stimulus'] = str(sid)
for seg in dsv.get_segments(null=True):
    sid = MozaikParametrized.idd(seg.annotations['stimulus'])
Exemple #12
0
def perform_analysis_and_visualization(data_store):

    sheets = list(set(data_store.sheets()) & set(
        ['V1_Exc_L4', 'V1_Inh_L4', 'V1_Exc_L2/3', 'V1_Inh_L2/3']))
    exc_sheets = list(set(data_store.sheets()) &
                      set(['V1_Exc_L4', 'V1_Exc_L2/3']))
    l23_flag = 'V1_Exc_L2/3' in set(sheets)

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()

    analog_ids = param_filter_query(data_store, sheet_name="V1_Exc_L4").get_segments()[
        0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(
        data_store, sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(data_store, sheet_name="V1_Exc_L4").get_segments()[
        0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(data_store, sheet_name="V1_Inh_L4").get_segments()[
        0].get_stored_spike_train_ids()

    if l23_flag:
        analog_ids23 = param_filter_query(
            data_store, sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_esyn_ids()
        analog_ids_inh23 = param_filter_query(
            data_store, sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_esyn_ids()
        spike_ids23 = param_filter_query(
            data_store, sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_spike_train_ids()
        spike_ids_inh23 = param_filter_query(
            data_store, sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_spike_train_ids()
    else:
        analog_ids23 = None
        analog_ids_inh23 = None

    if l23_flag:
        l23_exc_or = data_store.get_analysis_result(
            identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Exc_L2/3')[0]
        l23_inh_or = data_store.get_analysis_result(
            identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Inh_L2/3')[0]

    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Exc_L4')
    l4_exc_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue', value_name='LGNAfferentPhase', sheet_name='V1_Exc_L4')
    l4_exc = analog_ids[numpy.argmin([circular_dist(o, 0, numpy.pi) for (o, p) in zip(
        l4_exc_or[0].get_value_by_id(analog_ids), l4_exc_phase[0].get_value_by_id(analog_ids))])]
    l4_inh_or = data_store.get_analysis_result(
        identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Inh_L4')
    l4_inh_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue', value_name='LGNAfferentPhase', sheet_name='V1_Inh_L4')
    l4_inh = analog_ids_inh[numpy.argmin([circular_dist(o, 0, numpy.pi) for (o, p) in zip(
        l4_inh_or[0].get_value_by_id(analog_ids_inh), l4_inh_phase[0].get_value_by_id(analog_ids_inh))])]
    l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(numpy.array([circular_dist(
        o, 0, numpy.pi) for (o, p) in zip(l4_exc_or[0].values, l4_exc_phase[0].values)]) < 0.1)[0]]

    l4_exc_or_many = list(set(l4_exc_or_many) & set(spike_ids))

    if l23_flag:
        l23_exc_or_many = numpy.array(l23_exc_or.ids)[numpy.nonzero(numpy.array(
            [circular_dist(o, 0, numpy.pi) for o in l23_exc_or.values]) < 0.1)[0]]
        l23_exc_or_many = list(set(l23_exc_or_many) & set(spike_ids23))

    orr = list(set([MozaikParametrized.idd(s).orientation for s in queries.param_filter_query(
        data_store, st_name='FullfieldDriftingSinusoidalGrating', st_contrast=100).get_stimuli()]))

    l4_exc_or_many_analog = numpy.array(analog_ids)[numpy.nonzero(numpy.array(
        [circular_dist(l4_exc_or[0].get_value_by_id(i), 0, numpy.pi) for i in analog_ids]) < 0.1)[0]]
    l4_inh_or_many_analog = numpy.array(analog_ids_inh)[numpy.nonzero(numpy.array(
        [circular_dist(l4_inh_or[0].get_value_by_id(i), 0, numpy.pi) for i in analog_ids_inh]) < 0.15)[0]]

    if l23_flag:
        l23_inh_or_many_analog = numpy.array(analog_ids_inh23)[numpy.nonzero(numpy.array(
            [circular_dist(l23_inh_or.get_value_by_id(i), 0, numpy.pi) for i in analog_ids_inh23]) < 0.15)[0]]
        l23_exc_or_many_analog = numpy.array(analog_ids23)[numpy.nonzero(numpy.array(
            [circular_dist(l23_exc_or.get_value_by_id(i), 0, numpy.pi) for i in analog_ids23]) < 0.1)[0]]

    if True:
        if l23_flag:
            analysis(data_store, analog_ids, analog_ids_inh,
                     analog_ids23, analog_ids_inh23)
        else:
            analysis(data_store, analog_ids, analog_ids_inh)


    if True:  # PLOTTING
        activity_plot_param = {
            'frame_rate': 5,
            'bin_width': 5.0,
            'scatter':  True,
            'resolution': 0
        }

        # self sustained plotting
        dsv = param_filter_query(data_store, st_name=[
                                 'InternalStimulus'], st_direct_stimulation_name=None)
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': analog_ids[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcAnalog.png').plot()
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSInhAnalog.png').plot()

        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcRasterL4.png').plot({'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neurons': spike_ids_inh, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSInhRasterL4.png').plot({'SpikeRasterPlot.group_trials': True})
        if l23_flag:
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': analog_ids23[0], 'sheet_activity': {
            }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcAnalog23.png').plot()
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L2/3', 'neuron': analog_ids_inh23[0], 'sheet_activity': {
            }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSInhAnalog23.png').plot()

            RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neurons': spike_ids23, 'trial_averaged_histogram': False, 'spontaneous': False}),
                       fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcRasterL23.png').plot({'SpikeRasterPlot.group_trials': True})
            RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L2/3', 'neurons': spike_ids_inh23, 'trial_averaged_histogram': False, 'spontaneous': False}),
                       fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSInhRasterL23.png').plot({'SpikeRasterPlot.group_trials': True})

        TrialToTrialVariabilityComparisonNew(data_store, ParameterSet({'sheet_name1': 'V1_Exc_L4', 'sheet_name2': 'V1_Exc_L2/3', 'data_dg': 0.93, 'data_ni': 1.19}), fig_param={
                                             'dpi': 200, 'figsize': (15, 7.5)}, plot_file_name='TrialToTrialVariabilityComparisonNew.png').plot()

        dsv = param_filter_query(
            data_store, st_name='FullfieldDriftingSinusoidalGrating')
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='EvokedExcRaster.png').plot({'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neurons': spike_ids_inh, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='EvokedInhRaster.png').plot({'SpikeRasterPlot.group_trials': True})


        dsv = param_filter_query(
            data_store, st_name='FullfieldDriftingSinusoidalGrating', st_orientation=[0, numpy.pi/2])
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': l4_exc, 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Exc.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': l4_inh, 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Inh.png").plot({'Vm_plot.y_lim': (-80, -50)})

        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': analog_ids[0], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Exc1.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': analog_ids[1], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Exc2.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': analog_ids[2], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Exc3.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': analog_ids[3], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Exc4.png").plot({'Vm_plot.y_lim': (-80, -50)})

        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[0], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Inh1.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[1], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Inh2.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[2], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Inh3.png").plot({'Vm_plot.y_lim': (-80, -50)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[3], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                     'dpi': 100, 'figsize': (25, 12)}, plot_file_name="Inh4.png").plot({'Vm_plot.y_lim': (-80, -50)})

        if l23_flag:
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': analog_ids23[0], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="ExcL231.png").plot({'Vm_plot.y_lim': (-80, -50)})
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': analog_ids23[1], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="ExcL232.png").plot({'Vm_plot.y_lim': (-80, -50)})
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': analog_ids23[2], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="ExcL233.png").plot({'Vm_plot.y_lim': (-80, -50)})

            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L2/3', 'neuron': analog_ids_inh23[0], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="InhL231.png").plot({'Vm_plot.y_lim': (-80, -50)})
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L2/3', 'neuron': analog_ids_inh23[1], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="InhL232.png").plot({'Vm_plot.y_lim': (-80, -50)})
            OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L2/3', 'neuron': analog_ids_inh23[2], 'sheet_activity': {}, 'spontaneous': True}), fig_param={
                         'dpi': 100, 'figsize': (25, 12)}, plot_file_name="InhL233.png").plot({'Vm_plot.y_lim': (-80, -50)})

        if l23_flag:
            SpontActOverview(data_store, ParameterSet({'l4_exc_neuron': analog_ids[0], 'l4_inh_neuron': analog_ids_inh[0], 'l23_exc_neuron': analog_ids23[
                             0], 'l23_inh_neuron': analog_ids_inh23[0]}), plot_file_name='SpontActOverview.png', fig_param={'dpi': 200, 'figsize': (18, 14.5)}).plot()
            OrientationTuningSummaryAnalogSignals(data_store, ParameterSet({'exc_sheet_name1': 'V1_Exc_L4', 'inh_sheet_name1': 'V1_Inh_L4', 'exc_sheet_name2': 'V1_Exc_L2/3', 'inh_sheet_name2': 'V1_Inh_L2/3'}), fig_param={
                                                  'dpi': 200, 'figsize': (18, 12)}, plot_file_name='OrientationTuningSummaryAnalogSignals.png').plot({'*.fontsize': 19, '*.y_lim': (0, None)})
            OrientationTuningSummaryFiringRates(data_store, ParameterSet({'exc_sheet_name1': 'V1_Exc_L4', 'inh_sheet_name1': 'V1_Inh_L4', 'exc_sheet_name2': 'V1_Exc_L2/3', 'inh_sheet_name2': 'V1_Inh_L2/3'}), fig_param={
                                                'dpi': 200, 'figsize': (18, 12)}, plot_file_name='OrientationTuningSummary.png').plot({'*.fontsize': 19})
        else:
            SpontActOverview(data_store, ParameterSet({'l4_exc_neuron': analog_ids[0], 'l4_inh_neuron': analog_ids_inh[0], 'l23_exc_neuron': -1,
                                                       'l23_inh_neuron': -1}), plot_file_name='SpontActOverview.png', fig_param={'dpi': 200, 'figsize': (18, 14.5)}).plot()
            OrientationTuningSummaryAnalogSignals(data_store, ParameterSet({'exc_sheet_name1': 'V1_Exc_L4', 'inh_sheet_name1': 'V1_Inh_L4', 'exc_sheet_name2': 'None', 'inh_sheet_name2': 'None'}), fig_param={
                                                  'dpi': 200, 'figsize': (18, 12)}, plot_file_name='OrientationTuningSummaryAnalogSignals.png').plot({'*.fontsize': 19, '*.y_lim': (0, None)})

        SpontStatisticsOverview(data_store, ParameterSet({}), fig_param={
                                'dpi': 200, 'figsize': (18, 12)}, plot_file_name='SpontStatisticsOverview.png').plot()

        if l23_flag:
            MRfigReal(param_filter_query(data_store, sheet_name=['V1_Exc_L2/3', 'V1_Exc_L4', 'V1_Inh_L2/3', 'V1_Inh_L4'], st_contrast=[100], st_name='FullfieldDriftingSinusoidalGrating'), ParameterSet(
                {'SimpleSheetName': 'V1_Exc_L4', 'ComplexSheetName': 'V1_Exc_L2/3'}), plot_file_name='MRReal.png', fig_param={'dpi': 100, 'figsize': (19, 12)}).plot()
        else:
            MRfigReal(param_filter_query(data_store, sheet_name=['V1_Exc_L2/3', 'V1_Exc_L4', 'V1_Inh_L2/3', 'V1_Inh_L4'], st_contrast=[100], st_name='FullfieldDriftingSinusoidalGrating'), ParameterSet(
                {'SimpleSheetName': 'V1_Exc_L4', 'ComplexSheetName': 'V1_Exc_L2/3'}), plot_file_name='MRReal.png', fig_param={'dpi': 100, 'figsize': (19, 12)}).plot()

        dsv = param_filter_query(
            data_store, st_name='NaturalImageWithEyeMovement')
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': l4_exc, 'sheet_activity': {}, 'spontaneous': True}), plot_file_name='NMExc.png', fig_param={
                     'dpi': 100, 'figsize': (28, 12)}).plot({'Vm_plot.y_lim': (-70, -50), 'Conductance_plot.y_lim': (0, 50.0)})
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': l4_inh, 'sheet_activity': {}, 'spontaneous': True}), plot_file_name='NMInh.png', fig_param={
                     'dpi': 100, 'figsize': (28, 12)}).plot({'Vm_plot.y_lim': (-70, -50), 'Conductance_plot.y_lim': (0, 50.0)})

        TrialCrossCorrelationAnalysis(data_store, ParameterSet({'neurons1': list(analog_ids), 'sheet_name1': 'V1_Exc_L4', 'neurons2': list(
            analog_ids23), 'sheet_name2': 'V1_Exc_L2/3', 'window_length': 250}), fig_param={"dpi": 100, "figsize": (15, 6.5)}, plot_file_name="trial-to-trial-cross-correlation.png").plot({'*.Vm.title': None, '*.fontsize': 19})

        dsv = queries.param_filter_query(data_store, value_name=[
                                         'orientation HWHH of Firing rate', 'orientation CV(Firing rate)'], sheet_name=["V1_Exc_L2/3"], st_contrast=100)
        PerNeuronValueScatterPlot(dsv, ParameterSet({'only_matching_units': False, 'ignore_nan': True}), plot_file_name='CVvsHWHH.png').plot(
            {'*.x_lim': (0, 90), '*.y_lim': (0, 1.0)})

        dsv = param_filter_query(data_store, st_name=['InternalStimulus'])
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Inh_L4', 'neuron': analog_ids_inh[0], 'sheet_activity': {
        }, 'spontaneous': False}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSInhAnalog.png').plot()

        # orientation tuning plotting
        dsv = param_filter_query(data_store,sheet_name=['V1_Exc_L4','V1_Inh_L4'],value_name='LGNAfferentOrientation')
        PerNeuronValuePlot(dsv,ParameterSet({"cortical_view" : True}),plot_file_name='ORSet.png').plot()
Exemple #13
0
def perform_analysis_and_visualization_stc(data_store):
    l23 = 'V1_Exc_L2/3' in set(data_store.sheets())
    analog_ids = param_filter_query(data_store, sheet_name="V1_Exc_L4").get_segments()[
        0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(
        data_store, sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(data_store, sheet_name="V1_Exc_L4").get_segments()[
        0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(data_store, sheet_name="V1_Inh_L4").get_segments()[
        0].get_stored_spike_train_ids()

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()

    if l23:
        analog_ids23 = param_filter_query(
            data_store, sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_esyn_ids()
        analog_ids_inh23 = param_filter_query(
            data_store, sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_esyn_ids()
        spike_ids23 = param_filter_query(
            data_store, sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_spike_train_ids()
        spike_ids_inh23 = param_filter_query(
            data_store, sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_spike_train_ids()
        l23_exc_or = data_store.get_analysis_result(
            identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Exc_L2/3')[0]
        l23_exc_or_many = numpy.array(spike_ids23)[numpy.nonzero(numpy.array([circular_dist(
            l23_exc_or.get_value_by_id(i), 0, numpy.pi) for i in spike_ids23]) < 0.25)[0]]
        idx23 = data_store.get_sheet_indexes(
            sheet_name='V1_Exc_L2/3', neuron_ids=l23_exc_or_many)

    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue', value_name='LGNAfferentOrientation', sheet_name='V1_Exc_L4')[0]
    l4_exc_or_many = numpy.array(spike_ids)[numpy.nonzero(numpy.array([circular_dist(
        l4_exc_or.get_value_by_id(i), 0, numpy.pi) for i in spike_ids]) < 0.25)[0]]
    idx4 = data_store.get_sheet_indexes(
        sheet_name='V1_Exc_L4', neuron_ids=l4_exc_or_many)

    x = data_store.get_neuron_positions()['V1_Exc_L4'][0][idx4]
    y = data_store.get_neuron_positions()['V1_Exc_L4'][1][idx4]
    center4 = l4_exc_or_many[numpy.nonzero(numpy.sqrt(
        numpy.multiply(x, x)+numpy.multiply(y, y)) < 0.4)[0]]
    analog_center4 = set(center4).intersection(analog_ids)
    logger.info(str(analog_center4))

    if l23:
        x = data_store.get_neuron_positions()['V1_Exc_L2/3'][0][idx23]
        y = data_store.get_neuron_positions()['V1_Exc_L2/3'][1][idx23]
        center23 = l23_exc_or_many[numpy.nonzero(numpy.sqrt(
            numpy.multiply(x, x)+numpy.multiply(y, y)) < 0.4)[0]]
        analog_center23 = set(center23).intersection(analog_ids23)
        logger.info(str(analog_center23))

    if True:
        TrialAveragedFiringRate(param_filter_query(data_store, sheet_name=[
                                'V1_Exc_L4', 'V1_Exc_L2/3'], st_name='DriftingSinusoidalGratingDisk'), ParameterSet({})).analyse()

        dsv = param_filter_query(data_store, sheet_name=[
                                 'V1_Exc_L4', 'V1_Exc_L2/3'], st_name='DriftingSinusoidalGratingDisk')
        Analog_F0andF1(dsv, ParameterSet({})).analyse()

        dsv = param_filter_query(
            data_store, st_name='InternalStimulus', st_direct_stimulation_name=None)
        Analog_MeanSTDAndFanoFactor(dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L4', analysis_algorithm=[
                                 'Analog_MeanSTDAndFanoFactor'], value_name='Mean(VM)', st_direct_stimulation_name=None).get_analysis_result()[0]
        dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                 sheet_name='V1_Exc_L4', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Vm')
        OperationPNVfromPNVS(pnv, lambda x, y: -(x+y),
                             '-(x+y)', dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L4', analysis_algorithm=[
                                 'Analog_MeanSTDAndFanoFactor'], value_name='Mean(ECond)', st_direct_stimulation_name=None).get_analysis_result()[0]
        dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                 sheet_name='V1_Exc_L4', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Exc_Cond')
        OperationPNVfromPNVS(pnv, lambda x, y: x-y, 'x-y',
                             dsv, ParameterSet({})).analyse()

        pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L4', analysis_algorithm=[
                                 'Analog_MeanSTDAndFanoFactor'], value_name='Mean(ICond)', st_direct_stimulation_name=None).get_analysis_result()[0]
        dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                 sheet_name='V1_Exc_L4', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Inh_Cond')
        OperationPNVfromPNVS(pnv, lambda x, y: x-y, 'x-y',
                             dsv, ParameterSet({})).analyse()

        if l23:
            pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L2/3', analysis_algorithm=[
                                     'Analog_MeanSTDAndFanoFactor'], value_name='Mean(VM)', st_direct_stimulation_name=None).get_analysis_result()[0]
            dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                     sheet_name='V1_Exc_L2/3', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Vm')
            OperationPNVfromPNVS(pnv, lambda x, y: -(x+y),
                                 '-(x+y)', dsv, ParameterSet({})).analyse()

            pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L2/3', analysis_algorithm=[
                                     'Analog_MeanSTDAndFanoFactor'], value_name='Mean(ECond)', st_direct_stimulation_name=None).get_analysis_result()[0]
            dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                     sheet_name='V1_Exc_L2/3', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Exc_Cond')
            OperationPNVfromPNVS(pnv, lambda x, y: x-y,
                                 'x-y', dsv, ParameterSet({})).analyse()

            pnv = param_filter_query(data_store, st_name='InternalStimulus', sheet_name='V1_Exc_L2/3', analysis_algorithm=[
                                     'Analog_MeanSTDAndFanoFactor'], value_name='Mean(ICond)', st_direct_stimulation_name=None).get_analysis_result()[0]
            dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                     sheet_name='V1_Exc_L2/3', analysis_algorithm=['Analog_F0andF1'], value_name='F0_Inh_Cond')
            OperationPNVfromPNVS(pnv, lambda x, y: x-y,
                                 'x-y', dsv, ParameterSet({})).analyse()

        dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk',
                                 analysis_algorithm='TrialAveragedFiringRate', value_name='Firing rate')

        SizeTuningAnalysis(dsv, ParameterSet(
            {'neurons': center4.tolist(), 'sheet_name': 'V1_Exc_L4'})).analyse()
        if l23:
            SizeTuningAnalysis(dsv, ParameterSet(
                {'neurons': center23.tolist(), 'sheet_name': 'V1_Exc_L2/3'})).analyse()
        data_store.save()

    dsv = param_filter_query(data_store, st_name='DriftingSinusoidalGratingDisk', analysis_algorithm=[
                             'TrialAveragedFiringRate'], value_name="Firing rate")
    PlotTuningCurve(dsv, ParameterSet({'parameter_name': 'radius', 'neurons': list(center4), 'sheet_name': 'V1_Exc_L4', 'centered': False,
                                       'mean': False, 'polar': False, 'pool': False}), plot_file_name='SizeTuningExcL4.png', fig_param={'dpi': 100, 'figsize': (32, 7)}).plot()
    PlotTuningCurve(dsv, ParameterSet({'parameter_name': 'radius', 'neurons': list(center4), 'sheet_name': 'V1_Exc_L4', 'centered': False,
                                       'mean': True, 'polar': False, 'pool': False}), plot_file_name='SizeTuningExcL4M.png', fig_param={'dpi': 100, 'figsize': (32, 7)}).plot()

    if l23:
        PlotTuningCurve(dsv, ParameterSet({'parameter_name': 'radius', 'neurons': list(center23), 'sheet_name': 'V1_Exc_L2/3', 'centered': False,
                                           'mean': False, 'polar': False, 'pool': False}), plot_file_name='SizeTuningExcL23.png', fig_param={'dpi': 100, 'figsize': (32, 7)}).plot()
        PlotTuningCurve(dsv, ParameterSet({'parameter_name': 'radius', 'neurons': list(center23), 'sheet_name': 'V1_Exc_L2/3', 'centered': False,
                                           'mean': True, 'polar': False, 'pool': False}), plot_file_name='SizeTuningExcL23M.png', fig_param={'dpi': 100, 'figsize': (32, 7)}).plot()

    if True:
        dsv = param_filter_query(data_store, st_name=[
                                 'DriftingSinusoidalGratingDisk'])
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': list(analog_center4)[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL4_1.png').plot()

        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': list(analog_center23)[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL23_1.png').plot()

    if l23:
        SizeTuningOverview(data_store, ParameterSet({'l4_neurons': list(center4), 'l23_neurons': list(center23), 'l4_neurons_analog': list(
            analog_center4), 'l23_neurons_analog': list(analog_center23)}), plot_file_name='SizeTuningOverview.png', fig_param={'dpi': 300, 'figsize': (18, 8)}).plot()
        SizeTuningOverviewNew(data_store, ParameterSet({'l4_neurons': list(center4), 'l23_neurons': list(center23), 'l4_neurons_analog': list(
            analog_center4), 'l23_neurons_analog': list(analog_center23)}), plot_file_name='SizeTuningOverviewNew.png', fig_param={'dpi': 300, 'figsize': (18, 8)}).plot()
    else:
        SizeTuningOverview(data_store, ParameterSet({'l4_neurons': list(center4), 'l23_neurons': [], 'l4_neurons_analog': list(
            analog_center4), 'l23_neurons_analog': []}), plot_file_name='SizeTuningOverview.png', fig_param={'dpi': 300, 'figsize': (18, 8)}).plot()
        SizeTuningOverviewNew(data_store, ParameterSet({'l4_neurons': list(center4), 'l23_neurons': [], 'l4_neurons_analog': list(
            analog_center4), 'l23_neurons_analog': []}), plot_file_name='SizeTuningOverviewNew.png', fig_param={'dpi': 300, 'figsize': (18, 8)}).plot()

    if True:
        dsv = param_filter_query(data_store, st_name=[
                                 'DriftingSinusoidalGratingDisk'], st_size=[5.0])
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': list(analog_center4)[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL4_Small1.png').plot()
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': list(analog_center4)[1], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL4_Small2.png').plot()
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neuron': list(analog_center4)[2], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL4_Small3.png').plot()

        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': list(analog_center23)[0], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL23_Small1.png').plot()
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': list(analog_center23)[1], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL23_Small2.png').plot()
        OverviewPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neuron': list(analog_center23)[2], 'sheet_activity': {
        }, 'spontaneous': True}), fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='Overview_ExcL23_Small3.png').plot()

        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='EvokedExcRasterL4.png').plot({'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}),
                   fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='EvokedExcRasterL2/3.png').plot({'SpikeRasterPlot.group_trials': True})

        dsv = param_filter_query(data_store, st_name=['InternalStimulus'])
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L4', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}), fig_param={
                   'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcRasterL4.png').plot({'SpikeRasterPlot.group_trials': True})
        RasterPlot(dsv, ParameterSet({'sheet_name': 'V1_Exc_L2/3', 'neurons': spike_ids, 'trial_averaged_histogram': False, 'spontaneous': False}),
                   fig_param={'dpi': 100, 'figsize': (28, 12)}, plot_file_name='SSExcRasterL2/3.png').plot({'SpikeRasterPlot.group_trials': True})
Exemple #14
0
def LFP(sheet,
        folder,
        stimulus,
        parameter,
        tip=[.0, .0, .0],
        sigma=0.300,
        ylim=[0., -1.],
        addon="",
        color='black'):
    import matplotlib as ml
    import quantities as pq
    print inspect.stack()[0][3]
    print "folder: ", folder
    print "sheet: ", sheet

    data_store = PickledDataStore(load=True,
                                  parameters=ParameterSet({
                                      'root_directory':
                                      folder,
                                      'store_stimuli':
                                      False
                                  }),
                                  replace=True)
    data_store.print_content(full_recordings=False)

    ids = param_filter_query(
        data_store, sheet_name=sheet,
        st_name=stimulus).get_segments()[0].get_stored_esyn_ids()
    if ids == None or len(ids) < 1:
        print "No gesyn recorded.\n"
        return
    print "Recorded gesyn:", len(ids), ids

    ids = param_filter_query(
        data_store, sheet_name=sheet,
        st_name=stimulus).get_segments()[0].get_stored_vm_ids()
    if ids == None or len(ids) < 1:
        print "No Vm recorded.\n"
        return
    print "Recorded Vm:", len(ids), ids

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name=sheet)[0]
    l4_exc_or_many = numpy.array(ids)[numpy.nonzero(
        numpy.array([
            circular_dist(l4_exc_or.get_value_by_id(i), 0, numpy.pi)
            for i in ids
        ]) < .1)[0]]
    ids = list(l4_exc_or_many)

    print "Recorded neurons:", len(ids), ids
    # 900 neurons over 6000 micrometers, 200 micrometers interval

    sheet_indexes = data_store.get_sheet_indexes(sheet_name=sheet,
                                                 neuron_ids=ids)

    positions = data_store.get_neuron_postions()[sheet]
    print positions.shape  # all 10800

    # take the positions of the ids
    ids_positions = numpy.transpose(positions)[sheet_indexes, :]
    print ids_positions.shape
    print ids_positions

    # Pre-compute distances from the LFP tip
    distances = []
    for i in range(len(ids)):
        distances.append(
            numpy.linalg.norm(
                numpy.array(ids_positions[i][0]) - numpy.array(tip)))
    distances = numpy.array(distances)
    print "distances:", len(distances), distances

    # ##############################
    # LFP
    # tip = [[x],[y],[.0]]
    # For each recorded cell:
    # Gaussianly weight it by its distance from tip
    # produce the currents
    # Divide the whole by the norm factor (area): 4 * numpy.pi * sigma

    # 95% of the LFP signal is a result of all exc and inh cells conductances from 250um radius from the tip of the electrode (Katzner et al. 2009).
    # Mostly excitatory neurons are relevant for the LFP (because of their geometry) Bartos
    # Therefore we include all recorded cells but account for the distance-dependent contribution weighting currents /r^2
    # We assume that the electrode has been placed in the cortical coordinates <tip>
    # Given that the current V1 orientation map has a pixel for each 100 um, a reasonable way to look at a neighborhood is in a radius of 300 um

    print "LFP electrode tip location (x,y) in degrees:", tip

    # Gather vm and conductances
    segs = sorted(
        param_filter_query(data_store, st_name=stimulus,
                           sheet_name=sheet).get_segments(),
        key=lambda x: getattr(
            MozaikParametrized.idd(x.annotations['stimulus']), parameter))
    ticks = set([])
    for x in segs:
        ticks.add(
            getattr(MozaikParametrized.idd(x.annotations['stimulus']),
                    parameter))
    ticks = sorted(ticks)
    num_ticks = len(ticks)
    print ticks
    trials = len(segs) / num_ticks
    print "trials:", trials

    pop_vm = []
    pop_gsyn_e = []
    pop_gsyn_i = []
    for n, idd in enumerate(ids):
        print "idd", idd
        full_vm = [s.get_vm(idd) for s in segs]  # all segments
        full_gsyn_es = [s.get_esyn(idd) for s in segs]
        full_gsyn_is = [s.get_isyn(idd) for s in segs]
        print "len full_gsyn_e", len(
            full_gsyn_es)  # segments = stimuli * trials
        print "shape gsyn_e[0]", full_gsyn_es[0].shape  # stimulus lenght
        # mean input over trials
        mean_full_vm = numpy.zeros((num_ticks, full_vm[0].shape[0]))  # init
        mean_full_gsyn_e = numpy.zeros(
            (num_ticks, full_gsyn_es[0].shape[0]))  # init
        mean_full_gsyn_i = numpy.zeros((num_ticks, full_gsyn_es[0].shape[0]))
        # print "shape mean_full_gsyn_e/i", mean_full_gsyn_e.shape
        sampling_period = full_gsyn_es[0].sampling_period
        t_stop = float(full_gsyn_es[0].t_stop - sampling_period)  # 200.0
        t_start = float(full_gsyn_es[0].t_start)
        time_axis = numpy.arange(0, len(full_gsyn_es[0]), 1) / float(
            len(full_gsyn_es[0])) * abs(t_start - t_stop) + t_start
        # sum by size
        t = 0
        for v, e, i in zip(full_vm, full_gsyn_es, full_gsyn_is):
            s = int(t / trials)
            v = v.rescale(mozaik.tools.units.mV)
            e = e.rescale(
                mozaik.tools.units.nS)  # NEST is in nS, PyNN is in uS
            i = i.rescale(
                mozaik.tools.units.nS)  # NEST is in nS, PyNN is in uS
            mean_full_vm[s] = mean_full_vm[s] + numpy.array(v.tolist())
            mean_full_gsyn_e[s] = mean_full_gsyn_e[s] + numpy.array(e.tolist())
            mean_full_gsyn_i[s] = mean_full_gsyn_i[s] + numpy.array(i.tolist())
            t = t + 1

        # average by trials
        for st in range(num_ticks):
            mean_full_vm[st] = mean_full_vm[st] / trials
            mean_full_gsyn_e[st] = mean_full_gsyn_e[st] / trials
            mean_full_gsyn_i[st] = mean_full_gsyn_i[st] / trials

        pop_vm.append(mean_full_vm)
        pop_gsyn_e.append(mean_full_gsyn_e)
        pop_gsyn_i.append(mean_full_gsyn_i)

    pop_v = numpy.array(pop_vm)
    pop_e = numpy.array(pop_gsyn_e)
    pop_i = numpy.array(pop_gsyn_i)

    # Produce the current for each cell for this time interval, with the Ohm law:
    # I = ge(V-Ee) + gi(V+Ei)
    # where
    # Ee is the equilibrium for exc, which is 0.0
    # Ei is the equilibrium for inh, which is -80.0
    i = pop_e * (pop_v - 0.0) + pop_i * (pop_v - 80.0)
    # i = pop_e*(pop_v-0.0) + 0.3*pop_i*(pop_v-80.0)
    # i = pop_e*(pop_v-0.0) # only exc
    # the LFP is the result of cells' currents divided by the distance
    sum_i = numpy.sum(i, axis=0)
    lfp = sum_i / (4 * numpy.pi * sigma)  #
    lfp /= 1000.  # from milli to micro
    print "LFP:", lfp.shape, lfp.mean(), lfp.min(), lfp.max()
    # print lfp
    # lfp = np.convolve(lfp, np.ones((10,))/10, mode='valid') # moving avg or running mean implemented as a convolution over steps of 10, divided by 10
    # lfp = np.convolve(lfp, np.ones((10,))/10, mode='valid') # moving avg or running mean implemented as a convolution over steps of 10, divided by 10

    #plot the LFP for each stimulus
    for s in range(num_ticks):
        # for each stimulus plot the average conductance per cell over time
        matplotlib.rcParams.update({'font.size': 22})
        fig, ax = plt.subplots()

        ax.plot(range(0, len(lfp[s])), lfp[s], color=color, linewidth=3)

        # ax.set_ylim([lfp.min(), lfp.max()])
        ax.set_ylim(ylim)
        ax.set_ylabel("LFP (uV)")
        ax.set_xlabel("Time (us)")
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        ax.xaxis.set_ticks(ticks, ticks)
        ax.yaxis.set_ticks_position('left')

        # text
        plt.tight_layout()
        plt.savefig(folder + "/TimecourseLFP_" + sheet + "_" + parameter +
                    "_" + str(ticks[s]) + "_" + addon + ".svg",
                    dpi=200,
                    transparent=True)
        fig.clf()
        plt.close()
        # garbage
        gc.collect()
def perform_analysis_and_visualization(data_store,gratings,cort_stim,nat_stim,tp,scale=True,sharpness=False,lee_size=False):
    scales = [0.01,0.07,0.14,1.0];
    
    sheets = list(set(data_store.sheets()) & set(['V1_Exc_L4','V1_Inh_L4']))
    exc_sheets = list(set(data_store.sheets()) & set(['V1_Exc_L4']))
    
    NeuronAnnotationsToPerNeuronValues(data_store,ParameterSet({})).analyse()
    
    analog_ids = param_filter_query(data_store,sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(data_store,sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    analog_ids23 = param_filter_query(data_store,sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_esyn_ids()
    analog_ids_inh23 = param_filter_query(data_store,sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_esyn_ids()

    spike_ids = param_filter_query(data_store,sheet_name="V1_Exc_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(data_store,sheet_name="V1_Inh_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids23 = param_filter_query(data_store,sheet_name="V1_Exc_L2/3").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_inh23 = param_filter_query(data_store,sheet_name="V1_Inh_L2/3").get_segments()[0].get_stored_spike_train_ids()
    
    l4_exc_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Exc_L4')
    l4_exc_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Exc_L4')
    l4_exc = analog_ids[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),l4_exc_phase[0].get_value_by_id(analog_ids))])]
    l4_inh_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Inh_L4')
    l4_inh_phase = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentPhase', sheet_name = 'V1_Inh_L4')
    l4_inh = analog_ids_inh[numpy.argmin([circular_dist(o,numpy.pi/2,numpy.pi)  for (o,p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),l4_inh_phase[0].get_value_by_id(analog_ids_inh))])]
    l4_exc_or_many = numpy.array(l4_exc_or[0].ids)[numpy.nonzero(numpy.array([circular_dist(o,0,numpy.pi)  for (o,p) in zip(l4_exc_or[0].values,l4_exc_phase[0].values)]) < 0.1)[0]]
    l4_exc_or_many = list(set(l4_exc_or_many) &  set(spike_ids))

    l23_exc_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Exc_L2/3')[0]
    l23_inh_or = data_store.get_analysis_result(identifier='PerNeuronValue',value_name = 'LGNAfferentOrientation', sheet_name = 'V1_Inh_L2/3')[0]
    l23_exc_or_many = numpy.array(spike_ids23)[numpy.nonzero(numpy.array([circular_dist(l23_exc_or.get_value_by_id(i),0,numpy.pi)  for i in spike_ids23]) < 0.1)[0]]
    l23_exc_or_many_analog = numpy.array(analog_ids23)[numpy.nonzero(numpy.array([circular_dist(l23_exc_or.get_value_by_id(i),0,numpy.pi)  for i in analog_ids23]) < 0.1)[0]]
    l23_exc_or_many_analog_inh = numpy.array(analog_ids_inh23)[numpy.nonzero(numpy.array([circular_dist(l23_inh_or.get_value_by_id(i),0,numpy.pi)  for i in analog_ids_inh23]) < 0.1)[0]]
    l23_exc_or_many = list(set(l23_exc_or_many) &  set(spike_ids23))


        
    orr = list(set([MozaikParametrized.idd(s).orientation for s in queries.param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGratingA',st_contrast=100).get_stimuli()]))                
        
    l4_exc_or_many_analog = numpy.array(analog_ids)[numpy.nonzero(numpy.array([circular_dist(l4_exc_or[0].get_value_by_id(i),0,numpy.pi)  for i in analog_ids]) < 0.1)[0]]
    l4_inh_or_many_analog = numpy.array(analog_ids_inh)[numpy.nonzero(numpy.array([circular_dist(l4_inh_or[0].get_value_by_id(i),0,numpy.pi)  for i in analog_ids_inh]) < 0.15)[0]]

    lgn_on_ids = param_filter_query(data_store,sheet_name="X_ON").get_segments()[0].get_stored_spike_train_ids()
    lgn_off_ids = param_filter_query(data_store,sheet_name="X_OFF").get_segments()[0].get_stored_spike_train_ids()

    analysis(data_store,analog_ids23,l23_exc_or_many,analog_ids_inh23,gratings,cort_stim,scale)

    data_store.save()

    def overviews(dsv,name_prefix):
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : analog_ids23[0], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23ExcAnalog1.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : analog_ids_inh23[0], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23InhAnalog1.png').plot()    
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : analog_ids23[1], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23ExcAnalog2.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : analog_ids_inh23[1], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23InhAnalog2.png').plot()    
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : analog_ids23[2], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23ExcAnalog3.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neuron' : analog_ids_inh23[2], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L23InhAnalog3.png').plot()    

        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[0], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4ExcAnalog1.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : analog_ids_inh[0], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4InhAnalog1.png').plot()    
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[1], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4ExcAnalog2.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : analog_ids_inh[1], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4InhAnalog2.png').plot()    
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : analog_ids[2], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4ExcAnalog3.png').plot()
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : analog_ids_inh[2], 'sheet_activity' : {}, 'spontaneous' : True}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'L4InhAnalog3.png').plot()    


        RasterPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neurons' : spike_ids,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'SSExcRasterL4.png').plot({'SpikeRasterPlot.group_trials':True})
        RasterPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neurons' : spike_ids_inh,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'SSInhRasterL4.png').plot({'SpikeRasterPlot.group_trials':True})
    
        RasterPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neurons' : spike_ids23,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'SSExcRasterL23.png').plot({'SpikeRasterPlot.group_trials':True})
        RasterPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L2/3', 'neurons' : spike_ids_inh23,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'SSInhRasterL23.png').plot({'SpikeRasterPlot.group_trials':True})

        RasterPlot(dsv,ParameterSet({'sheet_name' : 'X_ON', 'neurons' : lgn_on_ids,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'XONRaster.png').plot({'SpikeRasterPlot.group_trials':True})
        RasterPlot(dsv,ParameterSet({'sheet_name' : 'X_OFF', 'neurons' : lgn_off_ids,'trial_averaged_histogram': False, 'spontaneous' : False}),fig_param={'dpi' : 100,'figsize': (28,12)},plot_file_name=name_prefix+'XOFFRasterL4.png').plot({'SpikeRasterPlot.group_trials':True})

    # spontaneous activity overview
    dsv = param_filter_query(data_store,st_name='InternalStimulus',st_direct_stimulation_name=None)   
    overviews(dsv,"SPONT_")

    x = data_store.get_neuron_postions()['V1_Exc_L2/3'][0]
    y = data_store.get_neuron_postions()['V1_Exc_L2/3'][1]
    depth = data_store.get_neuron_postions()['V1_Exc_L2/3'][2]
    ors = numpy.array(l23_exc_or.ids)[numpy.nonzero(numpy.array([circular_dist(o,0,numpy.pi) for o in l23_exc_or.values]) < 0.15)[0]]
    close_spikes = numpy.array([a for a in ors if (a in spike_ids23)])
    close_spikes_sheet_indexes = data_store.get_sheet_indexes(sheet_name='V1_Exc_L2/3',neuron_ids=close_spikes)
    close_spikes = close_spikes[numpy.sqrt(x[close_spikes_sheet_indexes]**2 + y[close_spikes_sheet_indexes]**2)<1.5]
    depth_of_close_spikes = depth[data_store.get_sheet_indexes(sheet_name='V1_Exc_L2/3',neuron_ids=close_spikes)]
    depth_of_close_spikes, close_spikes = zip(*sorted(zip(depth_of_close_spikes,close_spikes),reverse=True))
    close_analogs = list(set(close_spikes) & set(analog_ids23))

    if cort_stim:
	if sharpness:
	    OrientationTuningSharpness(data_store,ParameterSet({}),fig_param={'dpi' : 300,'figsize': (13,10)},plot_file_name='Sharpness.png').plot()
	    return;
	if lee_size:
	    OrientationTuningLEE_size(data_store,ParameterSet({}),fig_param={'dpi' : 300,'figsize': (13,10)},plot_file_name='LEESizeFigure.png').plot()
	    return;

	if scale:
		ContrastResponse(data_store,ParameterSet({'cortical_stimulation' : True}),fig_param={'dpi' : 100,'figsize': (9,3.6)},plot_file_name='ContrastResponse.png').plot()
	else:
		ContrastResponseTransformed(data_store,ParameterSet({'cortical_stimulation' : True, 'type' : tp }),fig_param={'dpi' : 100,'figsize': (9,3.6)},plot_file_name='ContrastResponseTransformed.png').plot()

	if scale:
            dsv = param_filter_query(data_store,st_name='InternalStimulus',st_direct_stimulation_name="LocalStimulatorArray")
	    LightStimulationOverview(data_store,ParameterSet({}),fig_param={'dpi' : 300,'figsize': (18,6.9)},plot_file_name='LightStimulationOverview.png').plot({'*.SpikeRasterPlot.group_trials':True,'*.SpikeRasterPlot.x_label':'neuron #','*.title' : None,'Conductance_plot.y_lim' : (0,170)})

	if scale:
        	dsv = queries.param_filter_query(data_store,st_name='InternalStimulus',st_direct_stimulation_name='LocalStimulatorArray',st_stimulating_signal_parameters_scale = [0.08],st_stimulating_signal_parameters_orientation = 0)
	else:
		dsv = queries.param_filter_query(data_store,st_name='InternalStimulus',st_direct_stimulation_name='LocalStimulatorArray',st_stimulating_signal_parameters_contrast = [100],st_stimulating_signal_parameters_orientation = 0)
	ResponseOverview(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : close_analogs[12] }),fig_param={'dpi' : 100,'figsize': (16,2.5)},plot_file_name='ResponseOverview.png').plot({ 'Conductance_plot.y_lim' : (0,150)})    



	overviews(dsv,"CS_")

	if scale:
		OrientationTuningSummaryFiringRates(data_store,ParameterSet({'cortical_stimulation' : True, 'scale' : True}),plot_file_name='OrientationTuning.png',fig_param={'dpi' : 100,'figsize': (18,3.6)}).plot()
	else:
		OrientationTuningSummaryFiringRates(data_store,ParameterSet({'cortical_stimulation' : True, 'scale' : False}),plot_file_name='OrientationTuning.png',fig_param={'dpi' : 100,'figsize': (18,3.6)}).plot()

	StatisticsOverview(data_store,ParameterSet({'cortical_stimulation' : True ,'type' : tp, 'window_length': 200}),plot_file_name='StatisticsOverview.png',fig_param={'dpi' : 100,'figsize': (12,8)}).plot()

    if gratings:
        dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGratingA',st_orientation=[0,numpy.pi/2],st_contrast=100)   
        overviews(dsv,"GR_")
	dsv = param_filter_query(data_store,st_name='FullfieldDriftingSinusoidalGratingA',st_orientation=[0],st_contrast=100)   
	ResponseOverview(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L2/3', 'neuron' : close_analogs[12] }),fig_param={'dpi' : 100,'figsize': (16,2.5)},plot_file_name='ResponseOverview.png').plot({ 'Conductance_plot.y_lim' : (0,150)})
	ContrastResponseTransformed(data_store,ParameterSet({'cortical_stimulation' : False, 'type' : tp }),fig_param={'dpi' : 100,'figsize': (9,3.6)},plot_file_name='ContrastResponseTransformed.png').plot()

	OrientationTuningSummaryFiringRates(data_store,ParameterSet({'cortical_stimulation' : False, 'scale' : False}),plot_file_name='OrientationTuning.png',fig_param={'dpi' : 100,'figsize': (18,3.6)}).plot()
	StatisticsOverview(data_store,ParameterSet({'cortical_stimulation' : False ,'type' : tp, 'window_length': 50}),plot_file_name='StatisticsOverview.png',fig_param={'dpi' : 100,'figsize': (12,8)}).plot()

        if False:
                pref_fr_100 = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],st_contrast=[100],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0],ads_unique=True).get_analysis_result()[0].get_value_by_id(l4_exc_or_many)
                ort_fr_100 = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],st_contrast=[100],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[numpy.pi/2],ads_unique=True).get_analysis_result()[0].get_value_by_id(l4_exc_or_many)
                pref_fr_50 = 0
                ort_fr_50 = 0
                if len(param_filter_query(data_store,sheet_name=['V1_Exc_L4'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0]).get_analysis_result()) != 0:    
                    pref_fr_50 = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0],ads_unique=True).get_analysis_result()[0].get_value_by_id(l4_exc_or_many)
                    ort_fr_50 = param_filter_query(data_store,sheet_name=['V1_Exc_L4'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[numpy.pi/2],ads_unique=True).get_analysis_result()[0].get_value_by_id(l4_exc_or_many)
                spont = param_filter_query(data_store,st_name='InternalStimulus',sheet_name=['V1_Exc_L4'],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',ads_unique=True).get_analysis_result()[0].get_value_by_id(l4_exc_or_many)

                pylab.figure()
                pylab.bar([1,2,3,4,5],[numpy.mean(pref_fr_100),numpy.mean(ort_fr_100),numpy.mean(pref_fr_50),numpy.mean(ort_fr_50),numpy.mean(spont)])
                pylab.xticks([1.4,2.4,3.4,4.4,5.4],['PREF100','ORT100','PREF50','ORT50','SPONT'])
                pylab.xlim([0.8,6.0])
                pylab.ylabel("Firing rate")
                pylab.savefig(Global.root_directory+"Orientation_responseL4.png")
                if True:
                    pref_fr_100 = param_filter_query(data_store,sheet_name=['V1_Exc_L2/3'],st_contrast=[100],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0],ads_unique=True).get_analysis_result()[0].get_value_by_id(l23_exc_or_many)
                    ort_fr_100 = param_filter_query(data_store,sheet_name=['V1_Exc_L2/3'],st_contrast=[100],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[numpy.pi/2],ads_unique=True).get_analysis_result()[0].get_value_by_id(l23_exc_or_many)
                    pref_fr_50 = 0
                    ort_fr_50 = 0
                    
                    if(len(param_filter_query(data_store,sheet_name=['V1_Exc_L2/3'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0]).get_analysis_result())!=0):
                        pref_fr_50 = param_filter_query(data_store,sheet_name=['V1_Exc_L2/3'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[0],ads_unique=True).get_analysis_result()[0].get_value_by_id(l23_exc_or_many)
                        ort_fr_50 = param_filter_query(data_store,sheet_name=['V1_Exc_L2/3'],st_contrast=[5],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',st_orientation=[numpy.pi/2],ads_unique=True).get_analysis_result()[0].get_value_by_id(l23_exc_or_many)
                    spont = param_filter_query(data_store,st_name='InternalStimulus',sheet_name=['V1_Exc_L2/3'],analysis_algorithm=['TrialAveragedFiringRate'],value_name='Firing rate',ads_unique=True).get_analysis_result()[0].get_value_by_id(l23_exc_or_many)

                    pylab.figure()
                    pylab.bar([1,2,3,4,5],[numpy.mean(pref_fr_100),numpy.mean(ort_fr_100),numpy.mean(pref_fr_50),numpy.mean(ort_fr_50),numpy.mean(spont)])
                    pylab.xticks([1.4,2.4,3.4,4.4,5.4],['PREF100','ORT100','PREF50','ORT50','SPONT'])
                    pylab.xlim([0.8,6.0])
                    pylab.ylabel("Firing rate")
                
                    pylab.savefig(Global.root_directory+"Orientation_responseL23.png")



    
        SpontStatisticsOverview(data_store,ParameterSet({}), fig_param={'dpi' : 200,'figsize': (12,8)},plot_file_name='SpontStatisticsOverview.png').plot()
        SpontActOverview(data_store,ParameterSet({'l4_exc_neuron' : analog_ids[0], 'l4_inh_neuron' : analog_ids_inh[0],'l23_exc_neuron' : analog_ids23[0],'l23_inh_neuron' : analog_ids_inh23[0]}),plot_file_name='SpontActOverview.png', fig_param={'dpi' : 200,'figsize': (18,14.5)}).plot()

        dsv = param_filter_query(data_store,sheet_name = 'V1_Exc_L4')    
        MeanVsVarainceOfVM(dsv,ParameterSet({'neurons' : list(analog_ids[:5])}),fig_param={'dpi' : 100,'figsize': (15,7.5)},plot_file_name='TrialToTrialMeanVsVarianceOfVM.png').plot()
        
        dsv = queries.param_filter_query(data_store,value_name=['orientation HWHH of Firing rate','orientation CV(Firing rate)'],sheet_name=["V1_Exc_L2/3"],st_contrast=100)
        PerNeuronValueScatterPlot(dsv, ParameterSet({'only_matching_units' : False,'ignore_nan' : True}),plot_file_name='CVvsHWHH.png').plot({'*.x_lim' : (0,90),'*.y_lim' : (0,1.0)})
    
        MRfig(param_filter_query(data_store,sheet_name=['V1_Exc_L2/3','V1_Exc_L4'],st_contrast=[100],st_name='FullfieldDriftingSinusoidalGratingA'),ParameterSet({'SimpleSheetName' : 'V1_Exc_L4','ComplexSheetName' : 'V1_Exc_L2/3'}),plot_file_name='MR.png',fig_param={'dpi' : 100,'figsize': (19,12)}).plot()
        MRfigReal(param_filter_query(data_store,sheet_name=['V1_Exc_L2/3','V1_Exc_L4'],st_contrast=[100],st_name='FullfieldDriftingSinusoidalGratingA'),ParameterSet({'SimpleSheetName' : 'V1_Exc_L4','ComplexSheetName' : 'V1_Exc_L2/3'}),plot_file_name='MRReal.png',fig_param={'dpi' : 100,'figsize': (19,12)}).plot()
	
	dsv = param_filter_query(data_store,st_name='InternalStimulus',st_direct_stimulation_name='LocalStimulatorArray',st_stimulating_signal_parameters_orientation=0,st_stimulating_signal_parameters_scale=1.0)   
	ActivityMovie(dsv,ParameterSet({'bin_width': 20.0,'scatter':  True,'resolution': 10,'sheet_name': 'V1_Exc_L2/3', 'exp_time_constant': 200}),fig_param={'dpi' : 100,'figsize': (12,6)},plot_file_name='cs_or_0_l23').plot({'*.title' : None})


    if nat_stim:        

        dsv = param_filter_query(data_store,st_name='NaturalImageWithEyeMovement')   
        overviews(dsv,"NI_")

        TrialToTrialVariabilityComparison(data_store,ParameterSet({'sheet_name1' : 'V1_Exc_L4','sheet_name2' : 'V1_Exc_L4','data_dg' : 0.93 , 'data_ni' : 1.19}),fig_param={'dpi' : 200,'figsize': (15,7.5)},plot_file_name='TrialToTrialVariabilityComparison.png').plot()

        dsv = param_filter_query(data_store,st_name='NaturalImageWithEyeMovement')    
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Exc_L4', 'neuron' : l4_exc, 'sheet_activity' : {}, 'spontaneous' : True}),plot_file_name='NMExc.png',fig_param={'dpi' : 100,'figsize': (28,12)}).plot({'Vm_plot.y_lim' : (-70,-50),'Conductance_plot.y_lim' : (0,50.0)})
        OverviewPlot(dsv,ParameterSet({'sheet_name' : 'V1_Inh_L4', 'neuron' : l4_inh, 'sheet_activity' : {}, 'spontaneous' : True}),plot_file_name='NMInh.png',fig_param={'dpi' : 100,'figsize': (28,12)}).plot({'Vm_plot.y_lim' : (-70,-50),'Conductance_plot.y_lim' : (0,50.0)})
                    
        TrialCrossCorrelationAnalysis(data_store,ParameterSet({'neurons1' : list(analog_ids),'sheet_name1' : 'V1_Exc_L4','neurons2' : list(analog_ids23),'sheet_name2' : 'V1_Exc_L2/3', 'window_length' : 250}),fig_param={"dpi" : 100,"figsize": (15,6.5)},plot_file_name="trial-to-trial-cross-correlation.png").plot({'*.Vm.title' : None, '*.fontsize' : 19})
Exemple #16
0
def trial_averaged_tuning_curve_errorbar(sheet,
                                         folder,
                                         stimulus,
                                         parameter,
                                         start,
                                         end,
                                         xlabel="",
                                         ylabel="",
                                         color="black",
                                         percentile=False,
                                         useXlog=False,
                                         useYlog=False,
                                         ylim=[0., 100.],
                                         xlim=False,
                                         opposite=False,
                                         box=None,
                                         radius=None,
                                         addon="",
                                         data=None,
                                         data_curve=True):
    print inspect.stack()[0][3]
    print "folder: ", folder
    print "sheet: ", sheet
    data_store = PickledDataStore(load=True,
                                  parameters=ParameterSet({
                                      'root_directory':
                                      folder,
                                      'store_stimuli':
                                      False
                                  }),
                                  replace=True)
    data_store.print_content(full_recordings=False)

    neurons = []
    neurons = param_filter_query(
        data_store, sheet_name=sheet,
        st_name=stimulus).get_segments()[0].get_stored_spike_train_ids()
    print "Recorded neurons:", len(neurons)

    if radius:
        sheet_ids = data_store.get_sheet_indexes(sheet_name=sheet,
                                                 neuron_ids=neurons)
        positions = data_store.get_neuron_postions()[sheet]
        if radius:
            ids1 = select_ids_by_position(positions, sheet_ids, radius=radius)
        neurons = data_store.get_sheet_ids(sheet_name=sheet, indexes=ids1)

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name=sheet)[0]
    l4_exc_or_many = numpy.array(neurons)[numpy.nonzero(
        numpy.array([
            circular_dist(l4_exc_or.get_value_by_id(i), 0, numpy.pi)
            for i in neurons
        ]) < .1)[0]]
    neurons = list(l4_exc_or_many)

    print "Selected neurons:", len(neurons)  #, neurons
    if len(neurons) < 1:
        return

    TrialAveragedFiringRate(
        param_filter_query(data_store, sheet_name=sheet, st_name=stimulus),
        ParameterSet({'neurons': list(neurons)})).analyse()

    PlotTuningCurve(
        param_filter_query(data_store,
                           st_name=stimulus,
                           analysis_algorithm=['TrialAveragedFiringRate']),
        ParameterSet({
            'polar': False,
            'pool': False,
            'centered': False,
            'percent': False,
            'mean': True,
            'parameter_name': parameter,
            'neurons': list(neurons),
            'sheet_name': sheet
        }),
        fig_param={
            'dpi': 200
        },
        plot_file_name=folder + "/TrialAveragedSensitivityNew_" + stimulus +
        "_" + parameter + "_" + str(sheet) + "_" + addon + "_mean.svg"
    ).plot({
        # '*.y_lim':(0,30),
        # '*.x_lim':(-10,100),
        # '*.x_scale':'log', '*.x_scale_base':10,
        '*.fontsize': 17
    })
    return
def perform_analysis_and_visualization_or(data_store):
    analog_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_esyn_ids()
    analog_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_esyn_ids()
    spike_ids = param_filter_query(
        data_store,
        sheet_name="V1_Exc_L4").get_segments()[0].get_stored_spike_train_ids()
    spike_ids_inh = param_filter_query(
        data_store,
        sheet_name="V1_Inh_L4").get_segments()[0].get_stored_spike_train_ids()

    NeuronAnnotationsToPerNeuronValues(data_store, ParameterSet({})).analyse()
    l4_exc_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Exc_L4')
    l4_exc_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentPhase',
        sheet_name='V1_Exc_L4')
    l4_exc = analog_ids[numpy.argmin([
        circular_dist(o, 0, numpy.pi)
        for (o, p) in zip(l4_exc_or[0].get_value_by_id(analog_ids),
                          l4_exc_phase[0].get_value_by_id(analog_ids))
    ])]
    l4_inh_or = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentOrientation',
        sheet_name='V1_Inh_L4')
    l4_inh_phase = data_store.get_analysis_result(
        identifier='PerNeuronValue',
        value_name='LGNAfferentPhase',
        sheet_name='V1_Inh_L4')
    l4_inh = analog_ids_inh[numpy.argmin([
        circular_dist(o, 0, numpy.pi)
        for (o, p) in zip(l4_inh_or[0].get_value_by_id(analog_ids_inh),
                          l4_inh_phase[0].get_value_by_id(analog_ids_inh))
    ])]

    GSTA(param_filter_query(data_store, sheet_name='V1_Exc_L4'),
         ParameterSet({
             'neurons': list(analog_ids),
             'length': 250.0
         }),
         tags=['GSTA']).analyse()

    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': l4_exc,
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[0],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview1.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[1],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview2.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[2],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview3.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[3],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview4.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[4],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview5.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[5],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview6.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[6],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview7.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[7],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview8.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[8],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview9.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[9],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview10.png').plot()
    dsv = param_filter_query(data_store,
                             st_name='FullfieldDriftingSinusoidalGrating',
                             st_orientation=0,
                             st_contrast=100)
    KremkowOverviewFigure(dsv,
                          ParameterSet({
                              'neuron': analog_ids[10],
                              'sheet_name': 'V1_Exc_L4'
                          }),
                          fig_param={
                              'dpi': 100,
                              'figsize': (19, 12)
                          },
                          plot_file_name='ExcOverview11.png').plot()