bmtk.utils.reports.spike_trains package

Submodules

bmtk.utils.reports.spike_trains.core module

class bmtk.utils.reports.spike_trains.core.SortOrder(value)[source]

Bases: Enum

An enumeration.

by_id = 'by_id'
by_time = 'by_time'
none = 'none'
unknown = 'unknown'
bmtk.utils.reports.spike_trains.core.find_conversion(units_old, units_new)[source]
bmtk.utils.reports.spike_trains.core.find_file_type(path)[source]

Tries to find the input type (sonata/h5, NWB, CSV) from the file-name

bmtk.utils.reports.spike_trains.plotting module

bmtk.utils.reports.spike_trains.plotting.moving_average(data, window_size=10)[source]
bmtk.utils.reports.spike_trains.plotting.plot_raster(spike_trains, with_histogram=True, population=None, node_groups=None, times=None, title=None, show=True, save_as=None, plt_style=None)[source]

will create a raster plot (plus optional histogram) from a SpikeTrains object or SONATA Spike-Trains file. Will return the figure

By default will display all nodes, if you want to only display a subset of nodes and/or group together different nodes (by node_id) by dot colors and labels then you can use the node_groups, which should be a list of dicts:

plot_raster('/path/to/my/spike.h5',
node_groups=[{'node_ids': range(0, 70), 'c': 'b', 'label': 'pyr'},      # first 70 nodes are blue pyr cells
             {'node_ids': range(70, 100), 'c': 'r', 'label': 'inh'}])   # last 30 nodes are red inh cells

The histogram will not be grouped.

Parameters:
  • spike_trains – SpikeTrains object or path to a (SONATA) spikes file.

  • with_histogram – If True the a histogram will be shown as a small subplot below the scatter plot. Default True.

  • population – string. If a spikes-file contains more than one population of nodes, use this to determine which nodes to actually plot. If only one population exists and population=None then the function will find it by default.

  • node_groups – None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should be a dictionary with a ‘node_ids’ key with a list of the ids. You can also add ‘label’ and ‘c’ keys for label and color. If None all nodes will be labeled and colored the same.

  • times – (float, float). Used to set start and stop time. If not specified will try to find values from spiking data.

  • title – str, Use to add a title. Default no tile

  • show – bool to display or not display plot. default True.

  • save_as – None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not save plot.

Returns:

matplotlib figure.Figure object

bmtk.utils.reports.spike_trains.plotting.plot_rates(spike_trains, population=None, node_groups=None, times=None, smoothing=False, smoothing_params=None, title=None, show=True, save_as=None, plt_style=None)[source]

Calculate and plot the rates of each node in a SpikeTrains object or SONATA Spike-Trains file. If start and stop times are not specified from the “times” parameter, will try to parse values from the timestamps data.

If you want to only display a subset of nodes and/or group together different nodes (by node_id) by dot colors and labels then you can use the node_groups, which should be a list of dicts:

plot_rates('/path/to/my/spike.h5',
            node_groups=[{'node_ids': range(0, 70), 'c': 'b', 'label': 'pyr'},
                         {'node_ids': range(70, 100), 'c': 'r', 'label': 'inh'}])
Parameters:
  • spike_trains – SpikeTrains object or path to a (SONATA) spikes file.

  • population – string. If a spikes-file contains more than one population of nodes, use this to determine which nodes to actually plot. If only one population exists and population=None then the function will find it by default.

  • node_groups – None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should be a dictionary with a ‘node_ids’ key with a list of the ids. You can also add ‘label’ and ‘c’ keys for label and color. If None all nodes will be labeled and colored the same.

  • times – (float, float). Used to set start and stop time. If not specified will try to find values from spiking data.

  • smoothing – Bool or function. Used to smooth the data. By default (False) no smoothing will be done. If True will using a moving average smoothing function. Or use a function pointer.

  • smoothing_params – dict, parameters when using a function pointer smoothing value.

  • title – str, Use to add a title. Default no tile

  • show – bool to display or not display plot. default True.

  • save_as – None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not save plot.

Returns:

matplotlib figure.Figure object

bmtk.utils.reports.spike_trains.plotting.plot_rates_boxplot(spike_trains, population=None, node_groups=None, times=None, title=None, show=True, save_as=None, plt_style=None)[source]

