olftrans package

Submodules

olftrans.errors module

exception olftrans.errors.MissingFileException[source]

Bases: Exception

exception olftrans.errors.MissingFileWarning[source]

Bases: Warning

olftrans.fbl module

FlyBrainLab compatible module

Classes:

Config: configuration of FBL Module FBL: FlyBrainLab-compatible module to be consumed by other FBL packages

olftrans.fbl.LARVA

an instance of FBL class that is loaded with Larva (Kreher2005) data

olftrans.fbl.ADULT

an instance of FBL class that is loaded with Adult (HallemCarlson20016) data

class olftrans.fbl.Config(NO, affs, drs=None, receptor_names=None, resting=None, sigma=None)[source]

Bases: object

Configuration for FlyBrainLab-compatible Module

Parameters
  • NO (Iterable[int]) –

  • affs (Iterable[float]) –

  • drs (Iterable[float]) –

  • receptor_names (Iterable[str]) –

  • resting (float) –

  • sigma (float) –

Return type

None

NO: Iterable[int]

Number of OSNs per Receptor Type

NR: int

Number of Receptor Types

affs: Iterable[float]

Affinity Values

drs: Iterable[float] = None

Dissociation Rates

receptor_names: Iterable[str] = None

Name of receptors of length NR

resting: float = None

Resting OSN Spike Rates [Hz]

sigma: float = None

NoisyConnorStevens Noise Standard Deviation

class olftrans.fbl.FBL(graph, inputs, outputs, extra_comps=<factory>, config=None)[source]

Bases: object

FlyBrainLab-compatible Module

Parameters
  • graph (networkx.classes.multidigraph.MultiDiGraph) –

  • inputs (dict) –

  • outputs (dict) –

  • extra_comps (List[neurokernel.LPU.NDComponents.NDComponent.NDComponent]) –

  • config (olftrans.fbl.Config) –

Return type

None

affinities: pandas.core.frame.DataFrame = None

a pandas dataframe with affinities saved as reference - index: odorants - columns: receptor names

config: olftrans.fbl.Config = None

configuration

classmethod create_from_config(cfg)[source]

Create Instance from Config

Parameters

cfg (olftrans.fbl.Config) – Config instance that specifies the configuration of the module

Returns

A new FBL instance

extra_comps: List[neurokernel.LPU.NDComponents.NDComponent.NDComponent]

list of neurodriver extra components

classmethod get_config(fbl)[source]

Parse Config from given FBL instance

Return type

olftrans.fbl.Config

graph: networkx.classes.multidigraph.MultiDiGraph

networkx graph describing the executable circuit

inputs: dict

input variable and uids dictionary

outputs: dict

output variable and uids dictionary

simulate(t, inputs, record_var_list=None, sample_interval=1)[source]

Update Affinities and Change Circuit Accordingly

Parameters
  • t (numpy.ndarray) – input time array

  • inputs (Any) – input data - if is BaseInputProcessor instance, passed to LPU directly - if is dictionary, passed to ArrayInputProcessor if is compatible

  • record_var_list (Iterable[Tuple[str, Iterable]]) –

  • sample_interval (int) –

Return type

Tuple[FileInput, FileOutput, LPU]

Keyword Argumnets:

record_var_list: [(var, uids)] sample_interval: interval at which output is recorded

Returns

Input Processor fo: Output Processor lpu: LPU instance

Return type

fi

Parameters
  • t (numpy.ndarray) –

  • inputs (Any) –

  • record_var_list (Iterable[Tuple[str, Iterable]]) –

  • sample_interval (int) –

update_affs(affs)[source]

Update Affinities and Change Circuit Accordingly

Return type

None

update_graph_attributes(data_dict, nodes='otp', receptor=None, node_predictive=None)[source]

Update Attributes of the graph

Parameters
  • data_dict (dict) – a dictionary of {attr: value}

  • nodes (Union[otp, bsg]) –

  • receptor (Iterable[str]) –

  • node_predictive (Callable[networkx.classes.reportviews.NodeView, bool]) –

Keyword Arguments
  • nodes – nodes to update, ‘otp’ or ‘bsg’

  • receptor – filter nodes with receptor

  • node_predictive – additional filtering of nodes from nx.nodes call

Return type

None

Example

