Skip to content

Commit

Permalink
Merge pull request #34 from DassHydro-dev/fix-event-seg-algo
Browse files Browse the repository at this point in the history
FIX: max_duration event segmentation algorithm
  • Loading branch information
nghi-truyen authored Jul 9, 2023
2 parents e9ca55a + 4d1e0b9 commit 1ab786c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ For :math:`t_{j}\in E`:
.. note::

If there exists :math:`m+1` :math:`(m>0)` consecutive events :math:`(sd_{u},ed_{u}),...,(sd_{u+m},ed_{u+m})`
occurring "nearly simultaneously", that means all of these events
occur in no more than ``max_duration`` hours: :math:`ed_{u+m}<sd_{u}+` ``max_duration``, then we
merge these :math:`m+1` events into a single event :math:`(sd_{u},ed_{u+m})`.
occurring "nearly simultaneously", then we merge these :math:`m+1` events into a single event :math:`(sd_{u},ed_{u+m})`.
Note that the duration of the merged event may exceed the specified maximum duration of ``max_duration`` hours.
5 changes: 5 additions & 0 deletions doc/source/release/0.5.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ The bug related to the computation of flood event signatures has been resolved f

See issue `#28 <https://github.com/DassHydro-dev/smash/issues/28>`__.

Segmentation algorithm
**********************

If multiple events are detected, the duration of the merged event is no longer constrained by the max duration parameter. Instead, its duration may exceed this value.

``smash.generate_mesh`` segmentation fault
******************************************

Expand Down
5 changes: 3 additions & 2 deletions smash/core/_event_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ def _events_grad(
prev_peakq = list_events[-1]["peakQ"]
prev_peakp = list_events[-1]["peakP"]

# % merge two events respecting to max duration:
if max(end, prev_end) <= prev_start + max_duration:
# % detect double events:
if prev_end >= start:
list_events[-1]["end"] = max(end, prev_end)
list_events[-1]["start"] = min(start, prev_start)

if q[i_peak] > q[prev_peakq]:
list_events[-1]["peakQ"] = i_peak
Expand Down
2 changes: 1 addition & 1 deletion smash/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def event_segmentation(self, peak_quant: float = 0.995, max_duration: float = 24
Events will be selected if their discharge peaks exceed the **peak_quant**-quantile of the observed discharge timeseries.
max_duration: float, default 240
The expected maximum duration of an event (in hour).
The expected maximum duration of an event (in hours). If multiple events are detected, their duration may exceed this value.
Returns
-------
Expand Down

0 comments on commit 1ab786c

Please sign in to comment.