Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Subscriptable 'Frequencies' class#265

Open
TKosir wants to merge 2 commits into
python-acoustics:masterfrom
TKosir:master
Open

Subscriptable 'Frequencies' class#265
TKosir wants to merge 2 commits into
python-acoustics:masterfrom
TKosir:master

Conversation

@TKosir
Copy link
Copy Markdown

@TKosir TKosir commented Dec 4, 2023

Greetings,

First of all, thank you for this great package!

The other day I needed to calculate sound pressure levels in specific frequency regions. I wanted to use the Signal.bandpass_frequencies method which needs Frequencies class as input frequencies. The code I used is the following:

import numpy as np
import matplotlib.pyplot as plt

sample_rate = 44100
signal = np.random.randn(10000)
s = Signal(signal, sample_rate)

freq_bands = np.array([[100, 200], [200, 400], [800, 1600], [3200, 6400]])
frequencies = Frequencies(center=freq_bands.mean(axis=1), lower=freq_bands[:, 0], upper=freq_bands[:, 1])

f, o = s.bandpass_frequencies(frequencies=frequencies)
Lp = o.leq()
fig, ax = plt.subplots()
ax.plot(f.center, Lp, ".-")

However, when using the following code, I get "TypeError: 'Frequencies' object is not subscriptable". I want to therefore propose a small change for the base Frequencies class by adding __getitem__ method, like in other child frequencies classes to resolve this issue and make Frequencies class usable also as stand alone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant