cochlea: inner ear models in Python


In [1]:
%matplotlib inline

In [2]:
from __future__ import division, print_function, absolute_import

import numpy as np
import scipy.signal as dsp
import pandas as pd
import matplotlib.pyplot as plt

import cochlea
import cochlea.stats
import thorns as th
import thorns.waves as wv

Generate a Tone


In [3]:
fs = 100e3
cf = 1000
tone = wv.ramped_tone(
    fs=fs,
    freq=1000,
    duration=0.1,
    dbspl=50
)

wv.plot_signal(tone, fs)


Out[3]:
<matplotlib.axes.AxesSubplot at 0x7f2ddd6d5090>

Run the model (responses of 200 cat HSR fibers)


In [4]:
anf_trains = cochlea.run_zilany2014(
    tone,
    fs,
    anf_num=(200,0,0),
    cf=cf,
    seed=0,
    species='cat'
)

In [5]:
th.plot_raster(anf_trains)


Out[5]:
<matplotlib.axes.AxesSubplot at 0x7f2ddd0da850>

Chirp


In [6]:
t = np.arange(0, 0.05, 1/fs)
chirp = dsp.chirp(t, 80, t[-1], 8000)
chirp = cochlea.set_dbspl(chirp, 50)

wv.plot_signal(chirp, fs)


Out[6]:
<matplotlib.axes.AxesSubplot at 0x7f2ddcb876d0>

Run Human Ear Model (100 frequency channels, 20 LSR fiber per channel)


In [7]:
anf_trains = cochlea.run_zilany2014(
    chirp,
    fs,
    anf_num=(0,0,50),
    cf=(125, 10e3, 100),
    seed=0,
    species='human'
)

In [8]:
th.plot_raster(th.accumulate(anf_trains))


Out[8]:
<matplotlib.axes.AxesSubplot at 0x7f2ddcabbd90>

Rate-Level Function


In [9]:
rates = cochlea.stats.calc_rate_intensity(
        model=cochlea.run_zilany2014,
        cf=1000,
        model_pars={'fs': 100e3, 'species': 'human'}
)


_run_model             [OOOOOOOOOOOOOOOOOOOO]  22/0/0  0:00:00.125618

In [10]:
rates.plot()


Out[10]:
<matplotlib.axes.AxesSubplot at 0x7f2ddc77b2d0>