>>> fbl.update_graph_attributes({'sigma':1.}, nodes='bsg', receptor=None)
olftrans.fbl.load_adult_affinities(cfg)[source]

Load HallemCarlson Spike Data and Parse to Affinities

olftrans.fbl.load_larva_affinities(cfg)[source]

Load HallemCarlson Spike Data and Parse to Affinities

olftrans.olftrans module

Main module of Olfactory Transduction Module

The module deals with estimation procedures to obtain binding and dissociation rates from peak/steady state spike rates for given odorant.

The main entry of the module is the estimate function.

class olftrans.olftrans.Estimation(sigma, steady_state_spike_rate, peak_spike_rate, steady_state_current, peak_current, affs, br, dr)[source]

Bases: object

Estimation Result

Parameters
  • sigma (float) –

  • steady_state_spike_rate (Union[float, numpy.ndarray]) –

  • peak_spike_rate (Union[float, numpy.ndarray]) –

  • steady_state_current (Union[float, numpy.ndarray]) –

  • peak_current (Union[float, numpy.ndarray]) –

  • affs (Union[float, numpy.ndarray]) –

  • br (Union[float, numpy.ndarray]) –

  • dr (Union[float, numpy.ndarray]) –

Return type

None

affs: Union[float, numpy.ndarray]

affinity values

br: Union[float, numpy.ndarray]

binding rates

dr: Union[float, numpy.ndarray]

dissociation rates

peak_current: Union[float, numpy.ndarray]

peak current estimated from peak spike rate

peak_spike_rate: Union[float, numpy.ndarray]

peak spike rate. This is the part of the input to estimation procedure stored as reference

sigma: float

noise parameter of the NoisyConnorStevens neuron

steady_state_current: Union[float, numpy.ndarray]

steady-state current estimated from steady-state spike rate

steady_state_spike_rate: Union[float, numpy.ndarray]

steady-state spike rate. This is the part of the input to estimation procedure stored as reference

olftrans.olftrans.estimate(amplitude, resting_spike_rate, steady_state_spike_rate, peak_spike_rate=None, decay_time=None, cache=True)[source]

Estimation Procedure

The estimation procedure assumes that the input concentration waveform is a step-waveform with an amplitude of amplitude. The Peak and Steady-State spike rate of the OSN measured is then used to estimate the binding and dissociation rates.

Parameters
  • amplitude (float) – concentration waveform’s amplitdue

  • resting_spike_rate (Union[float, numpy.ndarray]) – resting OSN spike rate

  • steady_state_spike_rate (Union[float, numpy.ndarray]) – steady-state OSN spike rate under input

  • peak_spike_rate (Optional[Union[float, numpy.ndarray]]) –

  • decay_time (Optional[float]) –

  • cache (bool) –

Keyword Arguments
  • peak_spike_rate – peak OSN spike rate under input

  • decay_time – Time for OSN spike to settle back to resting after odorant input offset

  • cache – whether to save the data generated by the estimation result

olftrans.olftrans.estimate_affinity(amplitude, steady_state_current)[source]

Estimate Affinity Value From Steady-State Current

Parameters
  • amplitude (float) – amplitude of the step odorant concentration waveform (in unit of [ppm])

  • steady_state_current (Union[float, numpy.ndarray]) – steady-state OTP output current value

Returns

estimated affinity value

Return type

Union[float, numpy.ndarray]

olftrans.olftrans.estimate_current(spike_rate, sigma, sigma_atol=0.0001, sigma_rtol=0.0001, cache=True)[source]

Estimate Current Value given Spike Rate

The current value is estimated from the spike_rate using the Frequency-Current (F-I) curve that is parameterized by the noise parameter sigma. If the F-I curve of the provided sigma value is not found, the F-I curve is calculated using sigma.

Parameters
  • spike_rate (Union[float, numpy.ndarray]) – output OSN spike rate

  • sigma (float) – noise parameter of the NoisyConnorStevens Model This is used to find the appropriate F-I curve

  • sigma_atol (float) –

  • sigma_rtol (float) –

  • cache (bool) –

Keyword Arguments
  • sigma_atol – absolute tolerence of checking if the required sigma is close to previously cached values

  • sigma_atol – relative tolerence of checking if the required sigma is close to previously cached values

  • cache – save results of F-I curve if it is run due to sigma mismatch

Returns

estimated currents

