mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-01-10 17:19:34 +01:00
Avoid empty strings as tags in legacy format conversion
This commit is contained in:
parent
efc996a0db
commit
6039b2c3eb
@ -88,14 +88,35 @@ def annotation_to_sound_event(
|
|||||||
return data.SoundEventAnnotation(
|
return data.SoundEventAnnotation(
|
||||||
uuid=uuid.uuid5(NAMESPACE, f"{sound_event.uuid}_annotation"),
|
uuid=uuid.uuid5(NAMESPACE, f"{sound_event.uuid}_annotation"),
|
||||||
sound_event=sound_event,
|
sound_event=sound_event,
|
||||||
tags=[
|
tags=get_sound_event_tags(
|
||||||
data.Tag(key=label_key, value=annotation.label),
|
annotation, label_key, event_key, individual_key
|
||||||
data.Tag(key=event_key, value=annotation.event),
|
),
|
||||||
data.Tag(key=individual_key, value=str(annotation.individual)),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_sound_event_tags(
|
||||||
|
annotation: Annotation,
|
||||||
|
label_key: str = "class",
|
||||||
|
event_key: str = "event",
|
||||||
|
individual_key: str = "individual",
|
||||||
|
) -> List[data.Tag]:
|
||||||
|
"""Get the tags for a sound event annotation."""
|
||||||
|
tags = []
|
||||||
|
|
||||||
|
if annotation.label:
|
||||||
|
tags.append(data.Tag(key=label_key, value=annotation.label))
|
||||||
|
|
||||||
|
if annotation.event:
|
||||||
|
tags.append(data.Tag(key=event_key, value=annotation.event))
|
||||||
|
|
||||||
|
if annotation.individual:
|
||||||
|
tags.append(
|
||||||
|
data.Tag(key=individual_key, value=str(annotation.individual))
|
||||||
|
)
|
||||||
|
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def file_annotation_to_clip(
|
def file_annotation_to_clip(
|
||||||
file_annotation: FileAnnotation,
|
file_annotation: FileAnnotation,
|
||||||
audio_dir: Optional[PathLike] = None,
|
audio_dir: Optional[PathLike] = None,
|
||||||
@ -109,10 +130,14 @@ def file_annotation_to_clip(
|
|||||||
if not full_path.exists():
|
if not full_path.exists():
|
||||||
raise FileNotFoundError(f"File {full_path} not found.")
|
raise FileNotFoundError(f"File {full_path} not found.")
|
||||||
|
|
||||||
|
tags = []
|
||||||
|
if file_annotation.label:
|
||||||
|
tags.append(data.Tag(key=label_key, value=file_annotation.label))
|
||||||
|
|
||||||
recording = data.Recording.from_file(
|
recording = data.Recording.from_file(
|
||||||
full_path,
|
full_path,
|
||||||
time_expansion=file_annotation.time_exp,
|
time_expansion=file_annotation.time_exp,
|
||||||
tags=[data.Tag(key=label_key, value=file_annotation.label)],
|
tags=tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
return data.Clip(
|
return data.Clip(
|
||||||
@ -135,11 +160,15 @@ def file_annotation_to_clip_annotation(
|
|||||||
if file_annotation.notes:
|
if file_annotation.notes:
|
||||||
notes.append(data.Note(message=file_annotation.notes))
|
notes.append(data.Note(message=file_annotation.notes))
|
||||||
|
|
||||||
|
tags = []
|
||||||
|
if file_annotation.label:
|
||||||
|
tags.append(data.Tag(key=label_key, value=file_annotation.label))
|
||||||
|
|
||||||
return data.ClipAnnotation(
|
return data.ClipAnnotation(
|
||||||
uuid=uuid.uuid5(NAMESPACE, f"{file_annotation.id}_clip_annotation"),
|
uuid=uuid.uuid5(NAMESPACE, f"{file_annotation.id}_clip_annotation"),
|
||||||
clip=clip,
|
clip=clip,
|
||||||
notes=notes,
|
notes=notes,
|
||||||
tags=[data.Tag(key=label_key, value=file_annotation.label)],
|
tags=tags,
|
||||||
sound_events=[
|
sound_events=[
|
||||||
annotation_to_sound_event(
|
annotation_to_sound_event(
|
||||||
annotation,
|
annotation,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user