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.1.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.1-py3-none-any.whl (169.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: thunderhopper-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 029d5d95f903d57fac3e0823d83e996a731021fc893914092d52da5df2ff2198
MD5 9c7f554bf942a3a9a9f0cde04252fb2d
BLAKE2b-256 73ae28dfea0381fddecae39825ee5f3ad8c2edd011d5dab309b4492025f4b09c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thunderhopper-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78db16818eb4ad6b1ea18783b9b74a7f0ade786be1fe0c8ab08fde7e8918af44
MD5 7c104f80ba9c39db9658517e83b9d276
BLAKE2b-256 01f445c959eb9ed2126630d1854dabf7109ae285e3ea4f8aa5cf288a8d9254e0

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