Skip to content

Commit c3f8c5e

Browse files
authored
Merge pull request #6 from NGWPC/bug_argmax_eventmetrics
fix argmax error in event metrics
2 parents 69ffaee + cb99ac8 commit c3f8c5e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

python/calib/src/calib/event_metric_functions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,31 @@ def separate_compound_events(events: pd.DataFrame, data: pd.Series) -> pd.DataFr
131131
# end times of new events
132132
end_times = [t1 - dt.timedelta(hours=1) for t1 in start_times[1:]] + [e1.end]
133133

134+
# make sure end_time is greater than start_time for every event
135+
start_times1 = []
136+
end_times1 = []
137+
for s, e in zip(start_times, end_times):
138+
if s < e:
139+
start_times1 = start_times1 + [s]
140+
end_times1 = end_times1 + [e]
141+
134142
# recompute peak times based on start and end times identified
135143
peak_times = [
136-
data1["value"].loc[start_times[i1] : end_times[i1]].idxmax()
137-
for i1 in range(len(start_times))
144+
data1["value"].loc[start_times1[i1] : end_times1[i1]].idxmax()
145+
for i1 in range(len(start_times1))
138146
]
139147

140148
# recompute peak values
141149
peak_values = [
142-
data1["value"].loc[start_times[i1] : end_times[i1]].max()
143-
for i1 in range(len(start_times))
150+
data1["value"].loc[start_times1[i1] : end_times1[i1]].max()
151+
for i1 in range(len(start_times1))
144152
]
145153

146154
# new events from the decomposition
147155
df_event = pd.DataFrame(
148156
{
149-
"start": start_times,
150-
"end": end_times,
157+
"start": start_times1,
158+
"end": end_times1,
151159
"peak": peak_times,
152160
"peak_value": peak_values,
153161
}

0 commit comments

Comments
 (0)