<jupyter_start><jupyter_text>ANTcircuits example<jupyter_code>%load_ext autoreload
%autoreload 2
from eoscircuits import ant
import olftrans as olf
import olftrans.data
import olftrans.fbl
import numpy as np
import networkx as nx
from neurokernel.LPU.InputProcessors.StepInputProcessor import StepInputProcessor
import matplotlib.pyplot as plt
import typing as tp
import pandas as pd
import seaborn as sns
from eoscircuits.plot import plot_data, plot_spikes<jupyter_output><empty_output><jupyter_text>Load Larva Affinity Values<jupyter_code>receptor_names = olf.fbl.LARVA.affinities.loc['ethyl acetate'].index.values.astype(str)
affinities = olf.fbl.LARVA.affinities.loc['ethyl acetate'].values
%matplotlib inline
plt.figure(figsize=(10,10))
sns.heatmap(olf.fbl.LARVA.affinities, annot=True, fmt='.2f')
cfg = ant.ANTConfig(NO=2, affs=affinities, receptors=receptor_names, node_params={'osn_bsgs':{'sigma': 0.0025}})
ant_circ = ant.ANTCircuit.create_from_config(cfg)
dt = 1e-5
dur = 4
steps = int((dur+dt/2)//dt)
t = np.arange(steps)*dt
fi = StepInputProcessor('conc', ant_circ.inputs['conc'], 100., start=1, stop=3)
fi, fo, lpu = ant_circ.simulate(
    t, fi, 
    record_var_list=[
        ('I', sum(ant_circ.config.osn_otps, [])),
        ('spike_state', sum(ant_circ.config.osn_bsgs, []))
    ]
)
%matplotlib inline
I = fo.get_output(var='I')
spike_times = fo.get_output(var='spike_state')

fig,axes = plt.subplots(1,3, figsize=(15,5), gridspec_kw={'width_ratios': [1,10,10]})
_ = plot_data(I, t=t, ax=axes[1], cmap=plt.cm.gnuplot, cax=True, cbar_kw={'label': 'I [$\mu A$]'})
_ = plot_spikes(spike_times, ax=axes[2], markersize=8)
_ = axes[2].set_xlim([0, t.max()])

axes[0].imshow(np.log10(ant_circ.config.affs)[:,None], cmap=plt.cm.gnuplot, origin='lower')
axes[0].set_xticks([])
axes[0].set_yticks(np.arange(ant_circ.config.NR))
axes[0].set_yticklabels(ant_circ.config.receptors)
axes[0].set_title('$\mathbf{b}_o$')
axes[1].set_ylabel('OSN Index')
axes[1].set_xlabel('Time [sec]')
axes[1].set_title('OTP Current')
axes[2].set_title('BSG Spikes')
axes[2].set_xlabel('Time [sec]')
axes[2].grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Change Affinity Values<jupyter_code>ant_circ.set_affinities([.1,.5], receptors=['30a', '42a'])
fi = StepInputProcessor('conc', ant_circ.inputs['conc'], 100., start=1, stop=3)
fi, fo, lpu = ant_circ.simulate(
    t, fi, 
    record_var_list=[
        ('I', sum(ant_circ.config.osn_otps, [])),
        ('spike_state', sum(ant_circ.config.osn_bsgs, []))
    ])
%matplotlib inline
I = fo.get_output(var='I')
spike_times = fo.get_output(var='spike_state')
fig,axes = plt.subplots(1,3, figsize=(15,5), gridspec_kw={'width_ratios': [1,10,10]})
_ = plot_data(I, ax=axes[1], cmap=plt.cm.gnuplot, cax=True, cbar_kw={'label': 'I [$\mu A$]'})
_ = plot_spikes(spike_times, ax=axes[2], markersize=8)
_ = axes[2].set_xlim([0, t.max()])

axes[0].imshow(np.log10(ant_circ.config.affs)[:,None], cmap=plt.cm.gnuplot, origin='lower')
axes[0].set_yticks(np.arange(ant_circ.config.NR))
axes[0].set_yticklabels(ant_circ.config.receptors)
axes[0].set_xticks([])
axes[0].set_title('$\log_{10} \mathbf{b}_o$')
axes[1].set_ylabel('OSN Index')
axes[1].set_xlabel('Time [sec]')
axes[1].set_title('OTP Current')
axes[2].set_title('BSG Spikes')
axes[2].set_xlabel('Time [sec]')
axes[2].grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Change BSG params<jupyter_code>ant_circ.set_bsg_params('sigma', 0.)
fi = StepInputProcessor('conc', ant_circ.inputs['conc'], 100., start=1, stop=3)
fi, fo, lpu = ant_circ.simulate(
    t, fi, 
    record_var_list=[
        ('I', sum(ant_circ.config.osn_otps, [])),
        ('spike_state', sum(ant_circ.config.osn_bsgs, []))
    ])
%matplotlib inline
I = fo.get_output(var='I')
spike_times = fo.get_output(var='spike_state')

fig,axes = plt.subplots(1,3, figsize=(15,5), gridspec_kw={'width_ratios': [1,10,10]})
_ = plot_data(I, ax=axes[1], cmap=plt.cm.gnuplot, cax=True, cbar_kw={'label': 'I [$\mu A$]'})
_ = plot_spikes(spike_times, ax=axes[2], markersize=8)
_ = axes[2].set_xlim([0, t.max()])

axes[0].imshow(np.log10(ant_circ.config.affs)[:,None], cmap=plt.cm.gnuplot, origin='lower')
axes[0].set_xticks([])
axes[0].set_yticks(np.arange(ant_circ.config.NR))
axes[0].set_yticklabels(ant_circ.config.receptors)
axes[0].set_title('$\mathbf{b}_o$')
axes[1].set_ylabel('OSN Index')
axes[1].set_xlabel('Time [sec]')
axes[1].set_title('OTP Current')
axes[2].set_title('BSG Spikes')
axes[2].set_xlabel('Time [sec]')
axes[2].grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Change Number of OSNs per Receptor Type<jupyter_code>ant_circ.set_NO(10)
fi = StepInputProcessor('conc', ant_circ.inputs['conc'], 100., start=1, stop=3)
fi, fo, lpu = ant_circ.simulate(
    t, fi, 
    record_var_list=[
        ('I', sum(ant_circ.config.osn_otps, [])),
        ('spike_state', sum(ant_circ.config.osn_bsgs, []))
    ])
%matplotlib inline
I = fo.get_output(var='I')
spike_times = fo.get_output(var='spike_state')

fig,axes = plt.subplots(1,3, figsize=(15,5), gridspec_kw={'width_ratios': [1,10,10]})
_ = plot_data(I, t=t, ax=axes[1], cmap=plt.cm.gnuplot, cax=True, cbar_kw={'label': 'I [$\mu A$]'})
_ = plot_spikes(spike_times, ax=axes[2], markersize=1)
_ = axes[2].set_xlim([0, t.max()])

axes[0].imshow(np.log10(ant_circ.config.affs)[:,None], cmap=plt.cm.gnuplot, origin='lower')
axes[0].set_xticks([])
axes[0].set_yticks(np.arange(ant_circ.config.NR))
axes[0].set_yticklabels(ant_circ.config.receptors)
axes[0].set_title('$\mathbf{b}_o$')
axes[1].set_ylabel('OSN Index')
axes[1].set_xlabel('Time [sec]')
axes[1].set_title('OTP Current')
axes[2].set_title('BSG Spikes')
axes[2].set_xlabel('Time [sec]')
axes[2].grid()
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup