def plotSpatialTuning(ex,N,stim,layer_sizes,path):

    # Compute harmonic responses
    for f in ex.spatial_frequency:
        print ("\n--- Freq = %s  cpd ---\n" % f)

        if(isinstance(layer_sizes, list) == False):
            data_analysis.initializePSTHs(ex,"retina",False,N,
            ex.FFT_labels,'_sf_'+str(f),0,path)
        else:
            data_analysis.initializePSTHs(ex,"thalamocortical_system",False,N,
            ex.labels,'_sf_'+str(f),ex.layer_sizes,path)

        ex.firstHarmonic(f,True)
        ex.resetPSTHs()

    fig = plt.figure()

    if(isinstance(layer_sizes, list) == False):
        data_analysis.spatialTuning(ex.spatial_frequency,ex.FFTamp,ex.FFTph,
        ex.FFT_labels,ex.FFT_rows,ex.FFT_cols,0,0,'Spatial frequency (cpd)',
       "Ampl. (mV or s^(-1))",'retina',"../data/")
    else:
        data_analysis.spatialTuning(ex.spatial_frequency,ex.FFTamp,ex.FFTph,
        ex.FFT_labels,ex.FFT_rows,ex.FFT_cols,0,0,'Spatial frequency (cpd)',
       "Ampl. (mV or s^(-1))",'thalamocortical_system',"../data/")
def plotTopographical(ex,N,stim,layer_sizes,path):

    fig = plt.figure()
    fig.subplots_adjust(hspace=1.5)
    fig.subplots_adjust(wspace=0.4)

    if(isinstance(layer_sizes, list) == False):
        data_analysis.initializePSTHs(ex,"retina",True,N,
        ex.sp_labels,stim,0,path)

        data_analysis.topographical(fig,ex.newSimulation.Params['N'],ex.topographical_time_intervals,
        ex.newSimulation.Params['resolution'],ex.simtime,ex.potentials,
        ex.top_layers_to_record,ex.top_labels,ex.topographical_rows,ex.topographical_cols,
        ex.topographical_V_mins,ex.topographical_V_maxs,ex.topographical_isSpikes,
        ex.trials,ex.top_PSTHs,ex.bin_size,ex.top_PSTH_index,0,False,'retina',"../data/")

    else:
        data_analysis.initializePSTHs(ex,"thalamocortical_system",True,N,
        ex.labels,stim,ex.layer_sizes,path)

        data_analysis.topographical(fig,ex.newSimulation.Params['N_cortex'],ex.topographical_time_intervals,
        ex.newSimulation.Params['resolution'],ex.simtime,ex.spikes,
        ex.top_layers_to_record,ex.top_labels,ex.topographical_rows,ex.topographical_cols,
        ex.topographical_V_mins,ex.topographical_V_maxs,ex.topographical_isSpikes,
        ex.trials,ex.top_PSTHs,ex.bin_size,ex.top_PSTH_index,ex.layer_sizes_top,False,
        'thalamocortical_system',"../data/")

        data_analysis.topographical(fig,ex.newSimulation.Params['N_cortex'],ex.topographical_time_intervals,
        ex.newSimulation.Params['resolution'],ex.simtime,ex.spikes,
        ex.pop_layers_to_record,ex.pop_labels,ex.topographical_rows,ex.topographical_cols,
        ex.pop_V_mins,ex.pop_V_maxs,ex.topographical_isSpikes,
        ex.trials,ex.top_PSTHs,ex.bin_size,ex.pop_PSTH_index,ex.layer_sizes_pop,True,
        'thalamocortical_system',"../data/")
def receptiveField(ex,N,stim,layer_sizes,path):

    ex.createRFmask()

    for pos in np.arange(len(ex.RF_mask)):
        if(isinstance(layer_sizes, list) == False):
            data_analysis.initializePSTHs(ex,"retina",False,N,
            ex.sp_labels,ex.stim+"_bright_"+str(pos),0,path)
        else:
            data_analysis.initializePSTHs(ex,"thalamocortical_system",False,N,
            ex.labels,"_disk_"+"_bright_"+str(pos),ex.layer_sizes,path)

        ex.updateRFmaps(pos,0,True)
        ex.resetPSTHs()

        if(isinstance(layer_sizes, list) == False):
            data_analysis.initializePSTHs(ex,"retina",False,N,
            ex.sp_labels,ex.stim+"_dark_"+str(pos),0,path)
        else:
            data_analysis.initializePSTHs(ex,"thalamocortical_system",False,N,
            ex.labels,"_disk_"+"_dark_"+str(pos),ex.layer_sizes,path)

        ex.updateRFmaps(pos,1,True)
        ex.resetPSTHs()

    fig = plt.figure()

    if(isinstance(layer_sizes, list) == False):
        data_analysis.receptiveField(fig,ex.newSimulation.Params['N'],
        ex.RF_intervals,ex.s_layers_to_record,
        ex.labels,ex.RF_bright,ex.RF_dark)
    else:
        data_analysis.receptiveField(fig,ex.newSimulation.Params['N_LGN'],
        ex.RF_intervals,ex.layers_to_record,
        ex.labels,ex.RF_bright,ex.RF_dark)
def plotAreaResponse(ex,N,stim,layer_sizes,path):

    # Compute responses to flashing spot
    for d in ex.disk_diameters:
        if(isinstance(layer_sizes, list) == False):
            data_analysis.initializePSTHs(ex,"retina",False,N,
            ex.area_labels,ex.stim+str(d),0,path)
        else:
            data_analysis.initializePSTHs(ex,"thalamocortical_system",False,N,
            ex.labels,'_disk_'+str(d),ex.layer_sizes,path)

        ex.areaResponseCurve(d,True)
        ex.resetPSTHs()

    fig = plt.figure()

    data_analysis.spatialTuning(ex.disk_diameters,ex.area_amp,ex.area_ph,
    ex.area_labels,ex.area_rows,ex.area_cols,0,0,'Disk diameter (deg)',
    "Ampl. (mV or s^(-1))")
def plotPSTHs(ex,N,stim,layer_sizes,path):

    fig = plt.figure()
    fig.subplots_adjust(hspace=1.5)
    fig.subplots_adjust(wspace=0.4)

    if(isinstance(layer_sizes, list) == False):
        data_analysis.initializePSTHs(ex,"retina",False,N,
        ex.sp_labels,stim,0,path)

        data_analysis.PSTH(ex.start_time,ex.newSimulation.Params['resolution'],
        ex.simtime,ex.spikes,ex.s_layers_to_record,ex.sp_labels,ex.selected_cell,
        ex.PSTH_rows,ex.PSTH_cols,ex.PSTH_starting_row,ex.PSTH_starting_col,
        ex.trials,ex.PSTHs,ex.bin_size,"retina","../data/")
    else:
        data_analysis.initializePSTHs(ex,"thalamocortical_system",False,N,
        ex.labels,stim,ex.layer_sizes,path)

        data_analysis.PSTH(ex.start_time,ex.newSimulation.Params['resolution'],
        ex.simtime,ex.spikes,ex.layers_to_record,ex.labels,ex.selected_cell,
        ex.PSTH_rows,ex.PSTH_cols,ex.PSTH_starting_row,ex.PSTH_starting_col,
        ex.trials,ex.PSTHs,ex.bin_size,"thalamocortical_system","../data/")