Custom Frequency Scale#
- class osekit.core_api.frequency_scale.Scale(parts: list[ScalePart])#
Class that represent a custom frequency scale for plotting spectrograms.
The custom scale is formed from a list of
ScaleParts, which assign a frequency range to a range on the scale. ProvidedScalePartsshould cover the whole scale (from0%to100%).Such
Scalecan then be passed to theSpectroData.plot()method for the spectrogram to be plotted on a custom frequency scale.Initialize a
Scaleobject.- classmethod from_dict_value(dict_value: list[list]) Scale#
Deserialize a
Scalefrom a dictionary entry.
- get_mapped_indexes(original_scale: list[float]) list[int]#
Return the indexes of the present scale in the original scale.
The indexes are those of the closest value from the mapped values in the original scale.
Parameters#
- original_scale: list[float]
Original scale from which the mapped scale is computed.
Returns#
- list[int]
Indexes of the closest value from the mapped values in the original scale.
- get_mapped_values(original_scale: list[float]) list[float]#
Return the closest values of the mapped scale from the original scale.
Parameters#
- original_scale: list[float]
Original scale from which the mapped scale is computed.
Returns#
- list[float]
Values from the original scale that are the closest to the mapped scale.
- map(original_scale_length: int) list[float]#
Map a given scale to the custom scale defined by its
ScaleParts.Parameters#
- original_scale_length: int
Length of the original frequency scale.
Returns#
- list[float]
Mapped frequency scale. Each
ScalePartfrom theScale.partsattribute are concatenated to form the returned scale.
- rescale(sx_matrix: ndarray, original_scale: ndarray | list) ndarray#
Rescale the given spectrum matrix according to the present scale.
Parameters#
- sx_matrix: np.ndarray
Spectrum matrix.
- original_scale: np.ndarray
Original frequency axis of the spectrum matrix.
Returns#
- np.ndarray
Spectrum matrix mapped on the present scale.
- to_dict_value() list[tuple[float, float, float, float, str]]#
Serialize a
Scaleto a dictionary entry.
- class osekit.core_api.frequency_scale.ScalePart(p_min: float, p_max: float, f_min: float, f_max: float, scale_type: Literal['lin', 'log'] = 'lin')#
Represent a part of the frequency scale of a spectrogram.
- p_min: float
Relative position of the bottom of the scale part on the full scale. Must be in the interval
[0.0, 1.0], where0.0is the bottom of the scale and1.0is the top.- p_max: float
Relative position of the top of the scale part on the full scale. Must be in the interval
[0.0, 1.0], where0.0is the bottom of the scale and1.0is the top.- f_min: float
Frequency corresponding to the bottom of the scale part.
- f_max: float
Frequency corresponding to the top of the scale part.
- scale_type: Literal[βlinβ, βlogβ]
Type of the scale, either linear or logarithmic.
- get_frequencies(nb_points: int) list[int]#
Return the frequency points of the present scale part.
- get_indexes(scale_length: int) tuple[int, int]#
Return the indexes of the present scale part in the full scale.
- get_values(scale_length: int) list[int]#
Return the values of the present scale part.
- property scale_lambda: callable#
Lambda function used to generate either a linear or logarithmic scale.
- to_dict_value() tuple[float, float, float, float, str]#
Serialize a ScalePart to a dictionary entry.