Initialization of variables passed in the command line or defined in a parameter file.
Executes commands defined in a parameters file, as well as processes subsequent Python commands delivered on the command line. The usage from the command line is then:
python PYTHONFILE [PARAM_FILES &| cmds]
PYTHONFILE is the name of a Python script or file.
global and/or local parameters.
set in the parameter file(s) or add new functionality.
EXAMPLE:
Run the simulation defined in main.py, which contains at least the following code.
import sys
from neuron import nrn # a nrn object
from neuron import h # a hoc object
from neuronpy.util import paraminit
# The file ``params.py`` in this same directory contains a dict,
# ``sim_var``, which defines our variables.
from params import sim_var
def run():
# Run the simulation
print "Do some amazing science."
if __name__ == "__main__":
"""Run when called from the command line."""
local_dict = {}
paraminit.parse_args(sys.argv[1:], globals(), local_dict)
if 'sim_var' in local_dict:
# Replace current values with those in the local_dict
replacing_dict = local_dict['sim_var']
for key, val in replacing_dict.items():
sim_var[key] = val
run() # Run the simulation.
From the command line, execute this file with:
python main.py
It is important to point out that a file called “params.py” must also exist at the same level as main.py, unless it is overridden with another parameter file as in:
python main.py some_params_file.py
To pass in other commands, you could deliver something like:
python main.py my_debugging_flag=True 'print "RUNNING IN DEBUGGING MODE"'
which will override my_debugging_flag if it is defined in params.py, or set it as a new global variable if it is not defined, and will print the statement before executing the simulation.
@author: - Thomas McTavish
Load the parameters file(s) into Python’s globals dictionary. This is called by plot_spikes().
Parameters: |
|
---|
Parse command line arguments and set global parameters. Each argument is first tested to see if it is a '.py' Python file, in which case, it is executed. Otherwise, it is executed as a command.
Parameters: |
|
---|---|
Return cmd_files, cmds: | |
the list of files and the list of cmds processed. |