Axis

class ketos.audio.utils.axis.Axis(bins, x_min, label)[source]

Base class for all Axis classes.

Child classes must implement the methods _pos_func, bin, low_edge, and resize

Args:
bins: int

Number of bins

x_min: float

Left edge of first bin

label: str

Descriptive label. Optional

Attributes:
bins: int

Number of bins

label: str

Descriptive label.

Methods

bin(x[, truncate, closed_right])

Get bin number corresponding to a given value.

bin_width([b])

Get the width of a given bin.

cut([x_min, x_max, bins])

Cut the axis by specifing either a minimum and a maximum value, or by specifying a minimum value and the axis length (as an integer number of bins).

low_edge(b)

Get the lower-edge value of a given bin.

max()

Get the upper boundary of the axis.

min()

Get the lower boundary of the axis.

resize(bins)

Resize the axis.

ticks_and_labels([numeric_format, ...])

Create ticks and labels for drawing the axis.

up_edge(b)

Get the upper-edge value of a given bin.

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

bin_width(b=0)[source]

Get the width of a given bin.

Args:
b: int

Bin number

Returns:
: float

Bin width

cut(x_min=None, x_max=None, bins=None)[source]

Cut the axis by specifing either a minimum and a maximum value, or by specifying a minimum value and the axis length (as an integer number of bins).

At both ends of the axis, the bins containing the cut values are included.

Args:
x_min: float

Position of lower cut. Defaults to the axis’ lower limit.

x_max: float

Position of upper cut.

bins: int

Cut length, given as a integer number of bins. When bins is specified, the argument x_max is ignored.

Returns:
b_min, b_max: int, int

Lower and upper bin number of the cut

Example:
>>> from ketos.audio.utils.axis import LinearAxis
>>> #Linear axis between 0. and 10. with 20 bins.
>>> ax = LinearAxis(bins=20, extent=(0.,10.))
>>> #Select interval from 5.3 to 8.7
>>> b_min, b_max = ax.cut(x_min=5.3, x_max=8.7)
>>> print(ax.min(), ax.max(), ax.bins, ax.dx)
5.0 9.0 8 0.5
>>> print(b_min, b_max)
10 17
>>> #Select 6-bin long interval with lower cut at 3.2
>>> ax = LinearAxis(bins=20, extent=(0.,10.))
>>> b_min, b_max = ax.cut(x_min=3.2, bins=6)
>>> print(ax.min(), ax.max(), ax.bins, ax.dx)
3.0 6.0 6 0.5
low_edge(b)[source]

Get the lower-edge value of a given bin.

Must be implemented in child class.

Args:
b: array-like

Bin number.

Returns:
x: array-like

Lower-edge bin value

max()[source]

Get the upper boundary of the axis.

Returns:
: float

Upper edge of the last bin

min()[source]

Get the lower boundary of the axis.

Returns:
: float

Lower edge of first bin

resize(bins)[source]

Resize the axis.

This operation changes the number of bins, but preserves the axis range.

Must be implemented in child class.

Args:
bins: int

Number of bins

ticks_and_labels(numeric_format='.1f', num_labels=None, step=None, step_bins=1, ticks=None, significant_figures=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.

significant_figures: int

Number of significant figures for labels.

Returns:
ticks: numpy.array

Tick positions

labels: list(str)

Labels

up_edge(b)[source]

Get the upper-edge value of a given bin.

Args:
b: array-like

Bin number.

Returns:
x: array-like

Upper-edge bin value