def test_neuronoptions(): nrnver7 = h.nrnversion(7) # First token is NEURON and may have -dll option print(nrnoptions) print(nrnver7) if neuron_already_imported: warnings.warn( UserWarning( "neuron was already imported prior to setting os.environ")) else: assert nrnoptions in nrnver7 i = 520 assert h.add_recurse(i) == i * (i + 1) / 2
def coreneuron_available(): if "NRN_ENABLE_CORENEURON=ON" not in h.nrnversion(6): # Not ideal. Maybe someday it will be default ON and then # will not appear in h.nrnversion(6) return False # But can it be loaded? cvode = h.CVode() cvode.cache_efficient(1) pc = h.ParallelContext() h.finitialize() result = 0 import sys from io import StringIO original_stderr = sys.stderr sys.stderr = StringIO() try: pc.nrncore_run("--tstop 1 --verbose 0") result = 1 except Exception as e: pass sys.stderr = original_stderr cvode.cache_efficient(0) return result
class LoopTimer(threading.Thread) : """ a Timer that calls f every interval """ def __init__(self, interval, fun) : """ @param interval: time in seconds between call to fun() @param fun: the function to call on timer update """ self.started = False self.interval = interval self.fun = fun threading.Thread.__init__(self) self.setDaemon(True) def run(self) : h.nrniv_bind_thread(threading.current_thread().ident); self.started = True; while True: self.fun() time.sleep(self.interval) if h.nrnversion(9) == '2' or h.nrnversion(8).find('mingw') > 0: timer = LoopTimer(0.1, process_events) timer.start() while not timer.started: time.sleep(0.001) h.load_file("nrngui.hoc")
""" a Timer that calls f every interval """ def __init__(self, interval, fun) : """ @param interval: time in seconds between call to fun() @param fun: the function to call on timer update """ self.started = False self.interval = interval self.fun = fun threading.Thread.__init__(self) self.setDaemon(True) def run(self) : h.nrniv_bind_thread(threading.current_thread().ident); self.started = True; while True: self.fun() time.sleep(self.interval) if h.nrnversion(9) == '2' or h.nrnversion(8).find('mingw') > 0: timer = LoopTimer(0.1, process_events) timer.start() while not timer.started: time.sleep(0.001) h.load_file("nrngui.hoc") h.movie_timer = Timer("moviestep()")
""" def __init__(self, interval, fun): """ @param interval: time in seconds between call to fun() @param fun: the function to call on timer update """ self.started = False self.interval = interval self.fun = fun threading.Thread.__init__(self) self.setDaemon(True) def run(self): h.nrniv_bind_thread(threading.current_thread().ident) self.started = True while True: self.fun() time.sleep(self.interval) if (h.nrnversion(9) == "2" or h.nrnversion(8).find("mingw") > 0 or h.nrnversion(8).find("Windows")): timer = LoopTimer(0.1, process_events) timer.start() while not timer.started: time.sleep(0.001) h.load_file("nrngui.hoc") h.movie_timer = Timer("moviestep()")
""" a Timer that calls f every interval """ def __init__(self, interval, fun) : """ @param interval: time in seconds between call to fun() @param fun: the function to call on timer update """ self.started = False self.interval = interval self.fun = fun threading.Thread.__init__(self) self.setDaemon(True) def run(self) : h.nrniv_bind_thread(threading.current_thread().ident); self.started = True; while True: self.fun() time.sleep(self.interval) if h.nrnversion(9) == '2' or h.nrnversion(8).find('mingw') > 0 or h.nrnversion(8).find('Windows'): timer = LoopTimer(0.1, process_events) timer.start() while not timer.started: time.sleep(0.001) h.load_file("nrngui.hoc") h.movie_timer = Timer("moviestep()")
v0 = h.Vector() v0.record(cable(x0)._ref_v, sample_dt) v1 = h.Vector() v1.record(cable(x1)._ref_v, sample_dt) t = h.Vector() t.record(h._ref_t, sample_dt) h.dt = dt h.steps_per_ms = 1/dt # or else NEURON might noisily fudge dt if 'firstorder' in tags: h.secondorder = 0 else: h.secondorder = 2 h.tstop = tend h.run() # Collect and save data out = xarray.Dataset({'v0': (['time'], list(v0)), 'v1': (['time'], list(v1))}, coords={'time': list(t)}) out.time.attrs['units'] = 'ms' out.v0.attrs['units'] = 'mV' out.v1.attrs['units'] = 'mV' nrnver = h.nrnversion() stdattr.set_stdattr(out, model='rallpack1', simulator='neuron', simulator_build=nrnver, tags=tags, params=params) out.to_netcdf(output)
def save_data(sim_type, conn_type, output_dir): """Saves the expected results""" from bmtk import __version__ as bmtk_version from neuron import h import platform save_file = 'expected/sim_output_{}.h5'.format(sim_type) sample_data = h5py.File(save_file, 'w') root_group = sample_data['/'] root_group.attrs['bmtk'] = bmtk_version root_group.attrs['date'] = str(datetime.datetime.now()) root_group.attrs['python'] = '{}.{}'.format(*sys.version_info[0:2]) root_group.attrs['NEURON'] = h.nrnversion() root_group.attrs['system'] = platform.system() root_group.attrs['arch'] = platform.machine() # spikes data input_spikes = SpikesFile(os.path.join(output_dir, 'spikes.h5')) spikes_df = input_spikes.to_dataframe() sample_data.create_dataset('/spikes/gids', data=np.array(spikes_df['gids'])) sample_data.create_dataset('/spikes/timestamps', data=np.array(spikes_df['timestamps'])) sample_data['/spikes/gids'].attrs['sorting'] = 'time' # soma data soma_reports = CellVarsFile(os.path.join(output_dir, 'soma_vars.h5')) soma_grp = sample_data.create_group('/soma') soma_grp.create_dataset('mapping/time', data=[2500.0, 3000.0, 0.1]) soma_grp.create_dataset('mapping/gids', data=soma_reports.h5['mapping/gids']) # data=[3]) soma_grp.create_dataset('mapping/element_id', data=soma_reports.h5['mapping/element_id']) soma_grp.create_dataset('mapping/element_pos', data=soma_reports.h5['mapping/element_pos']) soma_grp.create_dataset('mapping/index_pointer', data=soma_reports.h5['mapping/index_pointer']) for var_name in soma_reports.variables: ds_name = '{}/data'.format(var_name) soma_grp.create_dataset(ds_name, data=soma_reports.h5[ds_name][-5000:, :]) # compartmental report soma_reports = CellVarsFile(os.path.join(output_dir, 'full_cell_vars.h5')) soma_grp = sample_data.create_group('/compartmental') soma_grp.create_dataset('mapping/time', data=[2500.0, 3000.0, 0.1]) soma_grp.create_dataset('mapping/gids', data=soma_reports.h5['mapping/gids']) # data=[3]) soma_grp.create_dataset('mapping/element_id', data=soma_reports.h5['mapping/element_id']) soma_grp.create_dataset('mapping/element_pos', data=soma_reports.h5['mapping/element_pos']) soma_grp.create_dataset('mapping/index_pointer', data=soma_reports.h5['mapping/index_pointer']) for var_name in soma_reports.variables: ds_name = '{}/data'.format(var_name) soma_grp.create_dataset(ds_name, data=soma_reports.h5[ds_name][-5000:, :]) # ecp data ecp_file = h5py.File(os.path.join(output_dir, 'ecp.h5'), 'r') ecp_grp = sample_data.create_group('/ecp') ecp_grp.create_dataset('data', data=ecp_file['data'][:, 0]) ecp_grp.create_dataset('channel_id', data=ecp_file['channel_id'])
import threading import time def process_events() : #h.doEvents() h.doNotify() #print "timer" class LoopTimer(threading.Thread) : """ a Timer that calls f every interval """ def __init__(self, interval, fun) : """ @param interval: time in seconds between call to fun() @param fun: the function to call on timer update """ self.interval = interval self.fun = fun threading.Thread.__init__(self) self.setDaemon(True) def run(self) : while True: self.fun() time.sleep(self.interval) if (h.nrnversion(9) == '2'): timer = LoopTimer(.2, process_events) timer.start()