Return type

Union[float, numpy.ndarray]

olftrans.olftrans.estimate_dissociation(amplitude, affinity, peak_current=None, decay_time=0.1)[source]

Estimate Dissociation Rate

Parameters
  • amplitude (float) – concentration amplitude

  • affinity (Union[float, numpy.ndarray]) – affinity values

  • peak_current (Optional[Union[float, numpy.ndarray]]) –

  • decay_time (float) –

Keyword Arguments
  • peak_current – maximum current

  • decay_time – settling time after offset of odorant input

Returns

Estimated dissociation rate

Return type

Union[float, numpy.ndarray]

olftrans.olftrans.estimate_resting_spike_rate(sigma)[source]

Estimate Resting Spike Rate from Sigma Value

Parameters

sigma (Union[float, numpy.ndarray]) – noise parameter

Returns

estimated resting spike rate

Return type

Union[float, numpy.ndarray]

olftrans.olftrans.estimate_sigma(resting_spike_rate, cache=True)[source]

Estimate Sigma Value given Resting Spike Rate

Parameters
  • resting_spike_rate (Union[float, numpy.ndarray]) –

  • cache (bool) –

Return type

Union[float, numpy.ndarray]

olftrans.olftrans.run(t, waveform, br, dr, sigma)[source]

olftrans.plot module

Plotting functions

olftrans.plot.plot_mat(mat, t=None, ax=None, cax=None, vmin=None, vmax=None, cbar_kw=None, cmap=None)[source]

Plot Matrix with formatted time axes

Parameters
  • mat (numpy.ndarray) – the matrix to be plotted, it should of shape (N, Time)

  • t (Optional[numpy.ndarray]) –

  • ax (Optional[matplotlib.axes._axes.Axes]) –

  • vmin (Optional[float]) –

  • vmax (Optional[float]) –

  • cbar_kw (Optional[dict]) –

  • cmap (Optional[Any]) –

Keyword Arguments
  • t – time axes for the spikes, use arange if not provided

  • ax – which axis to plot into, create one if not provided

  • cax – which axis to plot colorbar into - if instance of axis, plot into that axis - if is True, steal axis from ax

  • vmin – minimum value for the imshow

  • vmax – maximum value for the imshow

  • cbar_kw – keyword arguments to be passed into the colorbar creation

  • cmap – colormap to use

Returns

the axis that the raster is plotted into cbar: colorbar object, only returned if cax is True or a plt.Axes instance

Return type

ax

Example

>>> dt, dur, start, stop = 1e-4, 2, 0.5, 1.0
>>> t = np.arange(0, dur, dt)
>>> amps = np.arange(0, 100, 10)
>>> wav = utils.generate_stimulus('step', dt, dur, (start, stop), amps)
>>> ax,cbar = plot_mat(wav, t=t, cax=True, vmin=10, vmax=100, cbar_kw={'label':'test'}, cmap=plt.cm.gnuplot)
>>> ax, = plot_mat(wav, t=t, cax=False, vmin=10, vmax=100, cbar_kw={'label':'test'}, cmap=plt.cm.gnuplot)
olftrans.plot.plot_multiple(data_x, *args, **kwargs)[source]

Plot multiple data curves against a same x-axis on mulitple subplots.

Parameters
  • datax (darray) – the data point on the x-axis.

  • *args – each entry of args is a list containing multiple sets of data and parameters that will be plotted in the same subplot. An entry should follow the format (data_1, param_1, …), where each of the data_i is a numpy array, and each of the param_i is a dict of the parameters for ploting data_i against data_x. Alternatively, an entry can simply be an numpy array. In this case, only one curve will be plotted in the corresponding subplot.

  • data_x (numpy.ndarray) –

Keyword Arguments
  • figw (float) – the figure width.

  • figh (float) – the figure height.

  • xlabel (str) – the label of the x-axis.

  • additional keyword arguments will propagate into the private (The) –

  • method _plot, and eventually into the pyplot.plot method. (plotting) –

Return type

Tuple[matplotlib.figure.Figure, numpy.ndarray]

olftrans.plot.plot_spikes(spikes, t=None, ax=None, markersize=None, color='k')[source]

Plot Spikes in raster format

