Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/osekit/core_api/spectro_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,14 @@ def link_audio_dataset(
first: int = 0,
last: int | None = None,
) -> None:
"""Link the ``SpectroData`` of the ``SpectroDataset`` to the ``AudioData`` of the ``AudioDataset``.
"""Link the ``SpectroDataset`` to the ``AudioDataset``.

The ``SpectroData`` of the ``SpectroDataset`` will be linked to
the ``AudioData`` of the ``AudioDataset``.

There should be in the ``AudioDataset`` an ``AudioData`` that
have the same ``begin`` and ``end`` than each of the ``SpectroData``
of the ``SpectroDataset``.

Parameters
----------
Expand All @@ -388,23 +395,16 @@ def link_audio_dataset(
Index of the last ``SpectroData`` and ``AudioData`` to link.

"""
if len(audio_dataset.data) != len(self.data):
msg = (
"The audio dataset doesn't contain the same number of data"
" as the spectro dataset."
)
raise ValueError(msg)

last = len(self.data) if last is None else last

for sd, ad in list(
zip(
sorted(self.data, key=lambda d: (d.begin, d.end)),
sorted(audio_dataset.data, key=lambda d: (d.begin, d.end)),
strict=False,
),
)[first:last]:
sd.link_audio_data(ad)
ad_dict = {(ad.begin, ad.end): ad for ad in audio_dataset.data}

for sd in self.data[first:last]:
key = (sd.begin, sd.end)
if key not in ad_dict:
msg = f"No AudioData found for SpectroData {sd}"
raise ValueError(msg)
sd.link_audio_data(ad_dict[key])

def update_json_audio_data(self, first: int, last: int) -> None:
"""Update the serialized ``json`` file with the spectro data from first to last.
Expand Down
Loading