def instantiate_BG(params={}, antagInjectionSite='none', antag=''): nest.ResetKernel() dataPath='log/' if 'nbcpu' in params: nest.SetKernelStatus({'local_num_threads': params['nbcpu']}) nstrand.set_seed(params['nestSeed'], params['pythonSeed']) # sets the seed for the BG construction nest.SetKernelStatus({"data_path": dataPath}) initNeurons() print '/!\ Using the following LG14 parameterization',params['LG14modelID'] loadLG14params(params['LG14modelID']) loadThetaFromCustomparams(params) # We check that all the necessary parameters have been defined. They should be in the modelParams.py file. # If one of them misses, we exit the program. necessaryParams=['nbCh','nbMSN','nbFSI','nbSTN','nbGPe','nbGPi','nbCSN','nbPTN','nbCMPf','IeMSN','IeFSI','IeSTN','IeGPe','IeGPi','GMSN','GFSI','GSTN','GGPe','GGPi','inDegCSNMSN','inDegPTNMSN','inDegCMPfMSN','inDegMSNMSN','inDegFSIMSN','inDegSTNMSN','inDegGPeMSN','inDegCSNFSI','inDegPTNFSI','inDegSTNFSI','inDegGPeFSI','inDegCMPfFSI','inDegFSIFSI','inDegPTNSTN','inDegCMPfSTN','inDegGPeSTN','inDegCMPfGPe','inDegSTNGPe','inDegMSNGPe','inDegGPeGPe','inDegMSNGPi','inDegSTNGPi','inDegGPeGPi','inDegCMPfGPi',] for np in necessaryParams: if np not in params: raise KeyError('Missing parameter: '+np) #------------------------ # creation and connection of the neural populations #------------------------ createBG() connectBG(antagInjectionSite,antag)
def instantiate_BG(params={}, antagInjectionSite='none', antag=''): nest.ResetKernel() dataPath = 'log/' if 'nbcpu' in params: nest.SetKernelStatus({'local_num_threads': params['nbcpu']}) nstrand.set_seed( params['nestSeed'], params['pythonSeed']) # sets the seed for the BG construction nest.SetKernelStatus({"data_path": dataPath}) #nest.SetKernelStatus({"resolution": 0.005}) # simulates with a higher precision initNeurons() print '/!\ Using the following LG14 parameterization', params[ 'LG14modelID'] loadLG14params(params['LG14modelID']) loadThetaFromCustomparams(params) # We check that all the necessary parameters have been defined. They should be in the modelParams.py file. # If one of them misses, we exit the program. if params['splitGPe']: necessaryParams = [ 'nbCh', 'nbMSN', 'nbFSI', 'nbSTN', 'nbGPe', 'nbArky', 'nbProt', 'nbGPi', 'nbCSN', 'nbPTN', 'nbCMPf', 'IeMSN', 'IeFSI', 'IeSTN', 'IeGPe', 'IeArky', 'IeProt', 'IeGPi', 'GCSNMSN', 'GPTNMSN', 'GCMPfMSN', 'GMSNMSN', 'GFSIMSN', 'GSTNMSN', 'GGPeMSN', 'GArkyMSN', 'GCSNFSI', 'GPTNFSI', 'GSTNFSI', 'GGPeFSI', 'GArkyFSI', 'GCMPfFSI', 'GFSIFSI', 'GPTNSTN', 'GCMPfSTN', 'GGPeSTN', 'GProtSTN', 'GCMPfGPe', 'GSTNGPe', 'GMSNGPe', 'GGPeGPe', 'GCMPfArky', 'GSTNArky', 'GMSNArky', 'GArkyArky', 'GProtArky', 'GCMPfProt', 'GSTNProt', 'GMSNProt', 'GProtProt', 'GArkyProt', 'GMSNGPi', 'GSTNGPi', 'GGPeGPi', 'GProtGPi', 'GCMPfGPi', 'redundancyCSNMSN', 'redundancyPTNMSN', 'redundancyCMPfMSN', 'redundancyMSNMSN', 'redundancyFSIMSN', 'redundancySTNMSN', 'redundancyGPeMSN', 'redundancyArkyMSN', 'redundancyCSNFSI', 'redundancyPTNFSI', 'redundancySTNFSI', 'redundancyGPeFSI', 'redundancyArkyFSI', 'redundancyCMPfFSI', 'redundancyFSIFSI', 'redundancyPTNSTN', 'redundancyCMPfSTN', 'redundancyGPeSTN', 'redundancyProtSTN', 'redundancyCMPfGPe', 'redundancySTNGPe', 'redundancyMSNGPe', 'redundancyGPeGPe', 'redundancyCMPfArky', 'redundancySTNArky', 'redundancyMSNArky', 'redundancyArkyArky', 'redundancyProtArky', 'redundancyCMPfProt', 'redundancySTNProt', 'redundancyMSNProt', 'redundancyProtProt', 'redundancyArkyProt', 'redundancyMSNGPi', 'redundancySTNGPi', 'redundancyGPeGPi', 'redundancyProtGPi', 'redundancyCMPfGPi', ] else: necessaryParams = [ 'nbCh', 'nbMSN', 'nbFSI', 'nbSTN', 'nbGPe', 'nbGPi', 'nbCSN', 'nbPTN', 'nbCMPf', 'IeMSN', 'IeFSI', 'IeSTN', 'IeGPe', 'IeGPi', 'GCSNMSN', 'GPTNMSN', 'GCMPfMSN', 'GMSNMSN', 'GFSIMSN', 'GSTNMSN', 'GGPeMSN', 'GCSNFSI', 'GPTNFSI', 'GSTNFSI', 'GGPeFSI', 'GCMPfFSI', 'GFSIFSI', 'GPTNSTN', 'GCMPfSTN', 'GGPeSTN', 'GCMPfGPe', 'GSTNGPe', 'GMSNGPe', 'GGPeGPe', 'GMSNGPi', 'GSTNGPi', 'GGPeGPi', 'GCMPfGPi', 'redundancyCSNMSN', 'redundancyPTNMSN', 'redundancyCMPfMSN', 'redundancyMSNMSN', 'redundancyFSIMSN', 'redundancySTNMSN', 'redundancyGPeMSN', 'redundancyCSNFSI', 'redundancyPTNFSI', 'redundancySTNFSI', 'redundancyGPeFSI', 'redundancyCMPfFSI', 'redundancyFSIFSI', 'redundancyPTNSTN', 'redundancyCMPfSTN', 'redundancyGPeSTN', 'redundancyCMPfGPe', 'redundancySTNGPe', 'redundancyMSNGPe', 'redundancyGPeGPe', 'redundancyMSNGPi', 'redundancySTNGPi', 'redundancyGPeGPi', 'redundancyCMPfGPi', ] for np in necessaryParams: if np not in params: raise KeyError('Missing parameter: ' + np) #------------------------ # creation and connection of the neural populations #------------------------ createBG() return connectBG(antagInjectionSite, antag)
def checkAvgFR(showRasters=False, params={}, antagInjectionSite='none', antag='', logFileName=''): nest.ResetNetwork() initNeurons( ) # sets the default params of iaf_alpha_psc_mutisynapse neurons to CommonParams showPotential = False # Switch to True to graph neurons' membrane potentials - does not handle well restarted simulations dataPath = 'log/' nest.SetKernelStatus( {"overwrite_files": True}) # when we redo the simulation, we erase the previous traces nstrand.set_seed(params['nestSeed'], params['pythonSeed']) # sets the seed for the simulation simulationOffset = nest.GetKernelStatus('time') print('Simulation Offset: ' + str(simulationOffset)) offsetDuration = 1000. simDuration = 5000. # ms #------------------------- # measures #------------------------- spkDetect = {} # spike detectors used to record the experiment multimeters = { } # multimeters used to record one neuron in each population expeRate = {} antagStr = '' if antagInjectionSite != 'none': antagStr = antagInjectionSite + '_' + antag + '_' # storeGDFdissociated = storeGDF # avoid an error # if antagStr != '': # storeGDFdissociated = False # gdf files are not required for antagonist simulation for N in NUCLEI: # 1000ms offset period for network stabilization spkDetect[N] = nest.Create("spike_detector", params={ "withgid": True, "withtime": True, "label": antagStr + N, "to_memory": False, "to_file": storeGDF, 'start': offsetDuration + simulationOffset, 'stop': offsetDuration + simDuration + simulationOffset }) nest.Connect(Pop[N], spkDetect[N]) if showPotential: # multimeter records only the last 200ms in one neuron in each population multimeters[N] = nest.Create( 'multimeter', params={ "withgid": True, 'withtime': True, 'interval': 0.1, 'record_from': ['V_m'], "label": antagStr + N, "to_file": False, 'start': offsetDuration + simulationOffset + simDuration - 200., 'stop': offsetDuration + simDuration + simulationOffset }) nest.Connect(multimeters[N], [Pop[N][0]]) #------------------------- # Simulation #------------------------- nest.Simulate(simDuration + offsetDuration) score = 0 text = [] frstr = "#" + str( params['LG14modelID']) + " , " + antagInjectionSite + ', ' s = '----- RESULTS -----' print s text.append(s + '\n') if antagInjectionSite == 'none': validationStr = "\n#" + str(params['LG14modelID']) + " , " frstr += "none , " for N in NUCLEI: strTestPassed = 'NO!' expeRate[N] = nest.GetStatus(spkDetect[N], 'n_events')[0] / float( nbSim[N] * simDuration) * 1000 if expeRate[N] <= FRRNormal[N][1] and expeRate[N] >= FRRNormal[N][ 0]: # if the measured rate is within acceptable values strTestPassed = 'OK' score += 1 validationStr += N + "=OK , " else: # out of the ranges if expeRate[N] > FRRNormal[N][1]: difference = expeRate[N] - FRRNormal[N][1] validationStr += N + "=+%.2f , " % difference else: difference = expeRate[N] - FRRNormal[N][0] validationStr += N + "=%.2f , " % difference frstr += '%f , ' % (expeRate[N]) s = '* ' + N + ' - Rate: ' + str( expeRate[N]) + ' Hz -> ' + strTestPassed + ' (' + str( FRRNormal[N][0]) + ' , ' + str(FRRNormal[N][1]) + ')' print s text.append(s + '\n') else: validationStr = "" frstr += str(antag) + " , " for N in NUCLEI: expeRate[N] = nest.GetStatus(spkDetect[N], 'n_events')[0] / float( nbSim[N] * simDuration) * 1000 if N == antagInjectionSite: strTestPassed = 'NO!' if expeRate[N] <= FRRAnt[N][antag][1] and expeRate[ N] >= FRRAnt[N][antag][0]: # if the measured rate is within acceptable values strTestPassed = 'OK' score += 1 validationStr += N + "_" + antag + "=OK , " else: # out of the ranges if expeRate[N] > FRRNormal[N][1]: difference = expeRate[N] - FRRNormal[N][1] validationStr += N + "_" + antag + "=+%.2f , " % difference else: difference = expeRate[N] - FRRNormal[N][0] validationStr += N + "_" + antag + "=%.2f , " % difference s = '* ' + N + ' with ' + antag + ' antagonist(s): ' + str( expeRate[N]) + ' Hz -> ' + strTestPassed + ' (' + str( FRRAnt[N][antag][0]) + ' , ' + str( FRRAnt[N][antag][1]) + ')' print s text.append(s + '\n') else: s = '* ' + N + ' - Rate: ' + str(expeRate[N]) + ' Hz' print s text.append(s + '\n') frstr += '%f , ' % (expeRate[N]) s = '-------------------' print s text.append(s + '\n') frstr += '\n' firingRatesFile = open(dataPath + 'firingRates.csv', 'a') firingRatesFile.writelines(frstr) firingRatesFile.close() #print "************************************** file writing",text #res = open(dataPath+'OutSummary_'+logFileName+'.txt','a') res = open(dataPath + 'OutSummary.txt', 'a') res.writelines(text) res.close() validationFile = open("validationArray.csv", 'a') validationFile.write(validationStr) validationFile.close() #------------------------- # Displays #------------------------- if showRasters and interactive: displayStr = ' (' + antagStr[:-1] + ')' if ( antagInjectionSite != 'none') else '' for N in NUCLEI: nest.raster_plot.from_device(spkDetect[N], hist=True, title=N + displayStr) if showPotential: pl.figure() nsub = 231 for N in NUCLEI: pl.subplot(nsub) nest.voltage_trace.from_device(multimeters[N], title=N + displayStr + ' #0') nest.Disconnect(Pop[N], multimeters[N]) pl.axhline(y=BGparams[N]['V_th'], color='r', linestyle='-') nsub += 1 pl.show() return score, 5 if antagInjectionSite == 'none' else 1