def main():
    """ This program launches a CollisionEesNatural simulation with predefined input parameters.

	This script can be executed both with and without MPI. In case MPI is used the different processes
	are used to run simulations with different initial condition and the results report the mean of
	all simulations.

	Example of how to run this script from the terminal:
	python scripts/runCollisionEesNatural.py
	mpiexec -np 10 python scripts/runCollisionEesNatural.py
	"""

    parser = argparse.ArgumentParser(
        description="Compute the probability of antidromic collisions")
    parser.add_argument(
        "--seed",
        help=
        "positive seed used to initialize random number generators (default = time.time())",
        type=int,
        choices=[gt.Range(0, 999999)])
    args = parser.parse_args()

    sh.save_seed(timeModule.time())
    from simulations import CollisionEesNatural

    # Create a Neuron ParallelContext object to support parallel simulations
    pc = h.ParallelContext()
    eesFrequencies = np.linspace(5, 100, 20)
    fiberDelays = [2, 10, 20]
    fiberFiringRates = np.linspace(5, 200, 20)
    simulation = CollisionEesNatural(pc, eesFrequencies, fiberDelays,
                                     fiberFiringRates)
    simulation.run()
    for i in range(len(fiberDelays)):
        simulation.plot(i, 10, "_40p_del" + str(fiberDelays[i]))
    simulation.plot_isoinformation_surface()
def main():
    """ This program launches a ForSimMuscleSpindles simulation with a predefined NeuralNetwork structure and
	senory-eencoding spatiotemporal EES profiles with amplitude and frequency given by the user as argument.

	This program can be executed both with and without MPI. In case MPI is used the cells
	of the NeuralNetwork are shared between the different hosts in order to speed up the
	simulation.


	Examples of how to run this script from the terminal:
	mpiexec -np 4 python scripts/runForSimMuscleSpindlesStimModulation.py 60 280 human sensory frwSimHuman.txt testHumanSpatiotemporalEES

	"""

    parser = argparse.ArgumentParser(
        description="launch a ForSimMuscleSpindles simulation")
    parser.add_argument("eesFrequency",
                        help="ees frequency",
                        type=float,
                        choices=[gt.Range(0, 1000)])
    parser.add_argument("eesAmplitude",
                        help="ees amplitude (0-600] or %%Ia_II_Mn")
    parser.add_argument("species",
                        help="simulated species",
                        choices=["rat", "human"])
    parser.add_argument("modulation",
                        help="type of stimulation modulation",
                        choices=["sensory"])
    parser.add_argument("inputFile", help="neural network structure file")
    parser.add_argument("name", help="name to add at the output files")
    parser.add_argument("--simTime",
                        help="simulation time",
                        type=int,
                        default=-1)
    parser.add_argument("--noPlot", help="no plots flag", action="store_true")
    parser.add_argument("--burstingEes",
                        help="flag to use burst stimulation",
                        action="store_true")
    parser.add_argument("--nPulsesPerBurst",
                        help="number of pulses per burst",
                        type=int,
                        default=5)
    parser.add_argument("--burstsFrequency",
                        help="stimulation frequency within bursts",
                        type=float,
                        default=600,
                        choices=[gt.Range(0, 1000)])
    parser.add_argument(
        "--seed",
        help=
        "positive seed used to initialize random number generators (default = time.time())",
        type=int,
        choices=[gt.Range(0, 999999)])
    args = parser.parse_args()

    if args.seed is not None: sh.save_seed(args.seed)
    else: sh.save_seed(int(time.time()))

    # Import simulation specific modules
    from simulations import ForSimMuscleSpindles
    from NeuralNetwork import NeuralNetwork
    from EES import EES
    from BurstingEES import BurstingEES

    # Initialze variables...
    if args.eesAmplitude[0] == "%":
        eesAmplitude = [float(x) for x in args.eesAmplitude[1:].split("_")]
    else:
        eesAmplitude = float(args.eesAmplitude)
    name = "_" + args.species + "_" + args.name
    if args.species == "rat":
        raise (Exception(
            "Spatiotemporal modulation is not implemented for the rat model"))
    elif args.species == "human":
        muscles = hp.get_muscles_dict()
        if args.modulation == "sensory":
            fileStimMod = "../inputFiles/spatiotemporalSensoryProfile.p"
        if 'fileStimMod' in locals():
            with open(fileStimMod, 'r') as pickle_file:
                eesModulation = pickle.load(pickle_file)

    pc = h.ParallelContext()
    nn = NeuralNetwork(pc, args.inputFile)
    if not args.burstingEes:
        ees = EES(pc,
                  nn,
                  eesAmplitude,
                  args.eesFrequency,
                  pulsesNumber=100000,
                  species=args.species)
    else:
        ees = BurstingEES(pc,
                          nn,
                          eesAmplitude,
                          args.eesFrequency,
                          args.burstsFrequency,
                          args.nPulsesPerBurst,
                          species=args.species)
    ees.get_amplitude(True)
    afferentsInput = ldt.load_afferent_input(args.species, muscles)

    simulation = ForSimMuscleSpindles(pc, nn, afferentsInput, ees,
                                      eesModulation, args.simTime)

    # Run simulation, plot results and save them
    simulation.run()
    if not args.noPlot:
        simulation.plot(muscles["flex"], muscles["ext"], name, False)
    comm.Barrier()
    simulation.save_results(muscles["flex"], muscles["ext"], name)
