def setupOptions(model, **kwargs): '''Can be called with no arguments except model. This will use the defaults in param_sim.py param_model_defaults.py and apply no overrides. Optionally, can pass any keyword arguments that are parameter names in param_sim (e.g. fname, plotcomps, logging_level, etc.) to override them. This function also handles any command line arguments. When run from command line, any command line options will take precedence over param_sim and param_model_defaults. Function is wrapped with a function that counts calls to enable checking if options have already been set up. ''' # Warn if overwriting prior setupOptions if setupOptions.calls > 1: model.log.warning('''setupOptions has already been called. Overwriting prior call with new options''') # Get the option_parsers param_sim_parser, model_parser = standard_options.standard_options() param_sim = model.param_sim ###### apply any kwargs that are param_sim overrides. ##### # Find set of all kwargs that match param_sim variables param_sim_overrides = set(set(kwargs.keys()) & set(vars(param_sim).keys())) # Override each param_sim parameter in kwargs and pop item from kwargs for k in param_sim_overrides: setattr(param_sim, k, kwargs.pop(k)) # Command line args should have precedence--call here to update param_sim # with any command line options after applying param_sim_overrides above # Passing existing namespace into parse_known_args will only set attributes # for command line arguments that are explicitly passed; no defaults are set param_sim, unknown_args = param_sim_parser.parse_known_args(namespace = param_sim) # parsing model params separately for setting spineYN, calYN, etc. from command line model, _ = model_parser.parse_known_args(unknown_args, namespace = model) # Pass param_sim to overrides and return model, plotcomps, and param_sim model, param_sim = standard_options.overrides(param_sim, model) # Any additional kwarg handling for kwargs not in param_sim can be added here: # Setup logging level log = setupLogging(model, level = param_sim.logging_level) # Set fname to default if is None in param_sim: if param_sim.fname is None: param_sim.fname = (model.param_stim.Stimulation.Paradigm.name + '_' + #model.param_stim.location.stim_dendrites[0]) #change to (after checking with Dan) model.param_stim.Stimulation.StimLoc.stim_dendrites[0]) ######### Add any new code here to parse additional possible kwargs. ######### Be sure to pop any parsed kwarg from kwargs dictionary. ######### Now kwargs should be empty, if not we passed an invalid kwarg if len(kwargs) > 0: log.warning("Passed invalid keyword arguments {} to setupOptions", kwargs) return model # Not necessary to return
def option_parser(): p = standard_options.standard_options( default_injection_delay=0.2, default_injection_width=0.4, default_injection_current=[-0.15e-9, 0.15e-9, 0.35e-9], default_simulation_time=.9, default_plot_vm=None, ) p.add_argument('--morph-file') p.add_argument('--baseline', type=real) p.add_argument('--model', required=True) p.add_argument('--neuron-type', required=True) p.add_argument('--RA', type=real) p.add_argument('--RM', type=real) p.add_argument('--CM', type=real) p.add_argument('--Erest', type=real) p.add_argument('--Eleak', type=real) p.add_argument('--Kir-offset', type=real) p.add_argument('--cond', default=[], nargs='+', type=cond_setting, action=standard_options.AppendFlat) p.add_argument('--save-vm') return p
def parse_args(commandline, do_exit): parser, _ = standard_options.standard_options() parser.add_argument("--cond", '-c', type=str, help='give exper name, for example: GABAosc') #these control synaptic strength and should start with GABA for ctrl, POST-HFS or POST-NoDa parser.add_argument( "--syn", '-syn', type=str, default='non', help='optional: synapse type of special input, omit or non for none') parser.add_argument( "--freq", '-f', type=int, default=0, help="optional: frequency of special input, omit or 0 for non") #could change this to type list to provide a range of frequencies parser.add_argument("--trials", '-n', type=int, help="number of trials") parser.add_argument("--stpYN", '-stp', type=int, choices=[1, 0], help="1 for yes, 0 for no short term plas") parser.add_argument("--ttGPe", '-tg', type=str, default='', help="name of tt files for GPe") parser.add_argument("--ttstr", '-ts', type=str, default='', help="name of tt files for Str") parser.add_argument("--ttSTN", '-tn', type=str, default='', help="name of tt files for STN") try: args = parser.parse_args( commandline ) # maps arguments (commandline) to choices, and checks for validity of choices. except SystemExit: if do_exit: raise # raise the exception above (SystemExit) else: raise ValueError('invalid ARGS') return args
def parse_args(commandline,do_exit): parser, _ = standard_options.standard_options() parser.add_argument("--stoptask", type=standard_options.parse_boolean, default=False, help="True to provide stop signal input") parser.add_argument("--fb_npas", type=int, default=3, help = "weight for npas feedback to SPNs") parser.add_argument("--fb_lhx",type=int, default=4, help="weight for lhx6 feedback to FSIs") parser.add_argument("--trials",type=int, help="number of trials") parser.add_argument("--pulsedur",'-dur', type=float, default=0,help="duration of stn pulse inputs during stop task") parser.add_argument("--stnfreq",'-stn', type=str, help="frequency of stn inputs to GPe") parser.add_argument("--rampdur",'-ramp', type=float, default=0,help="duration of ctx ramp inputs to striatum") parser.add_argument("--ctxfreq",'-ctx', type=str, help="frequency of ctx inputs to striatum") parser.add_argument("--FSI",'-FSI', type=str, default='11', help="2 bit string controlling FSI inputs, first bit=0 deletes inputs to FSI, 2nd bit=0 deletes inputs to SPNs") try: args = parser.parse_args(commandline) # maps arguments (commandline) to choices, and checks for validity of choices. except SystemExit: if do_exit: raise # raise the exception above (SystemExit) else: raise ValueError('invalid ARGS') return args
def option_parser(): ''' Extends moose_nerp.prototypes.standard_options by defining additional console arguments simulation. ''' p, _ = standard_options.standard_options( default_injection_delay=0.2, default_injection_width=0.4, default_injection_current=[-0.15e-9, 0.15e-9, 0.35e-9], default_simulation_time=.9, default_plot_vm=None, ) p.add_argument('--morph-file') p.add_argument('--baseline', type=real) p.add_argument('--model', required=True) p.add_argument('--neuron-type', required=True) p.add_argument('--RA', type=real) p.add_argument('--RM', type=real) p.add_argument('--CM', type=real) p.add_argument('--Erest', type=real) p.add_argument('--Eleak', type=real) p.add_argument('--Kir-offset', type=real) p.add_argument('--cond', default=[], nargs='+', type=cond_setting, action=standard_options.AppendFlat) p.add_argument('--save-vm') p.add_argument('--chan', default=[], nargs='+', type=chan_setting, action=standard_options.AppendFlat) p.add_argument('--CaPoolTauDend', type=real) p.add_argument('--CaPoolTauSoma', type=real) p.add_argument('--CaPoolBDend', type=real) p.add_argument('--CaPoolBSoma', type=real) return p
import numpy as np import matplotlib.pyplot as plt plt.ion() from pprint import pprint import moose from moose_nerp.prototypes import (cell_proto, calcium, clocks, inject_func, tables, plasticity_test, logutil, util, standard_options, constants) from moose_nerp import ca1 from moose_nerp.graph import plot_channel, neuron_graph, spine_graph option_parser = standard_options.standard_options( default_injection_current=[200e-12]) param_sim = option_parser.parse_args() param_sim.save = 0 plotcomps = [ca1.param_cond.NAME_SOMA] ######## adjust the model settings if specified by command-line options and retain model defaults otherwise #These assignment statements are required because they are not part of param_sim namespace. if param_sim.calcium is not None: ca1.calYN = param_sim.calcium if param_sim.spines is not None: ca1.spineYN = param_sim.spines if param_sim.stim_paradigm is not None: ca1.param_stim.Stimulation.Paradigm = ca1.param_stim.paradigm_dict[ param_sim.stim_paradigm] if param_sim.stim_loc is not None:
from moose_nerp.prototypes import (cell_proto, calcium, clocks, inject_func, tables, plasticity_test, logutil, util, standard_options, constants) from moose_nerp import d1d2 from moose_nerp.graph import plot_channel, neuron_graph, spine_graph #two examples of calling option_parser - one overrides the defaults and is useful when running from python window option_parser = standard_options.standard_options() option_parser = standard_options.standard_options(default_calcium=True, default_spines=False,default_injection_current=[-0.5e-9],default_stim='inject',default_stim_loc='soma') #,default_simulation_time=0.01) param_sim = option_parser.parse_args() param_sim.save=1 plotcomps=[d1d2.param_cond.NAME_SOMA] param_sim.hsolve=0 ######## adjust the model settings if specified by command-line options and retain model defaults otherwise #These assignment statements are required because they are not part of param_sim namespace. if param_sim.calcium is not None: d1d2.calYN = param_sim.calcium if param_sim.spines is not None: d1d2.spineYN = param_sim.spines if param_sim.stim_paradigm is not None: d1d2.param_stim.Stimulation.Paradigm=d1d2.param_stim.paradigm_dict[param_sim.stim_paradigm]
import numpy as np import matplotlib.pyplot as plt plt.ion() from pprint import pprint import moose from moose_nerp.prototypes import (cell_proto, calcium, clocks, inject_func, tables, plasticity_test, logutil, util, standard_options, constants) from moose_nerp import ep from moose_nerp.graph import plot_channel, neuron_graph, spine_graph option_parser = standard_options.standard_options( default_injection_current=[-200e-12, -100e-12, 150e-12, 50e-12], default_simulation_time=0.6, default_injection_width=0.3, default_injection_delay=0.1, default_plotdt=0.0001) param_sim = option_parser.parse_args() param_sim.hsolve = 1 plotcomps = [ep.param_cond.NAME_SOMA] ######## adjust the model settings if specified by command-line options and retain model defaults otherwise #These assignment statements are required because they are not part of param_sim namespace. if param_sim.calcium is not None: ep.calYN = param_sim.calcium if param_sim.spines is not None: ep.spineYN = param_sim.spines if param_sim.stim_paradigm is not None:
import numpy as np import matplotlib.pyplot as plt plt.ion() from pprint import pprint import moose from moose_nerp.prototypes import (cell_proto, calcium, clocks, inject_func, tables, plasticity_test, logutil, util, standard_options, constants) from moose_nerp import gp from moose_nerp.graph import plot_channel, neuron_graph, spine_graph option_parser = standard_options.standard_options( default_injection_current=[25e-12], #[-100e-12, -50e-12, 25e-12,75e-12], default_simulation_time=0.6, default_injection_width=0.4, default_plotdt=0.0001) #,default_stim='PSP_1') # Issue with stimulation needs fixing: #Line 83: st, spines, pg = inject_func.ConnectPreSynapticPostSynapticStimulation(gp,ntype) #File "moose_nerp/prototypes/inject_func.py", line 227, in ConnectPreSynapticPostSynapticStimulation #stim_spines.update(new_spines) #TypeError: 'NoneType' object is not iterable #same error with or without spines param_sim = option_parser.parse_args() plotcomps = [gp.param_cond.NAME_SOMA] ######## adjust the model settings if specified by command-line options and retain model defaults otherwise