Parameters
  • spikes (numpy.ndarray) – the spike states in binary format, where 1 stands for a spike. The shape of the spikes should either be (N_times, ) or (N_trials, N_times)

  • t (Optional[numpy.ndarray]) –

  • ax (Optional[matplotlib.axes._axes.Axes]) –

  • markersize (Optional[int]) –

  • color (Union[str, Any]) –

Keyword Arguments
  • t – time axes for the spikes, use arange if not provided

  • ax – which axis to plot into, create one if not provided

  • markersize – size of raster

  • color – color for the raster. Any acceptable type of matplotlib.pyplot.plot’s color argument is accepted.

Returns

the axis that the raster is plotted into

Return type

ax

olftrans.plot.yyaxis(ax, c='red')[source]

Create A second axis with colored spine/ticks/label

Parameters
  • ax (matplotlib.axes._axes.Axes) – ax to create another y-axis from

  • c (color) –

Keyword Arguments

c – Color

Returns

axis that shares x with ax

Return type

ax2

olftrans.utils module

Utility functions for simulating the synapse and neuron models

class olftrans.utils.PSTH(spikes, d_t, window=0.02, shift=0.01)[source]

Bases: object

Parameters
  • spikes (numpy.ndarray) –

  • d_t (float) –

  • window (float) –

  • shift (float) –

compute()[source]
Return type

Tuple[numpy.ndarray, numpy.ndarray]

merge(others)[source]
Parameters

others (Union[numpy.ndarray, Iterable[numpy.ndarray]]) –

Return type

None

olftrans.utils.compute_psth(spikes, d_t, window, interval)[source]

Compute the peri-stimulus time histogram

Parameters
  • spikes (numpy.ndarray) – spike sequences.

  • d_t (float) – time step.

  • window (float) – the size of the window.

  • interval (float) – the time shift between two consecutive windows.

Returns

the average spike rate for each windows. stamps: the time stamp for each windows.

Return type

rates

olftrans.utils.generate_spike_from_psth(d_t, psth, psth_t=None, num=1)[source]

Generate spike sequeces from a PSTH

Parameters
  • d_t (float) – the sampling interval of the input waveform.

  • psth (numpy.ndarray) – the spike rate waveform.

  • psth_t (Optional[numpy.ndarray]) –

  • num (int) –

Keyword Arguments
  • psth_t – time-stamps of the psth, optional. See Notes for behavior

  • num – number of trials to generate

Returns

A tuple of shape (time, spikes), where spikes is a binary numpy array of either shape (Nt, num) if num > 1, or (Nt,) if num == 1. See Notes for definition of Nt.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

Notes

  1. If psth_t is specified:
    • it needs to have the same dimensionality as psth.

    • In this case, d_t is the desired time-step instead of the time-step of the psth array.

    • Nt is given as np.arange(psth_t.min(), psth_t.max(), dt)

  2. If psth_t is not specified:
    • d_t is the time-step of the psth array

    • Nt given as len(psth)

Examples

>>> from neural import utils, plot
>>> dt, dur, start, stop, amp = 1e-5, 2, 0.5, 1.0, 100.0
>>> spikes = utils.generate_stimulus("spike", dt, dur, (start, stop), np.full((100,), amp))
>>> psth, psth_t = utils.PSTH(spikes, d_t=dt, window=20e-3, shift=10e-3).compute()
>>> tt, spikes = utils.generate_spike_from_psth(dt, psth, psth_t)
>>> plot.plot_spikes(spikes, t=tt)
olftrans.utils.generate_stimulus(mode, d_t, duration, support, amplitude, sigma=None, dtype=<class 'numpy.float64'>, **kwargs)[source]

Stimuli generator

Parameters
  • mode (str) – shape of the waveform.

  • d_t (float) – the sampling interval for the stimuli.

  • duration (float) – the duration of the stimuli.

  • support (Iterable[float]) – two time points at which the stimulus [start, end). It’s not inclusive of the end.

  • (float o (amplitude) – the amplitudes of the stimuli.

  • amplitude (Union[float, Iterable[float]]) –

  • sigma (Optional[float]) –

  • dtype (numpy.dtype) –

Keyword Arguments
  • sigma – variance of zero-mean Gaussian noise added to the waveform.

  • dtype – data type of the return array

Returns

generate stimulus of shape (NTime, NTrial)

Return type

numpy.ndarray

Module contents

Top-level package for OlfTrans.