Beispiel #3
0
def main():
	""" This program launches a ForwardSimulation simulation with a predefined NeuralNetwork structure,
	different stimulation amplitudes are tested to evealuate the muslce recruitment curve.
	The plots resulting from this simulation are saved in the results folder.

	This program can be executed both with and without MPI. In case MPI is used the cells
	of the NeuralNetwork are shared between the different hosts in order to speed up the
	simulation.

	This script is run by the runBatchOfRecCurve.py script. 
	"""

	parser = argparse.ArgumentParser(description="Estimate the reflex responses induced by a range of stimulation amplitudes")
	parser.add_argument("inputFile", help="neural network structure file")
	parser.add_argument("--name", help="name to add at the output files", type=str, default="")
	parser.add_argument("--noPlot", help=" no plot flag", action="store_true")
	parser.add_argument("--mnReal", help=" real mn flag", action="store_true")
	parser.add_argument("--burstingEes", help="flag to use burst stimulation", action="store_true")
	parser.add_argument("--nPulsesPerBurst", help="number of pulses per burst", type=int, default=5)
	parser.add_argument("--burstsFrequency", help="stimulation frequency within bursts",type=float, default=600, choices=[gt.Range(0,1000)])
	parser.add_argument("--seed", help="positive seed used to initialize random number generators (default = time.time())", type=int, choices=[gt.Range(0,999999)])
	parser.add_argument("--membranePotential", help="flag to compute the membrane potential", action="store_true")
	parser.add_argument("--muscleName", help="flag to compute the membrane potential", type=str, default="GM")
	args = parser.parse_args()

	if args.seed is not None: sh.save_seed(args.seed)
	else: sh.save_seed(int(time.time()))

	# Import simulation specific modules
	from simulations import ForwardSimulation
	from simulations import ForSimSpinalModulation
	from NeuralNetwork import NeuralNetwork
	from EES import EES
	from BurstingEES import BurstingEES

	# Initialize parameters
	eesAmplitudes = [[x,0,0] for x in np.arange(0.05,1.05,0.05)]
	eesFrequency = 10
	simTime = 150
	plotResults = True


	# Create a Neuron ParallelContext object to support parallel simulations
	pc = h.ParallelContext()
	nn=NeuralNetwork(pc,args.inputFile)

	if not args.burstingEes: ees = EES(pc,nn,eesAmplitudes[0],eesFrequency)
	else: ees = BurstingEES(pc,nn,eesAmplitudes[0],eesFrequency,args.burstsFrequency,args.nPulsesPerBurst)
	afferentsInput = None
	eesModulation = None

	if args.membranePotential:
		if args.mnReal:
			cellsToRecord = {"MnReal":[mn.soma for mn in nn.cells[args.muscleName]['MnReal']]}
			modelTypes = {"MnReal":"real"}
		else:
			cellsToRecord = {"Mn":nn.cells[args.muscleName]['Mn']}
			modelTypes = {"Mn":"artificial"}
		simulation = ForSimSpinalModulation(pc,nn,cellsToRecord,modelTypes, afferentsInput, ees, eesModulation, simTime)
		membranePotentials = []
	else: simulation = ForwardSimulation(pc,nn, afferentsInput, ees, eesModulation, simTime)

	mEmg = []
	mSpikes = []
	mStatTemp = []
	nSamplesToAnalyse = -100 # last 100 samples

	if not args.noPlot:
		fig, ax = plt.subplots(3,figsize=(16,9),sharex='col',sharey='col')
		fig2, ax2 = plt.subplots(1,figsize=(16,3))

	for eesAmplitude in eesAmplitudes:
		ees.set_amplitude(eesAmplitude)
		percFiberActEes = ees.get_amplitude(True)
		simulation.run()

		# Extract emg responses
		try: mEmg.append(simulation.get_estimated_emg(args.muscleName)[nSamplesToAnalyse:])
		except (ValueError, TypeError) as error: mEmg.append(np.zeros(abs(nSamplesToAnalyse)))

		# Extract mn spikes
		try: mSpikes.append(simulation.get_mn_spikes_profile(args.muscleName)[nSamplesToAnalyse:])
		except (ValueError, TypeError) as error: mSpikes.append(np.zeros(abs(nSamplesToAnalyse)))

		# plot mn membrane potentials
		if args.membranePotential:
			title = "%s_amp_%d_Ia_%f_II_%f_Mn_%f"%(args.name,percFiberActEes[0],percFiberActEes[1],percFiberActEes[2],percFiberActEes[3])
			try: fileName = "%s_amp_%d"%(args.name,eesAmplitude)
			except: fileName = "%s_amp_%.2f"%(args.name,eesAmplitude[0])
			simulation.plot_membrane_potatial(fileName,title)

		# Compute statistics
		mStatTemp.append(np.abs(mEmg[-1]).sum())

		if rank==0 and not args.noPlot:
			ax[1].plot(mEmg[-1])
			ax[0].plot(mSpikes[-1])
		comm.Barrier()

	if rank==0:
		resultsFolder = "../../results/"
		generalFileName = time.strftime("%Y_%m_%d_recCurve"+args.name)
		mStat = np.array(mStatTemp).sum()
		if not args.noPlot:
			ax[2].bar(1, mStat, 0.2)
			ax[0].set_title('Mn action potentials')
			ax[1].set_title('EMG response')
			ax[2].set_title('Statistic')

			ax2.plot([np.sum(x) for x in mSpikes])

			fileName = generalFileName+".pdf"
			pp = PdfPages(resultsFolder+fileName)
			pp.savefig(fig)
			pp.close()
			plt.show()

		fileName = generalFileName+".p"
		with open(resultsFolder+fileName, 'w') as pickle_file:
			pickle.dump(mSpikes, pickle_file)
			pickle.dump(mEmg, pickle_file)
			pickle.dump(mStat, pickle_file)

	comm.Barrier()
