def test_network_plot(self): # Generate test signal brunel_ai = ninemlcatalog.load('network/Brunel2000/AI.xml').as_network( 'Brunel2000AI') scaled_brunel_ai_path = os.path.join(self.work_dir, 'brunel_scaled.xml') brunel_ai.scale(0.01).write(scaled_brunel_ai_path) argv = ("{} nest 100.0 0.1 " "--record Exc.spike_output {}".format( scaled_brunel_ai_path, self.network_signal_path)) simulate.run(argv.split()) # Run plotting command for pop_name in self.recorded_pops: out_path = '{}/{}.png'.format(self.work_dir, pop_name) argv = ("{in_path} --save {out_path} --hide --dims 5 5 " "--resolution 100.0".format( in_path=self.network_signal_path, out_path=out_path, name='v')) plot.run(argv.split()) image = img.imread(out_path) self._ref_network_plot() ref_image = img.imread(self.ref_network_path) self.assertEqual(image.shape, ref_image.shape) self.assertTrue( (image == ref_image).all(), "Plotted spike data using 'plot' command (saved to '{}') " "did not match loaded image from '{}'".format( out_path, self.ref_network_path))
def test_network(self): nest.ResetKernel() for simulator in ('nest', 'neuron'): out_path = '{}/{}.neo.pkl'.format(self.tmpdir, simulator) argv = ( "{nineml_model} {sim} {t_stop} {dt} " "--record Exc.spikes {out_path} exc " "--record Inh.spikes {out_path} inh " "--build_mode force" .format(nineml_model=self.reduced_brunel_path, sim=simulator, out_path=out_path, t_stop=self.t_stop, dt=self.dt)) simulate.run(argv.split()) recs = {} for spiketrain in neo.io.PickleIO(out_path).read()[0].spiketrains: recs[spiketrain.name] = spiketrain ref_recs = self._ref_network(simulator) for pop_name in self.recorded_pops: self.assertTrue( all(recs[pop_name] == ref_recs[pop_name]), "'simulate' command produced different results to" " to api reference for izhikevich model using " "'{}' simulator".format(simulator)) # TODO: Need a better test self.assertGreater( len(recs[pop_name]), 0, "No spikes generated for '{}' population using {}." .format(pop_name, simulator))
def test_network_plot(self): # Generate test signal brunel_ai = ninemlcatalog.load( 'network/Brunel2000/AI.xml').as_network('Brunel2000AI') scaled_brunel_ai_path = os.path.join(self.work_dir, 'brunel_scaled.xml') brunel_ai.scale(0.01).write(scaled_brunel_ai_path) argv = ("{} nest 100.0 0.1 " "--record Exc.spike_output {}" .format(scaled_brunel_ai_path, self.network_signal_path)) simulate.run(argv.split()) # Run plotting command for pop_name in self.recorded_pops: out_path = '{}/{}.png'.format(self.work_dir, pop_name) argv = ("{in_path} --save {out_path} --hide --dims 5 5 " "--resolution 100.0" .format(in_path=self.network_signal_path, out_path=out_path, name='v')) plot.run(argv.split()) image = img.imread(out_path) self._ref_network_plot() ref_image = img.imread(self.ref_network_path) self.assertEqual( image.shape, ref_image.shape) self.assertTrue( (image == ref_image).all(), "Plotted spike data using 'plot' command (saved to '{}') " "did not match loaded image from '{}'" .format(out_path, self.ref_network_path))
def test_network(self): for simulator in ('nest', ): # , 'neuron'): argv = ( "{model_url}#{model_name} {sim} {t_stop} {dt} " "--record Exc.spike_output {tmpdir}/Exc-{sim}.neo.pkl " "{rec_t_start} " "--record Inh.spike_output {tmpdir}/Inh-{sim}.neo.pkl " "{rec_t_start} " "--build_mode force " "--seed {seed}" .format(model_url=self.reduced_brunel_path, model_name=self.brunel_name, sim=simulator, tmpdir=self.tmpdir, t_stop=self.t_stop, dt=self.dt, seed=self.seed, rec_t_start='{} {}'.format(*self.rec_t_start))) simulate.run(argv.split()) ref_recs = self._ref_network(simulator) for pop_name in self.recorded_pops: rec_path = '{}/{}-{}.neo.pkl'.format(self.tmpdir, pop_name, simulator) rec = neo.io.PickleIO(rec_path).read()[0].spiketrains ref = ref_recs[pop_name].spiketrains self.assertTrue( all(all(c == f) for c, f in zip(rec, ref)), "'simulate' command produced different results to" " to api reference for izhikevich model using " "'{}' simulator".format(simulator)) # TODO: Need a better test self.assertGreater( len(rec), 0, "No spikes generated for '{}' population using {}." .format(pop_name, simulator))
def test_single_cell(self): in_path = '{}/isyn.pkl'.format(self.tmpdir) out_path = '{}/v.pkl'.format(self.tmpdir) # First simulate input signal to have something to play into izhikevich # cell argv = ("{input_model} nest {t_stop} {dt} " "--record current_output {out_path} isyn " "--prop amplitude {amp} " "--prop onset {onset} " "--init_value current_output {init} " "--build_mode lazy" .format(input_model=self.isyn_path, out_path=in_path, t_stop=self.t_stop, dt=self.dt, U='{} {}'.format(*self.U), V='{} {}'.format(*self.V), amp='{} {}'.format(*self.isyn_amp), onset='{} {}'.format(*self.isyn_onset), init='{} {}'.format(*self.isyn_init))) # Run input signal simulation print "running input simulation" simulate.run(argv.split()) print "finished running input simulation" isyn = neo.io.PickleIO(in_path).read()[0].analogsignals[0] # Check sanity of input signal self.assertEqual(isyn.max(), self.isyn_amp[0], "Max of isyn input signal {} did not match specified " "amplitude, {}".format(isyn.max(), self.isyn_amp[0])) self.assertEqual(isyn.min(), self.isyn_init[0], "Min of isyn input signal {} did not match specified " "initial value, {}" .format(isyn.max(), self.isyn_init[0])) nest.ResetKernel() for simulator in ('nest', 'neuron'): argv = ( "{nineml_model} {sim} {t_stop} {dt} " "--record V {out_path} v " "--init_value U {U} " "--init_value V {V} " "--play Isyn {in_path} isyn " "--build_mode force" .format(nineml_model=self.izhi_path, sim=simulator, out_path=out_path, in_path=in_path, t_stop=self.t_stop, dt=self.dt, U='{} {}'.format(*self.U), V='{} {}'.format(*self.V), isyn_amp='{} {}'.format(*self.isyn_amp), isyn_onset='{} {}'.format(*self.isyn_onset), isyn_init='{} {}'.format(*self.isyn_init))) simulate.run(argv.split()) v = neo.io.PickleIO(out_path).read()[0].analogsignals[0] ref_v = self._ref_single_cell(simulator, isyn) self.assertTrue(all(v == ref_v), "'simulate' command produced different results to" " to api reference for izhikevich model using " "'{}' simulator".format(simulator)) # TODO: Need a better test self.assertGreater( v.max(), -60.0, "No spikes generated for '{}' (max val: {}) version of Izhi " "model. Probably error in 'play' method if all dynamics tests " "pass ".format(simulator, v.max()))
def test_single_cell_plot(self, show=False): # First simulate input signal to have something to play into # izhikevich cell argv = ("catalog://input/StepCurrent#StepCurrent " "nest {t_stop} {dt} " "--record current_output {out_path} {rec_t_start} " "--prop amplitude {amp} " "--prop onset {onset} " "--init_value current_output {init} " "--build_mode force " "--build_version Plot ".format( out_path=self.cell_input_path, rec_t_start='{} {}'.format(*self.rec_t_start), t_stop=self.t_stop, dt=self.dt, amp='{} {}'.format(*self.isyn_amp), onset='{} {}'.format(*self.isyn_onset), init='{} {}'.format(*self.isyn_init))) # Run input signal simulation simulate.run(argv.split()) argv = ("catalog://neuron/Izhikevich#SampleIzhikevichFastSpiking " "nest {} {} " "--record V {} " "--init_value U 1.625 pA " "--init_value V -65.0 mV " "--play iSyn {in_path} " "--init_regime subVb " "--build_version Plot " "--device_delay 0.5 ms " "--min_delay 0.5 ms ".format(self.t_stop, self.dt, self.cell_signal_path, in_path=self.cell_input_path)) simulate.run(argv.split()) # Run plotting command out_path = '{}/single_cell.png'.format(self.work_dir) argv = ("{in_path} --save {out_path} --dims 5 5 " "--resolution 100.0 {hide}".format( in_path=self.cell_signal_path, out_path=out_path, name='v', hide=('' if show else '--hide'))) plot.run(argv.split()) image = img.imread(out_path) self._ref_single_cell_plot() ref_image = img.imread(self.ref_single_cell_path) self.assertEqual(image.shape, ref_image.shape) self.assertTrue( (image == ref_image).all(), "Ploted single cell data using 'plot' command (saved to '{}') did " "not match loaded image from '{}'".format( out_path, self.ref_single_cell_path))
def test_single_cell_plot(self, show=False): # First simulate input signal to have something to play into # izhikevich cell argv = ("catalog://input/StepCurrent#StepCurrent " "nest {t_stop} {dt} " "--record current_output {out_path} {rec_t_start} " "--prop amplitude {amp} " "--prop onset {onset} " "--init_value current_output {init} " "--build_mode force " "--build_version Plot " .format(out_path=self.cell_input_path, rec_t_start='{} {}'.format(*self.rec_t_start), t_stop=self.t_stop, dt=self.dt, amp='{} {}'.format(*self.isyn_amp), onset='{} {}'.format(*self.isyn_onset), init='{} {}'.format(*self.isyn_init))) # Run input signal simulation simulate.run(argv.split()) argv = ( "catalog://neuron/Izhikevich#SampleIzhikevichFastSpiking " "nest {} {} " "--record V {} " "--init_value U 1.625 pA " "--init_value V -65.0 mV " "--play iSyn {in_path} " "--init_regime subVb " "--build_version Plot " "--device_delay 0.5 ms " "--min_delay 0.5 ms " .format(self.t_stop, self.dt, self.cell_signal_path, in_path=self.cell_input_path)) simulate.run(argv.split()) # Run plotting command out_path = '{}/single_cell.png'.format(self.work_dir) argv = ("{in_path} --save {out_path} --dims 5 5 " "--resolution 100.0 {hide}" .format(in_path=self.cell_signal_path, out_path=out_path, name='v', hide=('' if show else '--hide'))) plot.run(argv.split()) image = img.imread(out_path) self._ref_single_cell_plot() ref_image = img.imread(self.ref_single_cell_path) self.assertEqual(image.shape, ref_image.shape) self.assertTrue( (image == ref_image).all(), "Ploted single cell data using 'plot' command (saved to '{}') did " "not match loaded image from '{}'" .format(out_path, self.ref_single_cell_path))
def test_single_cell(self): in_path = '{}/isyn.pkl'.format(self.tmpdir) out_path = '{}/v.pkl'.format(self.tmpdir) # First simulate input signal to have something to play into izhikevich # cell argv = ("{input_model} nest {t_stop} {dt} " "--record current_output {out_path} {rec_t_start} " "--prop amplitude {amp} " "--prop onset {onset} " "--init_value current_output {init} " "--build_mode lazy " "--build_version Cmd " .format(input_model=self.isyn_path, out_path=in_path, t_stop=self.t_stop, dt=self.dt, amp='{} {}'.format(*self.isyn_amp), onset='{} {}'.format(*self.isyn_onset), init='{} {}'.format(*self.isyn_init), rec_t_start='{} {}'.format(*self.rec_t_start))) # Run input signal simulation simulate.run(argv.split()) isyn = neo.io.PickleIO(in_path).read()[0].analogsignals[0] # Check sanity of input signal self.assertEqual(isyn.max(), self.isyn_amp[0], "Max of isyn input signal {} ({}) did not match " "specified amplitude, {}".format( isyn.max(), in_path, self.isyn_amp[0])) self.assertEqual(isyn.min(), self.isyn_init[0], "Min of isyn input signal {} ({}) did not match " "specified initial value, {}" .format(isyn.min(), in_path, self.isyn_init[0])) for simulator in ('neuron', 'nest'): argv = ( "{nineml_model} {sim} {t_stop} {dt} " "--record V {out_path} {rec_t_start} " "--init_value U {U} " "--init_value V {V} " "--init_regime subVb " "--play iSyn {in_path} " "--build_mode force " "--build_version Cmd " "--device_delay 0.5 ms " "--min_delay 0.5 ms " .format(nineml_model=self.izhi_path, sim=simulator, out_path=out_path, in_path=in_path, t_stop=self.t_stop, dt=self.dt, U='{} {}'.format(*self.U), V='{} {}'.format(*self.V), isyn_amp='{} {}'.format(*self.isyn_amp), isyn_onset='{} {}'.format(*self.isyn_onset), isyn_init='{} {}'.format(*self.isyn_init), rec_t_start='{} {}'.format(*self.rec_t_start))) simulate.run(argv.split()) data_seg = neo.io.PickleIO(out_path).read()[0] v = data_seg.analogsignals[0] regimes = data_seg.epochs[0] ref_v, ref_regimes = self._ref_single_cell(simulator, isyn) self.assertTrue(all(v == ref_v), "'simulate' command produced different results to" " to api reference for izhikevich model using " "'{}' simulator".format(simulator)) # FIXME: Need a better test self.assertGreater( v.max(), -60.0, "No spikes generated for '{}' (max val: {}) version of Izhi " "model. Probably error in 'play' method if all dynamics tests " "pass ".format(simulator, v.max())) self.assertTrue(all(regimes.times == ref_regimes.times)) self.assertTrue(all(regimes.durations == ref_regimes.durations)) self.assertEqual(regimes.labels, ref_regimes.labels) self.assertEqual(len(regimes.times), 6) self.assertEqual(regimes.labels[0], 'subVb') self.assertTrue('subthreshold' in regimes.labels)