Skip to main content

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)

Release files for thunderhopper 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thunderhopper 1.0.1
File Size Uploaded
thunderhopper-1.0.1.tar.gz 175.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for thunderhopper 1.0.1
File Interpreter ABI Platform
thunderhopper-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 345.6 kB

Release files / thunderhopper-1.0.1.tar.gz

Download URL thunderhopper-1.0.1.tar.gz
Size 175.8 kB
Tags Source
SHA-256 checksum
How to use checksums
029d5d95f903d57fac3e0823d83e996a731021fc893914092d52da5df2ff2198
BLAKE2b-256 checksum
How to use checksums
73ae28dfea0381fddecae39825ee5f3ad8c2edd011d5dab309b4492025f4b09c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / thunderhopper-1.0.1-py3-none-any.whl

Download URL thunderhopper-1.0.1-py3-none-any.whl
Size 169.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78db16818eb4ad6b1ea18783b9b74a7f0ade786be1fe0c8ab08fde7e8918af44
BLAKE2b-256 checksum
How to use checksums
01f445c959eb9ed2126630d1854dabf7109ae285e3ea4f8aa5cf288a8d9254e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page