Log2Axis
- class ketos.audio.utils.axis.Log2Axis(bins, bins_per_oct, min_value, label=None)[source]
Logarithmic axis with base 2.
The lower-edge value of bin no. i is calculated from the formula,
x_{i} = 2^{i / m} \cdot x_{0}
where m is the number of bins per octave and x_0 is the lower-edge value of the first bin.
- Args:
- bins: int
Total number of bins
- bins_per_oct: int
Number of bins per octave
- min_value: float
Left edge of first bin
- label: str
Descriptive label. Optional
- Attributes:
- bins: int
Total number of bins
- bins_per_oct: float
Number of bins per octave
- x_min: float
Left edge of first bin
- label: str
Descriptive label
Methods
bin
(x[, truncate, closed_right])Get bin number corresponding to a given value.
low_edge
(b)Get the lower-edge value of a given bin.
resize
(bins)Resize the axis.
ticks_and_labels
([numeric_format, ...])Create ticks and labels for drawing the axis.
- bin(x, truncate=False, closed_right=False)[source]
Get bin number corresponding to a given value.
By default bins are closed on the left and open on the right, i.e., [a,b). Use the argument closed_right to reverse this.
If the value lies outside the axis range, a negative bin number or a bin number above N-1 will be returned. This behaviour can be changed using the argument ‘truncate’.
- Args:
- x: array-like
Value
- truncate: bool
Return 0 if x is below the lower axis boundary and N-1 if x is above the upper boundary. Default is False.
- closed_right: bool
If False, bin is closed on the left and open on the right. If True, bin is open on the left and closed on the right. Default is False.
- Returns:
- b: array-like
Bin number
- Example:
>>> from ketos.audio.utils.axis import Log2Axis >>> ax = Log2Axis(bins=4*8, bins_per_oct=8, min_value=200.) >>> ax.bin([400.,800.]) array([ 8, 16])
- low_edge(b)[source]
Get the lower-edge value of a given bin.
- Args:
- b: array-like
Bin number.
- Returns:
- x: array-like
Lower-edge bin value
- Example:
>>> from ketos.audio.utils.axis import Log2Axis >>> ax = Log2Axis(bins=4*8, bins_per_oct=8, min_value=200.) >>> ax.low_edge([0,16]) array([200., 800.])
- resize(bins)[source]
Resize the axis.
This operation changes the number of bins, but preserves the axis range.
Note: may result in an axis with a non-integer bins_per_oct attribute
- Args:
- bins: int
Number of bins
- ticks_and_labels(numeric_format='.1f', num_labels=None, step=None, step_bins=-1, ticks=None)[source]
Create ticks and labels for drawing the axis.
The label density can be specified in three different ways: using the num_labels argument, the step argument, or the step_bins argument.
- Args:
- numeric_format: str
Numeric format for labels.
- num_labels: int
Number of labels
- step: float
Distance between consecutive labels.
- step_bins: int
Number of bins between consecutive labels.
- ticks: array-like
Specify tick positions manually. In this case, the method simply returns copies of the input array, in float and string formats.
- Returns:
- ticks: numpy.array
Tick positions
- labels: list(str)
Labels