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. Provided ScaleParts should cover the whole scale (from 0% to 100%).
Such Scale can then be passed to the SpectroData.plot() method for the spectrogram to be plotted on a custom frequency scale.
Initialize a Scale object.
- classmethod from_dict_value(dict_value: list[list]) Scale #
Deserialize a Scale from 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 ScalePart from the Scale.parts attribute 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 Scale to 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.
The given part goes from: p_min (in % of the axis), representing f_min to: p_max (in % of the axis), representing f_max
Initialize a ScalePart.
Parameters#
- p_min: float
Position (in percent) of the bottom of the scale part on the full scale.
- p_max: float
Position (in percent) of the top of the scale part on the full scale.
- 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.