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
2 changes: 1 addition & 1 deletion src/post_processing/dataclass/data_aplose.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def filter_df(
msg = f'Label "{lbl}" not in APLOSE DataFrame'
raise ValueError(msg)
if self.df[
(self.df["is_box"] == 0)
(self.df["type"] == "WEAK")
& (self.df["annotator"] == ant)
& (self.df["annotation"] == lbl)
].empty:
Expand Down
23 changes: 16 additions & 7 deletions src/post_processing/utils/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from astral.sun import sunrise, sunset
from matplotlib import pyplot as plt
from osekit.config import TIMESTAMP_FORMAT_AUDIO_FILE
from osekit.utils.timestamp_utils import strptime_from_text
from osekit.utils.timestamp_utils import strptime_from_text, strftime_osmose_format
from pandas import (
DataFrame,
DatetimeIndex,
Expand Down Expand Up @@ -213,7 +213,10 @@ def add_weak_detection(
if not max_freq:
max_freq = get_max_freq(df)
if not max_time:
max_time = get_max_time(df)
max_time = Timedelta(get_max_time(df), "s")

df["start_datetime"] = [strftime_osmose_format(start) for start in df["start_datetime"]]
df["end_datetime"] = [strftime_osmose_format(stop) for stop in df["end_datetime"]]

for ant in annotators:
for lbl in labels:
Expand All @@ -223,30 +226,36 @@ def add_weak_detection(
.tolist()
)
for f in filenames:
test = df[(df["filename"] == f) & (df["annotation"] == lbl)]["is_box"]
test = df[(df["filename"] == f) & (df["annotation"] == lbl)]["type"]
if test.any():
start_datetime = strptime_from_text(
text=f,
datetime_template=datetime_format,
).tz_localize(tz)
)

if not start_datetime.tz:
start_datetime = tz.localize(start_datetime)

end_datetime = start_datetime + Timedelta(max_time, unit="s")
new_line = [
dataset_id,
f,
0,
max_time,
max_time.total_seconds(),
0,
max_freq,
lbl,
ant,
start_datetime,
end_datetime,
strftime_osmose_format(start_datetime),
strftime_osmose_format(end_datetime),
0,
]

if "score" in df.columns:
new_line.append(np.nan)
df.loc[df.index.max() + 1] = new_line


return df.sort_values(by=["start_datetime", "annotator"]).reset_index(drop=True)


Expand Down
10 changes: 8 additions & 2 deletions src/post_processing/utils/filtering_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ def filter_by_time(

def filter_by_annotator(
df: DataFrame,
annotator: str | list[str],
annotator: str | list[str] | None,
) -> DataFrame:
"""Filter a DataFrame based on annotator selection."""
if annotator is None:
return df

list_annotators = get_annotators(df)

if isinstance(annotator, str):
Expand All @@ -94,9 +97,12 @@ def filter_by_annotator(

def filter_by_label(
df: DataFrame,
label: str | list[str],
label: str | list[str] | None,
) -> DataFrame:
"""Filter a DataFrame based on label selection."""
if label is None:
return df

list_labels = get_labels(df)

if isinstance(label, str):
Expand Down
Loading