Skip to content

Commit

Permalink
add kwargs to Event.fill_gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautzilla committed Dec 16, 2024
1 parent 92446ce commit 1998e52
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
16 changes: 14 additions & 2 deletions src/OSmOSE/data/audio_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class AudioData(BaseData[AudioItem, AudioFile]):
The data is accessed via an AudioItem object per AudioFile.
"""

def __init__(self, items: list[AudioItem], sample_rate: int | None = None) -> None:
def __init__(
self,
items: list[AudioItem] | None = None,
begin: Timestamp | None = None,
end: Timestamp | None = None,
sample_rate: int | None = None,
) -> None:
"""Initialize an AudioData from a list of AudioItems.
Parameters
Expand All @@ -39,9 +45,15 @@ def __init__(self, items: list[AudioItem], sample_rate: int | None = None) -> No
List of the AudioItem constituting the AudioData.
sample_rate: int
The sample rate of the audio data.
begin: Timestamp | None
Only effective if items is None.
Set the begin of the empty data.
end: Timestamp | None
Only effective if items is None.
Set the end of the empty data.
"""
super().__init__(items)
super().__init__(items=items, begin=begin, end=end)
self._set_sample_rate(sample_rate=sample_rate)

@property
Expand Down
20 changes: 17 additions & 3 deletions src/OSmOSE/data/base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ class BaseData(Generic[TItem, TFile], Event):
The data is accessed via an Item object per File.
"""

def __init__(self, items: list[TItem]) -> None:
"""Initialize an BaseData from a list of Items.
def __init__(
self,
items: list[TItem] | None = None,
begin: Timestamp | None = None,
end: Timestamp | None = None,
) -> None:
"""Initialize a BaseData from a list of Items.
Parameters
----------
items: list[BaseItem]
items: list[BaseItem] | None
List of the Items constituting the Data.
Defaulted to an empty item ranging from begin to end.
begin: Timestamp | None
Only effective if items is None.
Set the begin of the empty data.
end: Timestamp | None
Only effective if items is None.
Set the end of the empty data.
"""
if not items:
items = [BaseItem(begin=begin, end=end)]
self.items = items
self.begin = min(item.begin for item in self.items)
self.end = max(item.end for item in self.items)
Expand Down
5 changes: 4 additions & 1 deletion src/OSmOSE/data/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def fill_gaps(
cls,
events: list[TEvent],
filling_class: type[TEvent],
**kwargs: any,
) -> list[TEvent]:
"""Return a list with empty events added in the gaps between items.
Expand All @@ -123,6 +124,8 @@ def fill_gaps(
List of events to fill.
filling_class: type[TEvent]
The class used for instantiating empty events in the gaps.
kwargs: any
Additional parameters to pass to the filling instance constructor.
Returns
-------
Expand All @@ -148,7 +151,7 @@ def fill_gaps(
filled_event_list.append(event)
if next_event.begin > event.end:
filled_event_list.append(
filling_class(begin=event.end, end=next_event.begin),
filling_class(begin=event.end, end=next_event.begin, **kwargs),
)
filled_event_list.append(events[-1])
return filled_event_list
Expand Down

0 comments on commit 1998e52

Please sign in to comment.