API reference

Module MEArec.generators

class TemplateGenerator

class generators.TemplateGenerator(cell_models_folder=None, templates_folder=None, temp_dict=None, info=None, tempgen=None, params=None, intraonly=False, parallel=True, recompile=False, n_jobs=None, joblib_backend='loky', delete_tmp=True, verbose=False)[source]

Bases: object

Class for generation of templates called by the gen_templates function. The list of parameters is in default_params/templates_params.yaml.

Parameters:
  • cell_models_folder (str) – Path to folder containing Blue Brain Project cell models
  • templates_folder (str) – Path to output template folder (if not in params)
  • temp_dict (dict) –
    Dictionary to instantiate TemplateGenerator with existing data. It contains the following fields:
    • templates : float (n_templates, n_electrodes, n_timepoints)
    • locations : float (n_templates, 3)
    • rotations : float (n_templates, 3)
    • celltypes : str (n_templates)
  • info (dict) –
    Info dictionary to instantiate TemplateGenerator with existing data. It contains the following fields:
    • params : dict with template generation parameters
    • electrodes : dict with probe info (from MEAutility.return_mea_info(‘probe-name’))
  • tempgen (TemplateGenerator) – If a TemplateGenerator is passed, the cell types, locations, and rotations of the templates will be set using the provided templates
  • params (dict) – Dictionary with parameters to simulate templates. Default values can be retrieved with mr.get_default_template_params()
  • intraonly (bool) – If True, only intracellular simulations are performed
  • parallel (bool) – If True, cell models are run in parallel
  • recompile (bool) – If True, cell models are recompiled (suggested if new models are added)
  • n_jobs (int) – If None, all cpus are used
  • delete_tmp (bool) – If True, temporary files are removed
  • verbose (bool) – If True, output is verbose
generate_templates()[source]

Generate templates.

class SpikeTrainGenerator

class generators.SpikeTrainGenerator(params=None, spiketrains=None, seed=None, verbose=False)[source]

Bases: object

Class for generation of spike trains called by the gen_recordings function. The list of parameters is in default_params/recordings_params.yaml (spiketrains field).

Parameters:
  • params (dict) – Dictionary with parameters to simulate spiketrains. Default values can be retrieved with mr.get_default_recordings_params()[‘spiketrains’]
  • spiketrains (list of neo.SpikeTrain) – List of neo.SpikeTrain objects to instantiate a SpikeTrainGenerator with existing data
  • verbose (bool) – If True, output is verbose
add_synchrony(idxs, rate=0.05, time_jitt=array(1.) * ms, verbose=False)[source]

Adds synchronous spikes between pairs of spike trains at a certain rate.

Parameters:
  • idxs (list or array) – Spike train indexes to add synchrony to
  • rate (float) – Rate of added synchrony spike to spike train idxs[1] for each spike of idxs[0]
  • time_jitt (quantity) – Maximum time jittering between added spikes
  • verbose (bool) – If True output is verbose
Returns:

  • sync_rate (float) – New synchrony rate
  • fr1 (quantity) – Firing rate spike train 1
  • fr2 (quantity) – Firing rate spike train 2

generate_spikes()[source]

Generate spike trains based on default_params of the SpikeTrainGenerator class. self.spiketrains contains the newly generated spike trains

set_spiketrain(idx, spiketrain)[source]

Sets spike train idx to new spiketrain.

Parameters:
  • idx (int) – Index of spike train to set
  • spiketrain (neo.SpikeTrain) – New spike train

class RecordingGenerator

class generators.RecordingGenerator(spgen=None, tempgen=None, params=None, rec_dict=None, info=None)[source]

Bases: object

Class for generation of recordings called by the gen_recordings function. The list of parameters is in default_params/recordings_params.yaml.

Parameters:
  • spgen (SpikeTrainGenerator) – SpikeTrainGenerator object containing spike trains
  • tempgen (TemplateGenerator) – TemplateGenerator object containing templates
  • params (dict) – Dictionary with parameters to simulate recordings. Default values can be retrieved with mr.get_default_recording_params()
  • rec_dict (dict) –
    Dictionary to instantiate RecordingGenerator with existing data. It contains the following fields:
    • recordings : float (n_electrodes, n_samples)
    • spiketrains : list of neo.SpikeTrains (n_spiketrains)
    • templates : float (n_spiketrains, 3)
    • template_locations : float (n_spiketrains, 3)
    • template_rotations : float (n_spiketrains, 3)
    • template_celltypes : str (n_spiketrains)
    • channel_positions : float (n_electrodes, 3)
    • timestamps : float (n_samples)
    • voltage_peaks : float (n_spiketrains, n_electrodes)
    • spike_traces : float (n_spiketrains, n_samples)
  • info (dict) – Info dictionary to instantiate RecordingGenerator with existing data. Same fields as ‘params’
