A3EM Package
import a3em_analysis
A3EM provides utilities for preprocessing bioacoustic recordings, extracting acoustic features, and working with supported bioacoustic datasets.
a3em_analysis.utils
preprocess
preprocess(audio, sample_rate, normalization=0.7)
Takes an audio clip as a numpy.ndarray, applies high-pass and low-pass filtering, and normalizes the signal.
Example
import librosa
from a3em_analysis.utils import preprocess
audio_path = "test.wav"
audio, sample_rate = librosa.load(audio_path)
preprocessed_audio = preprocess(audio, sample_rate)
extract_features
extract_features(audio, sample_rate)
Takes an audio clip as a numpy.ndarray and extracts acoustic features from the signal.
Example
import librosa
from a3em_analysis.utils import preprocess, extract_features
audio_path = "test.wav"
audio, sample_rate = librosa.load(audio_path)
preprocessed_audio = preprocess(audio, sample_rate)
features = extract_features(preprocessed_audio, sample_rate)
a3em_analysis.datasets
The a3em_analysis.datasets module provides convenient access to supported A3EM datasets. Dataset classes handle downloading, preprocessing, clip extraction, and feature extraction.
Arden
The Arden dataset contains collar-borne AudioMoth recordings collected in June 2025 in Samburu National Reserve, Kenya.
from a3em_analysis.datasets import Arden
import os
dataset = Arden(
path=os.getenv("DATA_PATH"),
token=os.getenv("API_TOKEN")
)
path specifies where the dataset should be stored locally. token is used to authenticate downloads from Dryad.
The first time data is loaded, the dataset will automatically:
- Check for the required audio and annotation files locally.
- Download the dataset from Dryad if necessary.
- Extract downloaded archives.
- Load and filter annotation metadata.
- Optionally generate background-noise examples.
- Extract audio clips.
- Preprocess the clips.
- Compute acoustic features.
The extracted clips and features are cached on the Arden instance so that subsequent calls do not repeat feature extraction unless reload=True is specified.
load_data
load_data(
random_state=None,
sample_rate=2000,
rumble_only=False,
reload=False
)
Loads the dataset and returns the extracted acoustic features together with their binary labels.
Example
features, labels = dataset.load_data(
random_state=123
)
Parameters
| Parameter | Description |
|---|---|
random_state |
Seed used when shuffling metadata and generating background-noise clips. |
sample_rate |
Sample rate used when loading audio. Defaults to 2000. |
rumble_only |
If True, only annotated elephant rumbles are included. If False, background-noise examples are also generated. |
reload |
If True, regenerates metadata, clips, and features even if they have already been loaded. |
Returns
features : pandas.DataFrame
labels : pandas.Series
Labels are binary:
0— Background noise1— Elephant rumble
Annotation quality values 2, 3, and 4 are mapped to the rumble label 1. Background-noise examples have quality 0 and are mapped to label 0.
load_data_ml
load_data_ml(
test_split=0.2,
random_state=None,
sample_rate=2000,
rumble_only=False,
reload=False,
shuffle=False
)
Loads the dataset and creates train/test splits suitable for machine-learning workflows.
Internally, this method uses sklearn.model_selection.train_test_split.
Example
x_train, x_test, y_train, y_test = dataset.load_data_ml(
test_split=0.2,
random_state=123,
shuffle=True
)
Parameters
| Parameter | Description |
|---|---|
test_split |
Fraction of samples reserved for testing. Defaults to 0.2. |
random_state |
Seed used for dataset generation and the train/test split. |
sample_rate |
Sample rate used when loading audio. Defaults to 2000. |
rumble_only |
If True, only annotated elephant rumbles are included. If False, background-noise examples are also generated. |
reload |
If True, regenerates metadata, clips, and features before splitting. |
shuffle |
Whether samples should be shuffled by train_test_split before creating the split. Defaults to False. |
Returns
x_train : pandas.DataFrame
x_test : pandas.DataFrame
y_train : pandas.Series
y_test : pandas.Series
load_clips
load_clips(
random_state=None,
sample_rate=2000,
rumble_only=False,
reload=False
)
Returns the extracted audio clips together with their computed acoustic features.
Example
clips, features = dataset.load_clips(
random_state=123,
rumble_only=False
)
Parameters
| Parameter | Description |
|---|---|
random_state |
Seed used when generating the dataset. |
sample_rate |
Sample rate used when loading audio. Defaults to 2000. |
rumble_only |
If True, background-noise examples are not generated. |
reload |
If True, regenerates the clips and features. |
Returns
clips— list containing the extracted audio clips as NumPy arrays.features—pandas.DataFramecontaining one row of acoustic features for each clip.
Each extracted clip includes a 0.2 second buffer before and after its annotated time range.
Clips shorter than two seconds after extraction are discarded during feature extraction.
Iteration
An Arden dataset can be iterated over directly.
dataset = Arden(path, token)
for clip, features in dataset:
print(len(clip))
print(features)
If the dataset has not already been loaded, iteration automatically initializes it using the default loading options.
Each iteration returns:
(
numpy.ndarray, # audio clip
dict # extracted acoustic features
)
Indexing
Individual clips and their corresponding features can be accessed by index after the dataset has been loaded.
clip, features = dataset[10]
The returned feature set is converted from its DataFrame row into a dictionary.
If the dataset has not yet been loaded, indexing returns:
(None, None)
Dataset Length
The number of metadata entries currently loaded can be obtained with len():
len(dataset)
Before the dataset has been initialized, its length is 0.
Rumble Filtering
Arden annotations are filtered before clips are extracted.
Only entries satisfying all of the following conditions are retained:
call_typeisRUMorBKGearflapis0or1overlapisNqualityis0,2,3, or4- duration is greater than
2seconds
When rumble_only=True, background-noise examples are not generated.
Background-Noise Generation
When rumble_only=False, background-noise (BKG) examples are automatically generated from regions outside the annotated event ranges.
The duration of generated noise clips is based on the mean and standard deviation of annotation durations in the corresponding recording.
Generated background-noise entries use:
call_type = BKG
quality = 0
overlap = N
earflap = 0
Because background-noise selection is randomized, use random_state when reproducible dataset generation is required.
features, labels = dataset.load_data(
random_state=123
)
Audio Processing
Audio recordings are loaded using librosa at the requested sample rate:
sample_rate=2000
For each retained metadata entry:
- The corresponding time range is extracted from the recording.
- A
0.2second buffer is added to each side. - The clip is passed through
a3em_analysis.utils.preprocess. - Acoustic features are calculated using
a3em_analysis.utils.extract_features.
The original extracted clip and its computed features are retained by the dataset instance.
Reloading Data
Once clips and features have been generated, the Arden instance reuses them.
To force the dataset to regenerate its metadata, clips, and features:
features, labels = dataset.load_data(
reload=True
)
This is useful when changing parameters such as:
sample_rate
rumble_only
random_state
Quick Start
import os
from a3em_analysis.datasets import Arden
dataset = Arden(
path=os.getenv("DATA_PATH"),
token=os.getenv("API_TOKEN")
)
# Load features and labels
features, labels = dataset.load_data(
random_state=123
)
print(features.head())
print(labels.head())
# Create a machine-learning split
x_train, x_test, y_train, y_test = dataset.load_data_ml(
test_split=0.2,
random_state=123,
shuffle=True
)
# Access raw clips and features
clips, clip_features = dataset.load_clips()
# Iterate through clips
for clip, feature_set in dataset:
print(clip.shape)
print(feature_set)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file a3em_analysis-0.0.3.tar.gz.
File metadata
- Download URL: a3em_analysis-0.0.3.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
febb73c580f863350a6faed38cb244c63d8b7eab3b11f83d6e3f77f11e648faf
|
|
| MD5 |
4fb96709467e87a41315de0c766294f2
|
|
| BLAKE2b-256 |
f5fc73a54409a128fb638fa750a3ca654e026564914a43d231412a66c520f1e2
|
File details
Details for the file a3em_analysis-0.0.3-py3-none-any.whl.
File metadata
- Download URL: a3em_analysis-0.0.3-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46306f0cfce9de93b3c3e1c5e01d9aa9fe09305e56da3e4c5c26e8307c07858d
|
|
| MD5 |
830e0638953630c92e2264139e0d4b9a
|
|
| BLAKE2b-256 |
29c35039d977274ee42515766215dc9bd3eaa957ffc161ac4a312f2bcae886fc
|