Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d090242
add the osekit.core.annotation.Annotation class
Gautzilla May 20, 2026
721525b
add Annotation deserialization from csv
Gautzilla May 27, 2026
425691f
move comments and phase to the AnnotationMetadata class
Gautzilla May 28, 2026
5fe8a61
filter na in annotation read_csv()
Gautzilla Jun 2, 2026
f077bdc
add FrequencyBounds post_init validity check
Gautzilla Jun 2, 2026
a3abd30
add FrequencyBounds tests
Gautzilla Jun 2, 2026
448ce25
parse missing cell values as None
Gautzilla Jun 2, 2026
7ffd859
remove analysis column from result csv
Gautzilla Jun 2, 2026
97935d9
fix docstring parameter name
Gautzilla Jun 2, 2026
34197dc
add AnnotatorInfo hash() method
Gautzilla Jun 2, 2026
521f96e
add AnnotatorInfo hash test
Gautzilla Jun 2, 2026
d4b54ed
add default None value for SignalParameters parameters
Gautzilla Jun 3, 2026
2f8d620
add ConfidenceIndicator level parsing in post_init()
Gautzilla Jun 3, 2026
f69ddef
clarify ConfidenceIndicator parameters
Gautzilla Jun 3, 2026
e8a2976
add ConfidenceIndicator post_init() tests
Gautzilla Jun 3, 2026
d06fffc
add ConfidenceIndicator.from_relative_level_string() test
Gautzilla Jun 3, 2026
a08a1f6
reverse index to the correct row name
Gautzilla Jun 3, 2026
06603da
Merge branch 'main' into annotation
Gautzilla Jun 3, 2026
0826e47
add annotation from csv integration test
Gautzilla Jun 3, 2026
562b2ff
fix relative path to sample csv file in tests
Gautzilla Jun 3, 2026
a9c9efd
add Annotation.to_rectangle() method
Gautzilla Jun 4, 2026
485a414
add None parameter in localize_timestamp
Gautzilla Jun 4, 2026
bea61bd
add Event.localize() method
Gautzilla Jun 4, 2026
e313e85
pass kwargs through Annotation.to_rectangle()
Gautzilla Jun 4, 2026
d11ec1e
make SpetroData.plot() return the Axes on which the spetro has been p…
Gautzilla Jun 4, 2026
7ec8066
add Annotation.__repr__() test
Gautzilla Jun 4, 2026
4897136
add sample Annotation fixture
Gautzilla Jun 8, 2026
bedd7d7
add Annotation.to_rectangle() test
Gautzilla Jun 8, 2026
4566eae
rename AnnotatorInfo fields
Gautzilla Jun 8, 2026
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
409 changes: 409 additions & 0 deletions src/osekit/core/annotation.py

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/osekit/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, TypeVar

from osekit.utils.timestamp import localize_timestamp

if TYPE_CHECKING:
from pandas import Timedelta, Timestamp

Expand Down Expand Up @@ -63,6 +65,23 @@ def __repr__(self) -> str:
"""Overwrite repr."""
return f"{self.begin} - {self.end}"

def localize(self, timezone: str | None) -> None:
"""Localize the event begin and end in a timezone.

If the event is already tz-aware, it will be converted
to the target timezone.

Parameters
----------
timezone: str | None
Target timezone

"""
# We use the private fields here because we can't compare
# naive and aware timestamps in the begin and end setters
self._begin = localize_timestamp(timestamp=self._begin, timezone=timezone)
self._end = localize_timestamp(timestamp=self._end, timezone=timezone)

def overlaps(self, other: type[Event] | Event) -> bool:
"""Return ``True`` if the other event shares time with the current event.

Expand Down
10 changes: 8 additions & 2 deletions src/osekit/core/spectro_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,24 @@ def plot(
ax: plt.Axes | None = None,
sx: np.ndarray | None = None,
scale: Scale | None = None,
) -> None:
) -> plt.Axes:
"""Plot the spectrogram on a specific ``Axes``.

Parameters
----------
ax: plt.axes | None
ax: plt.Axes | None
``Axes`` on which the spectrogram should be plotted.
Defaulted to ``osekit.utils.plot.get_default_axes()``.
sx: np.ndarray | None
Spectrogram ``sx`` values. Will be computed if ``None``.
scale: osekit.core.frequecy_scale.Scale
Custom frequency scale to use for plotting the spectrogram.

Returns
-------
plt.Axes
The ``Axes`` on which the spectrogram has been plotted.