annotate_overlapping_spikes(parallel=True)[source]

Annnotate spike trains with overlapping information.

parallel : bool
If True, spike trains are annotated in parallel
extract_templates(cut_out=[0.5, 2], recompute=False)[source]

Extract templates from spike trains.

Parameters:
  • cut_out (float or list) – Ms before and after peak to cut out. If float the cut is symmetric.
  • recompute (bool) – If True, templates are recomputed from extracted waveforms
extract_waveforms(cut_out=[0.5, 2])[source]

Extract waveforms from spike trains and recordings.

Parameters:cut_out (float or list) – Ms before and after peak to cut out. If float the cut is symmetric.
generate_recordings(tmp_mode=None, tmp_folder=None, verbose=None, template_ids=None, n_jobs=0)[source]

Generates recordings

Parameters:
  • tmp_mode (None, 'memmap') – Use temporary file h5 memmap or None None is no temporary file and then use memory.
  • tmp_folder (str or Path) – In case of tmp files, you can specify the folder. If None, then it is automatic using tempfile.mkdtemp()
  • n_jobs (int) – if >1 then use joblib to execute chunk in parallel else in loop
  • template_ids (list or None) – If None, templates are selected randomly based on selection rules. If a list of indices is provided, the indices are used to select templates (template selection is bypassed)
  • verbose (bool or int) – Determines the level of verbose. If 1 or True, low-level, if 2 high level, if False, not verbose

Module MEArec.generation_tools

function gen_templates

generation_tools.gen_templates(cell_models_folder, params=None, templates_tmp_folder=None, tempgen=None, intraonly=False, parallel=True, n_jobs=None, joblib_backend='loky', recompile=False, delete_tmp=True, verbose=True)[source]
Parameters:
  • cell_models_folder (str) – path to folder containing cell models
  • params (str or dict) – Path to parameters yaml file or parameters dictionary
  • templates_tmp_folder (str) – Path to temporary folder where templates are temporarily saved
  • tempgen (TemplateGenerator) – If a TemplateGenerator is passed, the cell types, locations, and rotations of the templates will be set using the provided templates
  • intraonly (bool) – if True, only intracellular simulation is run
  • parallel (bool) – if True, multi-threading is used
  • n_jobs (int) – Number of jobs to run in parallel (If None all cpus are used)
  • joblib_backend (str) – The joblib backend to use when n_jobs > 1 (default ‘loky’)
  • recompile (bool) – If True, cell models are recompiled
  • delete_tmp – if True, the temporary files are deleted
  • verbose (bool) – If True, the output is verbose
Returns:

Generated template generator object

Return type:

TemplateGenerator

function gen_spiketrains

generation_tools.gen_spiketrains(params=None, spiketrains=None, seed=None, verbose=False)[source]

Generates spike trains.

Parameters:
  • params (str or dict) – Path to parameters yaml file or parameters dictionary
  • spiketrains (list) – List of neo.SpikeTrains (alternative to params definition)
  • verbose (bool) – If True, the output is verbose
Returns:

Generated spike train generator object

Return type:

SpikeTrainGenerator

function gen_recordings

generation_tools.gen_recordings(params=None, templates=None, tempgen=None, spgen=None, verbose=True, tmp_mode='memmap', template_ids=None, tmp_folder=None, n_jobs=0)[source]

Generates recordings.

Parameters:
  • templates (str) – Path to generated templates
  • params (dict or str) – Dictionary containing recording parameters OR path to yaml file containing parameters
  • tempgen (TemplateGenerator) – Template generator object
  • spgen (SpikeTrainGenerator) – Spike train generator object. If None spike trains are created from params[‘spiketrains’]
  • verbose (bool or int) – Determines the level of verbose. If 1 or True, low-level, if 2 high level, if False, not verbose
  • tmp_mode (None, 'h5' 'memmap') – Use temporary file h5 memmap or None None is no temporary file
  • template_ids (list or None) – If None, templates are selected randomly based on selection rules. If a list of indices is provided, the indices are used to select templates (template selection is bypassed)
  • tmp_folder (str or Path) – In case of tmp files, you can specify the folder. If None, then it is automatic using tempfile.mkdtemp()
Returns:

Generated recording generator object

Return type:

RecordingGenerator

Module MEArec.tools