Creates a box plot of the firing rates taken from a SpikeTrains object or SONATA Spike-Trains file. If start and stop times are not specified from the “times” parameter, will try to parse values from the timestamps data.

By default will plot all nodes together. To only display a subset of the nodes and/or create groups of nodes use the node_groups options:

plot_rates_boxplot(
    '/path/to/my/spike.h5',
    node_groups=[{'node_ids': range(0, 70), 'label': 'pyr'},
                 {'node_ids': range(70, 100), 'label': 'inh'}]
)
Parameters:
  • spike_trains – SpikeTrains object or path to a (SONATA) spikes file.

  • population – string. If a spikes-file contains more than one population of nodes, use this to determine which nodes to actually plot. If only one population exists and population=None then the function will find it by default.

  • node_groups – None or list of dicts. Used to group sets of nodes by labels and color. Each grouping should be a dictionary with a ‘node_ids’ key with a list of the ids. You can also add ‘label’ and ‘c’ keys for label and color. If None all nodes will be labeled and colored the same.

  • title – str, Use to add a title. Default no tile

  • show – bool to display or not display plot. default True.

  • save_as – None or str: file-name/path to save the plot as a png/jpeg/etc. If None or empty string will not save plot.

Returns:

matplotlib figure.Figure object

bmtk.utils.reports.spike_trains.spike_train_buffer module

class bmtk.utils.reports.spike_trains.spike_train_buffer.STCSVBuffer(cache_dir=None, default_population=None, cache_name='spikes', **kwargs)[source]

Bases: SpikeTrainsAPI

A Class for creating, storing and reading multi-population spike-trains - especially for saving the spikes of a large scale network simulation. Keeps a running tally of the (timestamp, population-name, node_id) for each individual spike.

Uses a caching mechanism to periodically save spikes to the disk. Will encure a runtime performance penality but will always have an upper bound on the maximum memory used.

If running parallel simulations should use the STMPIBuffer adaptor instead.

add_spike(node_id, timestamp, population=None, **kwargs)[source]

Add a single spike

Parameters:
  • node_id – integer, id of node/cell that spike belongs too.

  • timestamp – double, time that spike occurred.

  • population – string, name of population belong to spike. If none will try to use the default population.

  • kwargs – optional arguments.

add_spikes(node_ids, timestamps, population=None, **kwargs)[source]

Add a sequence of spikes.

Parameters:
  • node_ids – list of ints or int. If a list is used, it should be the same lenght as the corresponding timestamps. If a singluar integer value is used then assumes all timestamps corresponds with said node_id.

  • timestamps – A list of doubles

  • population – The population to which the node(s) belong too

  • kwargs – optional arguments.

close()[source]
flush()[source]

Used by some underlying strategies to finish saving spikes.

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

set_units(u, population=None)[source]

Set the units associated with a population timestamps (ms, seconds)

