pykanto.app.data#

Code to generate embeddable data to be used in the interactive song labelling web application.

Functions

embeddable_image(data[, invert, background])

Save a base 64 png from a np.ndarray.

load_app_data(dataset, datatype, ID)

Load saved data source to use in interactive labelling app.

prepare_datasource(dataset, ID[, ...])

Prepare and save data source for the interactibe labelling application.

prepare_datasource_parallel(dataset[, ...])

Prepare and save data sources for the interactibe labelling application (parallel).

pykanto.app.data.embeddable_image(data: numpy.ndarray, invert: bool = False, background: int = 41) str[source]#

Save a base 64 png from a np.ndarray. Source: Leland McInnes, 2018.

Parameters
  • data (np.ndarray) – Image to embed.

  • invert (bool, optional) – Whether to invert image. Defaults to True.

  • background (int, optional) – RGB grey value. Defaults to 41 (same as app).

Returns

A decoded png image.

Return type

str

pykanto.app.data.prepare_datasource(dataset: KantoData, ID: str, spec_length: int = 500, song_level: bool = False) Tuple[str, Path][source]#

Prepare and save data source for the interactibe labelling application.

Parameters
  • dataset (KantoData) – Source dataset.

  • ID (str) – ID to process.

  • spec_length (int, optional) – Desired spectrogram lenght, in frames. Defaults to 500.

  • song_level (bool, optional) – Whether to use all units per vocalisation or their average. Defaults to False.

Returns

A tuple with ID and path to saved data source.

Return type

Tuple[str, Path]

pykanto.app.data.prepare_datasource_parallel(dataset: KantoData, spec_length: float | None = None, song_level: bool = False, num_cpus: float | None = None) List[List[Tuple[str, Path]]][source]#

Prepare and save data sources for the interactibe labelling application (parallel).

Parameters
  • dataset (KantoData) – Source dataset.

  • spec_length (float | None, optional) – . Defaults to None.

  • song_level (bool, optional) – _description_. Defaults to False.

  • num_cpus (float | None, optional) – N cpus to use. Defaults to None.

  • dataset – Source dataset.

  • spec_length – Desired spectrogram lenght, in frames. Defaults to 500.

  • song_level – Whether to use all units per vocalisation or their average. Defaults to False.

  • num_cpus – N cpus to use. Defaults to None.

Returns

A list of lists of tuples

with ID and path to saved data source.

Return type

List[List[Tuple[str, Path]]]

pykanto.app.data.load_app_data(dataset: KantoData, datatype: str, ID: str) ColumnDataSource[source]#

Load saved data source to use in interactive labelling app.

Parameters
  • dataset (KantoData) – Source dataset.

  • datatype (str) – Type of data to use (one of ‘voc_app_data’, ‘unit_app_data’)

  • ID (str) – ID to process.

Returns

Data ready to plot.

Return type

ColumnDataSource