Skip to main content

Model of the auditory pathway of grasshoppers.

Project description

license PyPI version downloads contributors commits

ThunderHopper

Model of the auditory pathway of grasshoppers.

Documentation | API Reference

Auditory pathway

Acoustic signals are sequentially processed along the auditory pathway:

  1. Raw auditory signal (raw).
  2. Bandpass filterd by tympanum (filt).
  3. Computation of envelope by rectification and low-pass filtering (env).
  4. Logarithmic transform into decibel (log).
  5. High-pass filtering to generate intensity invariant envelope (inv).
  6. Convolution of the envelope with a set of Gabor kerneles (conv).
  7. Thresholding the convolved traces (bi).
  8. Low-pass filtering the binary trace to generate slowly varying features (feat).

In brackets the acronyms are given that are used by output dictionaries and for signal selection as described below.

Usage

First, import what we need:

import numpy as np
import matplotlib.pyplot as plt
from thunderhopper import configuration, process_signal, load_data

Second, prepare a configuration dictionary. You simply need to provide the standard deviations of the Garbor kernels and their types. The latter is the number of lobes you want, a negative number flips the kernel on the x-axis:

sigmas = [0.001, 0.002, 0.004, 0.008, 0.016, 0.032]
types = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5,
         6, -6, 7, -7, 8, -8, 9, -9, 10, -10]
config = configuration(types=types, sigmas=sigmas)

Then just run the model on an audio recording:

data, rates = process_signal(config, path='recording.wav')

That's it!

Both, data and rates are dictionaries with the same keys. data contains the time series and rates the corresponding sampling rates. To plot the filtered signal and the envelope of the first channel just run

filt = data['filt'][:, 0]
filt_rate = rates['filt']
tfilt = np.arange(len(filt))/filt_rate

env = data['env'][:, 0]
env_rate = rates['env']
tenv = np.arange(len(env))/env_rate

plt.plot(tfilt, filt)
plt.plot(tenv, env)
plt.show()

Save model traces in file

You can also save all computed traces in a numpy npz file. Just pass a file path to the save argument:

process_signal(config, path=data_path, save='recording.npz')

Now, all the computed traces are saved in this file.

Load this file like this:

data, params = load_data('recording.npz', ['filt', 'env'])
filt_rate = params['rate']
env_rate = params['env_rate']

The second argument requests only the filtered signal and the envelope to be loaded from the file. When not specified, all traces are loaded.

Configuration parameters

After calling configuration(), you may change some of the parameters of the model.

For example, you can set individual thresholds for each feature by loading them from a file and change the low-pass filter's cutoff frequency that generates the features:

config.update({
    'feat_thresh': np.load('acrididae.npy') * 0.1,
    'feat_fcut': 0.75,
    })

Or run the song detection on a specific input channel with a specific threshold:

config.update({
    'label_channels': 0,
    'label_thresh': 0.5
    })

Select what to store

If you do not need the traces from every step of the auditory pathway, you may select what to store via the returns argument. For example, if you are only interested in the features, the norm of the features and the song labels, call process_signal() like this:

returns = ['feat', 'norm', 'songs']
data, rates = process_signal(config, path='recording.wav', returns=returns)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thunderhopper-1.0.0.tar.gz (175.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thunderhopper-1.0.0-py3-none-any.whl (169.8 kB view details)

Uploaded Python 3

File details

Details for the file thunderhopper-1.0.0.tar.gz.

File metadata

  • Download URL: thunderhopper-1.0.0.tar.gz
  • Upload date:
  • Size: 175.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for thunderhopper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c5443d9166bbe8f47f6d6d62d0e2dc461666ee8262baeda21b59667e7462e0fc
MD5 66a10dc14f2f59c2265560e87915dd6b
BLAKE2b-256 a1d572fe30e923941fa41fd03fa594c642f55b4b210da84bda755ec82131e7b4

See more details on using hashes here.

File details

Details for the file thunderhopper-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: thunderhopper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 169.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for thunderhopper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42246d81b76db75fb1e7ae206e9944280ad367eadd692ae8b51bcc20fef6ccf9
MD5 6bbea60353a3fa1f9d435b3615d5c7f1
BLAKE2b-256 be066ab29c7c175b3a5d3e4adc5c5b8a2c381300a68cf7bf42b5437dd8fc8a57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page