def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): def _get_path(file_name): # Unless file-name is an absolute path then it should be placed in the $OUTPUT_DIR if file_name is None: return None return file_name if os.path.isabs(file_name) else os.path.join( tmp_dir, file_name) self._csv_fname = _get_path(spikes_file_csv) self._h5_fname = _get_path(spikes_file) self._nwb_fname = _get_path(spikes_file_nwb) self._tmp_dir = tmp_dir self._tmp_file_base = 'tmp_spike_times' self._spike_labels = os.path.join(self._tmp_dir, self._tmp_file_base) self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS) self._spike_writer.delimiter = '\t' self._spike_writer.gid_col = 0 self._spike_writer.time_col = 1 self._sort_order = spikes_sort_order self._spike_detector = None
def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): # TODO: Have option to turn off caching spikes to csv. def _file_path(file_name): if file_name is None: return None return file_name if os.path.isabs(file_name) else os.path.join( tmp_dir, file_name) self._csv_fname = _file_path(spikes_file_csv) self._save_csv = spikes_file_csv is not None self._h5_fname = _file_path(spikes_file) self._save_h5 = spikes_file is not None self._nwb_fname = _file_path(spikes_file_nwb) self._save_nwb = spikes_file_nwb is not None self._tmpdir = tmp_dir self._sort_order = spikes_sort_order self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS)
def __spike_writer_orig(self): from bmtk.utils.io.spike_trains import SpikeTrainWriter tmpdir = tempfile.mkdtemp() spike_trains = SpikeTrainWriter(tmpdir) for node_id in range(1000): spike_trains.add_spike(1.0, node_id) for node_id in range(1000, 3000): spike_trains.add_spikes(np.linspace(0, 2000.0, 1000), node_id) spike_trains.flush() spike_trains.close()
def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): # TODO: Have option to turn off caching spikes to csv. self._csv_fname = spikes_file_csv self._save_csv = spikes_file_csv is not None self._h5_fname = spikes_file self._save_h5 = spikes_file is not None self._nwb_fname = spikes_file_nwb self._save_nwb = spikes_file_nwb is not None self._tmpdir = tmp_dir self._sort_order = spikes_sort_order self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS)
def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): self._csv_fname = spikes_file_csv self._h5_fname = spikes_file self._nwb_fname = spikes_file_nwb self._tmp_dir = tmp_dir self._tmp_file_base = 'tmp_spike_times' self._spike_labels = os.path.join(self._tmp_dir, self._tmp_file_base) self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS) self._spike_writer.delimiter = '\t' self._spike_writer.gid_col = 0 self._spike_writer.time_col = 1 self._sort_order = spikes_sort_order self._spike_detector = None
def __init__(self, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, tmp_dir='output'): def _get_file_path(file_name): if file_name is None or os.path.isabs(file_name): return file_name return os.path.join(tmp_dir, file_name) self._csv_fname = _get_file_path(spikes_file_csv) self._save_csv = spikes_file_csv is not None self._h5_fname = _get_file_path(spikes_file) self._save_h5 = spikes_file is not None self._nwb_fname = _get_file_path(spikes_file_nwb) self._save_nwb = spikes_file_nwb is not None self._tmpdir = tmp_dir self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir)
class SpikesMod(SimulatorMod): """Module use for saving spikes """ def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): # TODO: Have option to turn off caching spikes to csv. self._csv_fname = spikes_file_csv self._save_csv = spikes_file_csv is not None self._h5_fname = spikes_file self._save_h5 = spikes_file is not None self._nwb_fname = spikes_file_nwb self._save_nwb = spikes_file_nwb is not None self._tmpdir = tmp_dir self._sort_order = spikes_sort_order self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS) def initialize(self, sim): # TODO: since it's possible that other modules may need to access spikes, set_spikes_recordings() should # probably be called in the simulator itself. sim.set_spikes_recording() def block(self, sim, block_interval): # take spikes from Simulator spikes vector and save to the tmp file for gid, tVec in sim.spikes_table.items(): for t in tVec: self._spike_writer.add_spike(time=t, gid=gid) pc.barrier() # wait until all ranks have been saved sim.set_spikes_recording() # reset recording vector def finalize(self, sim): self._spike_writer.flush() pc.barrier() if self._save_csv: self._spike_writer.to_csv(self._csv_fname, sort_order=self._sort_order) pc.barrier() if self._save_h5: self._spike_writer.to_hdf5(self._h5_fname, sort_order=self._sort_order) pc.barrier() if self._save_nwb: self._spike_writer.to_nwb(self._nwb_fname, sort_order=self._sort_order) pc.barrier() self._spike_writer.close()
class SpikesMod(object): """Module use for saving spikes """ def __init__(self, tmp_dir, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, spikes_sort_order=None): def _get_path(file_name): # Unless file-name is an absolute path then it should be placed in the $OUTPUT_DIR if file_name is None: return None return file_name if os.path.isabs(file_name) else os.path.join( tmp_dir, file_name) self._csv_fname = _get_path(spikes_file_csv) self._h5_fname = _get_path(spikes_file) self._nwb_fname = _get_path(spikes_file_nwb) self._tmp_dir = tmp_dir self._tmp_file_base = 'tmp_spike_times' self._spike_labels = os.path.join(self._tmp_dir, self._tmp_file_base) self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir, mpi_rank=MPI_RANK, mpi_size=N_HOSTS) self._spike_writer.delimiter = '\t' self._spike_writer.gid_col = 0 self._spike_writer.time_col = 1 self._sort_order = spikes_sort_order self._spike_detector = None def initialize(self, sim): self._spike_detector = nest.Create( "spike_detector", 1, { 'label': self._spike_labels, 'withtime': True, 'withgid': True, 'to_file': True }) for pop_name, pop in sim._graph._nestid2nodeid_map.items(): nest.Connect(list(pop.keys()), self._spike_detector) def finalize(self, sim): if MPI_RANK == 0: for gdf_file in glob.glob(self._spike_labels + '*.gdf'): self._spike_writer.add_spikes_file(gdf_file) io.barrier() gid_map = sim._graph._nestid2gid if self._csv_fname is not None: self._spike_writer.to_csv(self._csv_fname, sort_order=self._sort_order, gid_map=gid_map) io.barrier() if self._h5_fname is not None: self._spike_writer.to_hdf5(self._h5_fname, sort_order=self._sort_order, gid_map=gid_map) io.barrier() if self._nwb_fname is not None: self._spike_writer.to_nwb(self._nwb_fname, sort_order=self._sort_order, gid_map=gid_map) io.barrier() self._spike_writer.close()
class SpikesGenerator(SimModule): def __init__(self, spikes_file_csv=None, spikes_file=None, spikes_file_nwb=None, tmp_dir='output'): def _get_file_path(file_name): if file_name is None or os.path.isabs(file_name): return file_name return os.path.join(tmp_dir, file_name) self._csv_fname = _get_file_path(spikes_file_csv) self._save_csv = spikes_file_csv is not None self._h5_fname = _get_file_path(spikes_file) self._save_h5 = spikes_file is not None self._nwb_fname = _get_file_path(spikes_file_nwb) self._save_nwb = spikes_file_nwb is not None self._tmpdir = tmp_dir self._spike_writer = SpikeTrainWriter(tmp_dir=tmp_dir) def save(self, sim, gid, times, rates): try: spike_trains = np.array( f_rate_to_spike_train(times * 1000.0, rates, np.random.randint(10000), 1000. * min(times), 1000. * max(times), 0.1)) except: # convert to milliseconds and hence the multiplication by 1000 spike_trains = 1000.0 * np.array( pg.generate_inhomogenous_poisson( times, rates, seed=np.random.randint(10000))) self._spike_writer.add_spikes(times=spike_trains, gid=gid) def finalize(self, sim): self._spike_writer.flush() if self._save_csv: self._spike_writer.to_csv(self._csv_fname) if self._save_h5: self._spike_writer.to_hdf5(self._h5_fname) if self._save_nwb: self._spike_writer.to_nwb(self._nwb_fname) self._spike_writer.close()