Beispiel #4
0
def main():
    """ This program launches a ForSimMuscleSpindles simulation with a NeuralNetwork structure,
	EES amplitude and EES frequency given by the user as argument. The NeuralNetwork
	needs to conatain the structure of a muscle spindle sensorimotor circuitry for 2
	antagonist muscles, 'TA' and 'GM' for a rat model and 'TA' and 'SOL' for a human model.
	Precomputed senosry information of the Ia and II fibers is used to drive the NN.
	The plots resulting from this simulation are saved in the results folder.

	This program can be executed both with and without MPI. In case MPI is used the cells
	of the NeuralNetwork are shared between the different hosts in order to speed up the
	simulation.

	Examples of how to run this script from the terminal:
	mpiexec -np 4 python scripts/runForSimMuscleSpindles.py 60 260 rat frwSimRat.txt testRat
	mpiexec -np 4 python scripts/runForSimMuscleSpindles.py 60 260 human frwSimHuman.txt testHuman
	mpiexec -np 4 python scripts/runForSimMuscleSpindles.py 60 260 human frwSimHumanRat.txt testHumanRat
	mpiexec -np 4 python scripts/runForSimMuscleSpindles.py 60 %0.2_0_0 human frwSimHuman.txt testHumanHFLA --burstingEes
	"""
    parser = argparse.ArgumentParser(
        description="launch a ForSimMuscleSpindles simulation")
    parser.add_argument("eesFrequency",
                        help="ees frequency",
                        type=float,
                        choices=[gt.Range(0, 1000)])
    parser.add_argument("eesAmplitude",
                        help="ees amplitude (0-600] or %%Ia_II_Mn")
    parser.add_argument("species",
                        help="simulated species",
                        choices=["rat", "human"])
    parser.add_argument("inputFile", help="neural network structure file")
    parser.add_argument("name", help="name to add at the output files")
    parser.add_argument("--simTime",
                        help="simulation time",
                        type=int,
                        default=-1)
    parser.add_argument("--noPlot", help="no plot flag", action="store_true")
    parser.add_argument("--burstingEes",
                        help="flag to use burst stimulation",
                        action="store_true")
    parser.add_argument("--nPulsesPerBurst",
                        help="number of pulses per burst",
                        type=int,
                        default=5)
    parser.add_argument("--burstsFrequency",
                        help="stimulation frequency within bursts",
                        type=float,
                        default=600,
                        choices=[gt.Range(0, 1000)])
    parser.add_argument(
        "--seed",
        help=
        "positive seed used to initialize random number generators (default = time.time())",
        type=int,
        choices=[gt.Range(0, 999999)])
    args = parser.parse_args()

    if args.seed is not None: sh.save_seed(args.seed)
    else: sh.save_seed(int(time.time()))

    # Import simulation specific modules
    from simulations import ForSimMuscleSpindles
    from NeuralNetwork import NeuralNetwork
    from EES import EES
    from BurstingEES import BurstingEES

    # Initialze variables...
    if args.eesAmplitude[0] == "%":
        eesAmplitude = [float(x) for x in args.eesAmplitude[1:].split("_")]
    else:
        eesAmplitude = float(args.eesAmplitude)
    name = "_" + args.species + "_" + args.name
    if args.species == "human": muscles = hp.get_muscles_dict()
    elif args.species == "rat": muscles = rp.get_muscles_dict()
    pc = h.ParallelContext()
    nn = NeuralNetwork(pc, args.inputFile)
    if not args.burstingEes:
        ees = EES(pc,
                  nn,
                  eesAmplitude,
                  args.eesFrequency,
                  pulsesNumber=100000,
                  species=args.species)
    else:
        ees = BurstingEES(pc,
                          nn,
                          eesAmplitude,
                          args.eesFrequency,
                          args.burstsFrequency,
                          args.nPulsesPerBurst,
                          species=args.species)
    ees.get_amplitude(True)
    afferentsInput = ldt.load_afferent_input(args.species, muscles)
    simulation = ForSimMuscleSpindles(pc, nn, afferentsInput, ees, None,
                                      args.simTime)

    # Run simulation, plot results and save them
    simulation.run()
    if not args.noPlot:
        simulation.plot(muscles["flex"], muscles["ext"], name, False)
    comm.Barrier()
    simulation.save_results(muscles["flex"], muscles["ext"], name)