"""
ax = ax if ax is not None else get_default_axes()
sx = self.get_value() if sx is None else sx
Expand All @@ -439,6 +444,7 @@ def plot(
interpolation="none",
extent=(date2num(time[0]), date2num(time[-1]), freq[0], freq[-1]),
)
return ax

def get_db_value(self, sx: np.ndarray | None = None) -> np.ndarray:
"""Return the ``Sx`` spectrum of the spectrogram expressed in ``dB``.
Expand Down
7 changes: 4 additions & 3 deletions src/osekit/utils/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ def normalize_datetime(datetime: tuple[str], template: str) -> tuple[str, str]:

def localize_timestamp(
timestamp: Timestamp,
timezone: str | pytz.timezone,
timezone: str | pytz.timezone | None,
) -> Timestamp:
"""Localize a timestamp in the given timezone.

Parameters
----------
timestamp: pandas.Timestamp
The timestamp to localize.
timezone: str | pytz.timezone
timezone: str | pytz.timezone | None
The timezone in which the timestamp is localized.
If None, the output timestamp is naive.

Returns
-------
Expand All @@ -109,7 +110,7 @@ def localize_timestamp(
to the new timezone.

"""
if not timestamp.tz:
if not timestamp.tz or timezone is None:
return timestamp.tz_localize(timezone)

if timestamp.utcoffset() != timestamp.tz_convert(timezone).utcoffset():
Expand Down
9 changes: 9 additions & 0 deletions tests/_static/aplose_result.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dataset,filename,annotation_id,is_update_of_id,start_time,end_time,start_frequency,end_frequency,min_frequency,max_frequency,annotation,annotator,annotator_expertise,start_datetime,end_datetime,is_box,type,confidence_indicator_label,confidence_indicator_level,comments,signal_quantity,signal_is_intensity_too_low,signal_does_overlap_other_signals,signal_start_frequency,signal_end_frequency,signal_relative_min_frequency_count,signal_relative_max_frequency_count,signal_steps_count,signal_has_harmonics,signal_trend,signal_sidebands,signal_subharmonics,signal_frequency_jumps,signal_deterministic_chaos,created_at_phase,lookaftering,bunyan
great_tit,990694,586654,,0.0,20.0,0.0,24000.0,0.0,24000.0,bird,vashti,NOVICE,2021-01-01T00:00:00.000+00:00,2021-01-01T00:00:20.000+00:00,0,WEAK,Sure,1/1,great tits |- vashti,MULTIPLE,,,,,,,,,,,,,,ANNOTATION,True,False
great_tit,990694,586655,,1.412,3.651,2512.0,15661.0,2512.0,15661.0,bird,vashti,NOVICE,2021-01-01T00:00:01.412+00:00,2021-01-01T00:00:03.651+00:00,1,BOX,Not sure,0/1,fluffy-backed tit-babbler |- vashti,MULTIPLE,,,,,,,,,,,,,,ANNOTATION,False,False
great_tit,990694,586656,,0.0,20.0,0.0,24000.0,0.0,24000.0,rain,heartleap,,2021-01-01T00:00:00.000+00:00,2021-01-01T00:00:20.000+00:00,0,WEAK,Sure,1/1,,MULTIPLE,,,,,,,,,,,,,,ANNOTATION,True,True
great_tit,990694,586657,,3.53,4.71,11137.0,13997.0,11137.0,13997.0,rain,heartleap,,2021-01-01T00:00:03.530+00:00,2021-01-01T00:00:04.710+00:00,1,BOX,Sure,1/1,,SINGLE,,True,12000.0,13000.0,3,2,4,True,MOD,True,,True,True,ANNOTATION,True,True
great_tit,990694,586669,586655,1.412,3.651,2512.0,15660.0,2512.0,15660.0,bird,bunyan,EXPERT,2021-01-01T00:00:01.412+00:00,2021-01-01T00:00:03.651+00:00,1,BOX,Not sure,0/1,,MULTIPLE,,,,,,,,,,,,,,VERIFICATION,,
great_tit,990694,586710,586655,1.412,3.651,2512.0,15660.0,2512.0,15660.0,bird,lookaftering,EXPERT,2021-01-01T00:00:01.412+00:00,2021-01-01T00:00:03.651+00:00,1,BOX,Not sure,0/1,,MULTIPLE,,,,,,,,,,,,,,VERIFICATION,,
great_tit,994410,586671,,0.0,20.0,0.0,24000.0,0.0,24000.0,car,bunyan,EXPERT,2021-01-01T00:01:18.218+00:00,2021-01-01T00:01:38.218+00:00,0,WEAK,Sure,1/1,,MULTIPLE,,,,,,,,,,,,,,VERIFICATION,,
great_tit,994410,586672,,0.0,20.0,0.0,24000.0,0.0,24000.0,bird,bunyan,EXPERT,2021-01-01T00:01:18.218+00:00,2021-01-01T00:01:38.218+00:00,0,WEAK,Sure,1/1,,MULTIPLE,,,,,,,,,,,,,,VERIFICATION,,
Loading