clarity.utils.audiogram module

Dataclass to represent a monaural audiogram

class clarity.utils.audiogram.Audiogram(levels: ~numpy.ndarray, frequencies: ~numpy.ndarray = <factory>)[source]

Bases: object

Dataclass to represent an audiogram.

levels

The audiometric levels in dB HL

Type:

ndarray

frequencies

The frequencies at which the levels are measured

Type:

ndarray

frequencies: ndarray
has_frequencies(frequencies: ndarray) bool[source]

Check if the audiogram has the given frequencies.

Parameters:

frequencies (ndarray) – The frequencies to check

Returns:

True if the audiogram has the given frequencies

Return type:

bool

levels: ndarray
resample(new_frequencies: ndarray, linear_frequency: bool = False) Audiogram[source]

Resample the audiogram to a new set of frequencies.

Interpolates linearly on a (by default) log frequency axis. If linear_frequencies is set True then interpolation is done on a linear frequency axis.

Parameters:

new_frequencies (ndarray) – The new frequencies to resample to

Returns:

New audiogram with resampled frequencies

Return type:

Audiogram

property severity: str

Categorise HL severity level for the audiogram.

Note that this categorisation is different from that of the British Society of Audiology, which recommends descriptors mild, moderate, severe and profound for average hearing threshold levels at 250, 500, 1000, 2000 and 4000 Hz of 21-40 dB HL, 41-70 dB HL, 71-95 dB HL and > 95 dB HL, respectively (BSA Pure-tone air-conduction and bone-conduction threshold audiometry with and without masking 2018).

Returns:

str – severity level, one of SEVERE, MODERATE, MILD, NOTHING

class clarity.utils.audiogram.Listener(audiogram_left: Audiogram, audiogram_right: Audiogram, id: str = '')[source]

Bases: object

Dataclass to represent a Listener.

The listener is currently defined by their left and right ear audiogram. In later versions, this may be extended to include further audiometric data.

The class provides methods for reading metadata files which will also include some basic validation.

id

The ID of the listener

Type:

str

audiogram_left

The audiogram for the left ear

Type:

Audiogram

audiogram_right

The audiogram for the right ear

Type:

Audiogram

audiogram_left: Audiogram
audiogram_right: Audiogram
static from_dict(listener_dict: dict) Listener[source]

Create a Listener from a dict.

The dict structure and fields are based on those used in the Clarity metadata files.

Parameters:

listener_dict (dict) – The listener dict

Returns:

The listener

Return type:

Listener

id: str = ''
static load_listener_dict(filename: Path) dict[str, Listener][source]

Read a Clarity Listener dict file.

The standard Clarity metadata files presents listeners as a dictionary of listeners, keyed by listener ID.

Parameters:

filename (Path) – The path to the listener dict file

Returns:

A dict of listeners keyed by id

Return type:

dict[str, Listener]