spikes(populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

time_range(populations=None)[source]
to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

units(population=None)[source]

Returns the units used in the timestamps.

Returns:

str

class bmtk.utils.reports.spike_trains.spike_train_buffer.STCSVMPIBuffer(cache_dir=None, default_population=None, cache_name='spikes', **kwargs)[source]

Bases: STCSVBuffer

get_populations(on_rank='all')[source]
get_times(node_id, population=None, time_window=None, on_rank='all', **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None, on_rank='all')[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None, on_rank='all')[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

spikes(populations=None, time_window=None, sort_order=SortOrder.none, on_rank='all', **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

class bmtk.utils.reports.spike_trains.spike_train_buffer.STCSVMPIBufferV2(cache_dir=None, default_population=None, cache_name='spikes', **kwargs)[source]

Bases: STCSVMPIBuffer

to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, on_rank='all', **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_buffer.STMPIBuffer(default_population=None, store_type='array', **kwargs)[source]

Bases: STMemoryBuffer

get_populations(on_rank='all')[source]
get_times(node_id, population=None, time_window=None, on_rank='all', **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None, on_rank='all')[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None, on_rank='all')[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

spikes(populations=None, time_window=None, sort_order=SortOrder.none, on_rank='all', **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, on_rank='all', **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_buffer.STMemoryBuffer(default_population=None, store_type='array', **kwargs)[source]

Bases: SpikeTrainsAPI

A Class for creating, storing and reading multi-population spike-trains - especially for saving the spikes of a large scale network simulation. Keeps a running tally of the (timestamp, population-name, node_id) for each individual spike.

The spikes are stored in memory and very large and/or epiletic simulations may run into memory issues. Not designed to work with parallel simulations.

add_spike(node_id, timestamp, population=None, **kwargs)[source]

Add a single spike

Parameters:
  • node_id – integer, id of node/cell that spike belongs too.

  • timestamp – double, time that spike occurred.

  • population – string, name of population belong to spike. If none will try to use the default population.

  • kwargs – optional arguments.

add_spikes(node_ids, timestamps, population=None, **kwargs)[source]

Add a sequence of spikes.

Parameters:
  • node_ids – list of ints or int. If a list is used, it should be the same lenght as the corresponding timestamps. If a singluar integer value is used then assumes all timestamps corresponds with said node_id.

  • timestamps – A list of doubles

  • population – The population to which the node(s) belong too

  • kwargs – optional arguments.

close()[source]
flush()[source]

Used by some underlying strategies to finish saving spikes.

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

import_spikes(obj, **kwargs)[source]

Import spikes from another spike-trains or other object. Highly dependent on stragey

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

set_units(v, population=None)[source]

Set the units associated with a population timestamps (ms, seconds)

spikes(populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

units(population=None)[source]

Returns the units used in the timestamps.

Returns:

str

bmtk.utils.reports.spike_trains.spike_train_readers module

class bmtk.utils.reports.spike_trains.spike_train_readers.CSVSTReader(path, sep=' ', default_population=None, **kwargs)[source]

Bases: SpikeTrainsReadOnlyAPI

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

spikes(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_readers.EmptySonataReader(path, **kwargs)[source]

Bases: SpikeTrainsReadOnlyAPI

A Hack that is needed for when a simulation produces a file with no spikes, since there won’t/can’t be <population_name> subgroup and/or gids/timestamps datasets.

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

spikes(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

time_range(populations=None)[source]
to_dataframe(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_readers.NWBSTReader(path, **kwargs)[source]

Bases: SpikeTrainsReadOnlyAPI

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

spikes(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

to_dataframe(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_readers.SonataOldReader(path, **kwargs)[source]

Bases: SonataSTReader

Older version of SONATA

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

spikes(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

time_range(populations=None)[source]
to_dataframe(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

class bmtk.utils.reports.spike_trains.spike_train_readers.SonataSTReader(path, **kwargs)[source]

Bases: SpikeTrainsReadOnlyAPI

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

set_units(u, population=None)[source]

Set the units associated with a population timestamps (ms, seconds)

sort_order(population=None)[source]
spikes(node_ids=None, populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

time_range(populations=None)[source]
to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

units(population=None)[source]

Returns the units used in the timestamps.

Returns:

str

bmtk.utils.reports.spike_trains.spike_train_readers.load_sonata_file(path, version=None, **kwargs)[source]

Loads a Sonata file reader, making sure it matches the correct version.

Parameters:
  • path

  • version

  • kwargs

Returns:

bmtk.utils.reports.spike_trains.spike_train_readers.to_list(v)[source]

bmtk.utils.reports.spike_trains.spike_trains module

class bmtk.utils.reports.spike_trains.spike_trains.GammaSpikeGenerator(population=None, seed=None, output_units='ms', **kwargs)[source]

Bases: SpikeGenerator

A Class for generating spike-trains based on a gamma-distributed renewal process.

add(node_ids, firing_rate, a, population=None, times=(0.0, 1.0))[source]
Parameters:
  • firing_rate – Stationary firing rate (Hz)

  • a – Shape parameter (a>0). For a=1, this becomes a Poisson distribution.

  • times – Start and end time for spike train (s)

time_range(population=None)[source]
class bmtk.utils.reports.spike_trains.spike_trains.PoissonSpikeGenerator(population=None, seed=None, output_units='ms', **kwargs)[source]

Bases: SpikeGenerator

A Class for generating spike-trains with a homogeneous and inhomogeneous Poisson distribution.

Uses the methods describe in Dayan and Abbott, 2001.

add(node_ids, firing_rate, population=None, times=(0.0, 1.0), abs_ref=0, tau_ref=0)[source]
Parameters:
  • firing_rate – Scalar stationary firing rate or array of values for inhomogeneous (Hz)

  • times – Start and end time for spike train (s)

  • abs_ref – Absolute refractory period (s)

  • tau_ref – Relative refractory period time constant for exponential recovery (s)

time_range(population=None)[source]
class bmtk.utils.reports.spike_trains.spike_trains.SpikeGenerator(population=None, seed=None, output_units='ms', **kwargs)[source]

Bases: SpikeTrains

class bmtk.utils.reports.spike_trains.spike_trains.SpikeTrains(spikes_adaptor=None, **kwargs)[source]

Bases: object

A class for creating and reading spike files.

classmethod from_csv(path, **kwargs)[source]
classmethod from_nwb(path, **kwargs)[source]
classmethod from_sonata(path, **kwargs)[source]
classmethod load(path, file_type=None, **kwargs)[source]
bmtk.utils.reports.spike_trains.spike_trains.fr_corr(abs_ref, tau_ref)[source]

bmtk.utils.reports.spike_trains.spike_trains_api module

class bmtk.utils.reports.spike_trains.spike_trains_api.SpikeTrainsAPI[source]

Bases: object

add_spike(node_id, timestamp, population=None, **kwargs)[source]

Add a single spike

Parameters:
  • node_id – integer, id of node/cell that spike belongs too.

  • timestamp – double, time that spike occurred.

  • population – string, name of population belong to spike. If none will try to use the default population.

  • kwargs – optional arguments.

add_spikes(node_ids, timestamps, population=None, **kwargs)[source]

Add a sequence of spikes.

Parameters:
  • node_ids – list of ints or int. If a list is used, it should be the same lenght as the corresponding timestamps. If a singluar integer value is used then assumes all timestamps corresponds with said node_id.

  • timestamps – A list of doubles

  • population – The population to which the node(s) belong too

  • kwargs – optional arguments.

close()[source]
flush()[source]

Used by some underlying strategies to finish saving spikes.

get_times(node_id, population=None, time_window=None, **kwargs)[source]

Returns a list of spike-times for a given node.

Parameters:
  • node_id – The id of the node

  • population – Name of the node-population which the node belongs to. By default will try to use the default population (if possible).

  • time_window – A tuple (min-time, max-time) to limit the returned spikes. By default returns all spikes.

  • kwargs – optional arguments.

Returns:

list of spike times [float]

import_spikes(obj, **kwargs)[source]

Import spikes from another spike-trains or other object. Highly dependent on stragey

is_equal(other, populations=None, err=1e-05, time_window=None)[source]

Compares two SpikeTrains instances to see if they have the same spikes (exlcuding order or their method of storage). Use this method instead of == when one of the spike-train instances has extra populations or timestamps are stored at a different precision.

Parameters:
  • other – spike-trains instance being compared

  • populations – string or list of strings, populations to compare between the two. By default (populations=None) will return True only if the two files have the same populations.

  • err – precision on which two timestamps are compared.

  • time_window

Returns:

True if the two spike-trains have the same node-ids/timestamps (given the conditions).

is_subset(other, err=1e-05, strict=False)[source]

Checks to see if this given set of spike-trains is a subset of another, which means that every (population, node_id, timestamp) that exists in self also exists in other.

WARNING: It may be possible, possible due to precision, that a node has two spikes at the same time. Right now this isn’t accounted for, and if self’s node 0 has two spikes at 100.00 ms it except other.node[0] has two spikes at 100.00 ms as well. # TODO: Account for non-uniqueness in on the timestamps

Parameters:
  • other

  • err – precision for comparing two timestamps

  • strict – bool, if True makes sure that self is a strict subset of other. default False

Returns:

merge(other)[source]

Import Another SpikesTrain object into current file, always in-place.

Parameters:

other – Another SpikeTrainsAPI object

n_spikes(population=None)[source]

Get the number of spikes for the given population.

Parameters:

population – population name. If none None will use the default population (when possible).

Returns:

unsigned integer, number of spikes.

node_ids(population=None)[source]

Returns a list of (node-ids, population_name).

Parameters:

population – Name of population, if not set uses the default_population

Returns:

A list of node-ids (integers).

property populations

Get all available spike population names

Returns:

A list of strings

set_units(u, population=None)[source]

Set the units associated with a population timestamps (ms, seconds)

sort_order(population=None)[source]
spikes(populations=None, time_window=None, sort_order=SortOrder.none, **kwargs)[source]

Iterate over all the saved spikes, returning a single spike at a time. Will typically be slower than calling to_dataframe(), but not require as much memory. To use the generator:

for node_id, population, timestamp in spike_trains.spikes():
    ...
Parameters:
  • populations – string or list of strings, used to select specific node_populations. By default all populations with spikes data is iterated over

  • time_window

  • sort_order

  • kwargs

Returns:

to_csv(path, mode='w', sort_order=SortOrder.none, **kwargs)[source]

Write spikes to csv file

Parameters:
  • path

  • mode

  • sort_order

  • kwargs

Returns:

to_dataframe(populations=None, sort_order=SortOrder.none, with_population_col=True, **kwargs)[source]

Returns a pandas dataframe of the node_ids, populations, and timestamps of the given spikes

Parameters:
  • populations – string or list of strings, used to only return the dataframes associated with a given node population. By default (populations=None) all populations are included

  • sort_order – ‘by_time’, ‘by_id’, ‘none’ or None. Returns the dataframe sorted within their population. By default will not sort and return spikes as they are saved

  • with_population_col – bool, set to False to not return the ‘population’ column (useful for really large dataframs with only one population). True by default

  • kwargs

Returns:

A pandas dataframe, unindex, with columns ‘node_ids’, ‘timestamps’, and ‘population’ (optional)

to_nwb(path, mode='w', **kwargs)[source]
to_sonata(path, mode='w', sort_order=SortOrder.none, compression='gzip', **kwargs)[source]

Write current spike-trains to a sonata hdf5 file

Parameters:
  • path

  • mode

  • sort_order

  • compression – Compression algorithm for h5py’s dataset_create. ‘gzip’ is default Only applied to h5 spike data.

  • kwargs

Returns:

units(population=None)[source]

Returns the units used in the timestamps.

Returns:

str

class bmtk.utils.reports.spike_trains.spike_trains_api.SpikeTrainsReadOnlyAPI[source]

Bases: SpikeTrainsAPI

add_spike(node_id, timestamp, population=None, **kwargs)[source]

Add a single spike

Parameters:
  • node_id – integer, id of node/cell that spike belongs too.

  • timestamp – double, time that spike occurred.

  • population – string, name of population belong to spike. If none will try to use the default population.

  • kwargs – optional arguments.

add_spikes(node_ids, timestamps, population=None, **kwargs)[source]

Add a sequence of spikes.

Parameters:
  • node_ids – list of ints or int. If a list is used, it should be the same lenght as the corresponding timestamps. If a singluar integer value is used then assumes all timestamps corresponds with said node_id.

  • timestamps – A list of doubles

  • population – The population to which the node(s) belong too

  • kwargs – optional arguments.

close()[source]
flush()[source]

Used by some underlying strategies to finish saving spikes.

import_spikes(obj, **kwargs)[source]

Import spikes from another spike-trains or other object. Highly dependent on stragey

warning_msg = 'read-only SpikeTrains, trying to add or import spikes will be ignored.'

bmtk.utils.reports.spike_trains.spikes_file_writers module

bmtk.utils.reports.spike_trains.spikes_file_writers.write_csv(path, spiketrain_reader, mode='w', sort_order=SortOrder.none, include_header=True, include_population=True, units='ms', **kwargs)[source]
bmtk.utils.reports.spike_trains.spikes_file_writers.write_csv_itr(path, spiketrain_reader, mode='w', sort_order=SortOrder.none, include_header=True, include_population=True, units='ms', **kwargs)[source]
bmtk.utils.reports.spike_trains.spikes_file_writers.write_sonata(path, spiketrain_reader, mode='w', sort_order=SortOrder.none, units='ms', population_renames=None, compression='gzip', **kwargs)[source]
bmtk.utils.reports.spike_trains.spikes_file_writers.write_sonata_itr(path, spiketrain_reader, mode='w', sort_order=SortOrder.none, units='ms', population_renames=None, compression='gzip', **kwargs)[source]

bmtk.utils.reports.spike_trains.stats module

bmtk.utils.reports.spike_trains.stats.fr_mean(spike_trains, **kwargs)[source]

Module contents