Skip to content

ENH: Store Annotation data in consistent format #259

@sammlapp

Description

@sammlapp

Is your feature request related to a problem? Please describe.
I find it confusing that the base class for all annotations (Annotation) stores data in different ways for "sequence" and "bounding box" type annotations, since these fundamentally contain similar (overlapping) data types.

Describe the solution you'd like
Annotation class could be refactored to store annotations in a dataframe with columns for time0, time1, freq0, freq1. It would contain methods or properties that allow the user to get either a list of bbox or a sequence/ list of sequences. This would enable all of the current functionality while storing data in a consistent format regardless of the source of the annotation.

class Annotation:
    def __init__(self,df,annotation_file,notated_file):
        self.df = df #columns time0, time1, freq0, freq1 etc
        self.annotation_file=annotation_file
        self.notated_file=notated_file
    
    @classmethod
    def from_bboxes(cls, bboxes,annotation_file,notated_file):
        ...
        return cls(df,annotation_file,notated_file)
    
    @classmethod
    def from_sequences(cls,sequences,annotation_file,notated_file):
        ...
        return cls(df,annotation_file,notated_file)

    @property
    def sequences(self):
        return self._make_sequences_from_df()

    def _make_sequences_from_df(self):
        ...
        return list_of_sequences

    @property
    def bboxes(self):
        return self._make_bboxes_from_df()

    def _make_bboxes_from_df(self):
        ...
        return list_of_bboxes

#example usage with sequences
anns = Annotation.from_sequences(sequences)
anns.sequences # gives list of sequences

#example usage with bboxes
anns = Annotation.from_bboxes(bboxes)
anns.bboxes # gives list of bboxes

Describe alternatives you've considered
Alternatively to storing annotations as a dataframe, Annotation could store a list of BBox objects, and a sequences property could call a method _bbox_to_seq() to convert the list of BBox to a sequence.

Additional context
This vocalpy thread contains discussion of this idea https://forum.vocalpy.org/t/use-of-both-sequence-and-bbox-in-annotation-class/63/6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions