vak.common.annotation.from_df#

vak.common.annotation.from_df(dataset_df: DataFrame, annot_root: str | Path | None = None) list[Annotation] | None[source]#

Get list of annotations from a dataframe representing a dataset.

If no annotation format is specified for the dataframe (in the ‘annot_format’ column), returns None.

Parameters:
  • dataset_df (DataFrame) – Dataframe representing a dataset of vocalizations, with columns ‘annot_format’ and ‘annot_path’.

  • annot_root (str or pathlib.Path, optional) – Path to root of directory where annotation files are located. If specified, then paths in the DataFrame from the ‘annot_path’ column are constructed relative to annot_root. Default is None, in which case ‘annot_paths’ are used directly, as if they were absolute paths.

Returns:

annots – of annotations for each row in the dataframe, represented as crowsetta.Annotation instances.

Return type:

list

Notes

This function encapsulates logic for handling different types of annotations; it determines whether each row has a separate annotation file, or if instead there is a single annotation file associated with all rows. If the latter, then the function opens that file and makes sure that each row from the dataframe can be paired with an annotation (using vak.annotation.map_annotated_to_annot()). If instead there is a unique annotation file per row in the dataframe, the format of the annotation files is determined with vak.annotation.format_from_df() and then each file is opened with :module:`crowsetta` – in other words, we assume the mapping was already done when preparing the dataset, and that each row contains an annotation file paired with the file it annotates.