Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 591258a

Browse files
committed
fix bug with trailing zeros on the last storm
1 parent 4ad1f23 commit 591258a

4 files changed

Lines changed: 95 additions & 88 deletions

File tree

‎cloudside/storms.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import timedelta
2+
13
import numpy
24
import pandas
35

@@ -74,7 +76,7 @@ def parse_record(
7476
Returns
7577
-------
7678
parsed_storms : pandas.DataFrame
77-
Copy of the origin `hydrodata` DataFrame, but resampled to a
79+
Copy of the original `data` DataFrame, but resampled to a
7880
fixed frequency, columns possibly renamed, and a `storm` column
7981
added to denote the storm to which each record belongs. Records
8082
where `storm` == 0 are not a part of any storm.
@@ -139,6 +141,11 @@ def parse_record(
139141
)
140142
)
141143

144+
# fix trailing zeroes on the last storm
145+
last_storm = res[stormcol].max()
146+
last_storm_end = res[res[stormcol].eq(last_storm) & res[precipcol].gt(0)].index.max() + (2 * freq)
147+
res.loc[last_storm_end:, stormcol] = 0
148+
142149
if not debug:
143150
res = res.loc[:, res.columns.map(lambda c: not c.startswith("__"))]
144151

‎cloudside/tests/data/teststorm_firstobs.csv‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -510,32 +510,32 @@ date,rain,influent,effluent,storm
510510
2013-05-21 13:50:00,0.01,90.0,37.0,2
511511
2013-05-21 13:55:00,0.01,85.0,33.0,2
512512
2013-05-21 14:00:00,0.0,80.0,32.0,2
513-
2013-05-21 14:05:00,0.0,75.0,30.0,2
514-
2013-05-21 14:10:00,0.0,70.0,28.0,2
515-
2013-05-21 14:15:00,0.0,65.0,27.0,2
516-
2013-05-21 14:20:00,0.0,60.0,25.0,2
517-
2013-05-21 14:25:00,0.0,55.0,23.0,2
518-
2013-05-21 14:30:00,0.0,50.0,22.0,2
519-
2013-05-21 14:35:00,0.0,45.0,20.0,2
520-
2013-05-21 14:40:00,0.0,40.0,18.0,2
521-
2013-05-21 14:45:00,0.0,37.0,17.0,2
522-
2013-05-21 14:50:00,0.0,34.0,15.0,2
523-
2013-05-21 14:55:00,0.0,31.0,13.0,2
524-
2013-05-21 15:00:00,0.0,28.0,12.0,2
525-
2013-05-21 15:05:00,0.0,25.0,11.0,2
526-
2013-05-21 15:10:00,0.0,22.0,10.0,2
527-
2013-05-21 15:15:00,0.0,20.0,9.0,2
528-
2013-05-21 15:20:00,0.0,18.0,8.0,2
529-
2013-05-21 15:25:00,0.0,16.0,7.0,2
530-
2013-05-21 15:30:00,0.0,14.0,7.0,2
531-
2013-05-21 15:35:00,0.0,12.0,6.0,2
532-
2013-05-21 15:40:00,0.0,10.0,5.0,2
533-
2013-05-21 15:45:00,0.0,8.0,5.0,2
534-
2013-05-21 15:50:00,0.0,6.0,4.0,2
535-
2013-05-21 15:55:00,0.0,5.0,3.0,2
536-
2013-05-21 16:00:00,0.0,4.0,3.0,2
537-
2013-05-21 16:05:00,0.0,3.0,2.0,2
538-
2013-05-21 16:10:00,0.0,2.0,2.0,2
539-
2013-05-21 16:15:00,0.0,1.0,1.0,2
540-
2013-05-21 16:20:00,0.0,0.0,1.0,2
541-
2013-05-21 16:25:00,0.0,0.0,1.0,2
513+
2013-05-21 14:05:00,0.0,75.0,30.0,0
514+
2013-05-21 14:10:00,0.0,70.0,28.0,0
515+
2013-05-21 14:15:00,0.0,65.0,27.0,0
516+
2013-05-21 14:20:00,0.0,60.0,25.0,0
517+
2013-05-21 14:25:00,0.0,55.0,23.0,0
518+
2013-05-21 14:30:00,0.0,50.0,22.0,0
519+
2013-05-21 14:35:00,0.0,45.0,20.0,0
520+
2013-05-21 14:40:00,0.0,40.0,18.0,0
521+
2013-05-21 14:45:00,0.0,37.0,17.0,0
522+
2013-05-21 14:50:00,0.0,34.0,15.0,0
523+
2013-05-21 14:55:00,0.0,31.0,13.0,0
524+
2013-05-21 15:00:00,0.0,28.0,12.0,0
525+
2013-05-21 15:05:00,0.0,25.0,11.0,0
526+
2013-05-21 15:10:00,0.0,22.0,10.0,0
527+
2013-05-21 15:15:00,0.0,20.0,9.0,0
528+
2013-05-21 15:20:00,0.0,18.0,8.0,0
529+
2013-05-21 15:25:00,0.0,16.0,7.0,0
530+
2013-05-21 15:30:00,0.0,14.0,7.0,0
531+
2013-05-21 15:35:00,0.0,12.0,6.0,0
532+
2013-05-21 15:40:00,0.0,10.0,5.0,0
533+
2013-05-21 15:45:00,0.0,8.0,5.0,0
534+
2013-05-21 15:50:00,0.0,6.0,4.0,0
535+
2013-05-21 15:55:00,0.0,5.0,3.0,0
536+
2013-05-21 16:00:00,0.0,4.0,3.0,0
537+
2013-05-21 16:05:00,0.0,3.0,2.0,0
538+
2013-05-21 16:10:00,0.0,2.0,2.0,0
539+
2013-05-21 16:15:00,0.0,1.0,1.0,0
540+
2013-05-21 16:20:00,0.0,0.0,1.0,0
541+
2013-05-21 16:25:00,0.0,0.0,1.0,0

‎cloudside/tests/data/teststorm_simple.csv‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -511,32 +511,32 @@ date,rain,influent,effluent,storm
511511
2013-05-21 13:50:00,0.01,90.0,37.0,2
512512
2013-05-21 13:55:00,0.01,85.0,33.0,2
513513
2013-05-21 14:00:00,0.0,80.0,32.0,2
514-
2013-05-21 14:05:00,0.0,75.0,30.0,2
515-
2013-05-21 14:10:00,0.0,70.0,28.0,2
516-
2013-05-21 14:15:00,0.0,65.0,27.0,2
517-
2013-05-21 14:20:00,0.0,60.0,25.0,2
518-
2013-05-21 14:25:00,0.0,55.0,23.0,2
519-
2013-05-21 14:30:00,0.0,50.0,22.0,2
520-
2013-05-21 14:35:00,0.0,45.0,20.0,2
521-
2013-05-21 14:40:00,0.0,40.0,18.0,2
522-
2013-05-21 14:45:00,0.0,37.0,17.0,2
523-
2013-05-21 14:50:00,0.0,34.0,15.0,2
524-
2013-05-21 14:55:00,0.0,31.0,13.0,2
525-
2013-05-21 15:00:00,0.0,28.0,12.0,2
526-
2013-05-21 15:05:00,0.0,25.0,11.0,2
527-
2013-05-21 15:10:00,0.0,22.0,10.0,2
528-
2013-05-21 15:15:00,0.0,20.0,9.0,2
529-
2013-05-21 15:20:00,0.0,18.0,8.0,2
530-
2013-05-21 15:25:00,0.0,16.0,7.0,2
531-
2013-05-21 15:30:00,0.0,14.0,7.0,2
532-
2013-05-21 15:35:00,0.0,12.0,6.0,2
533-
2013-05-21 15:40:00,0.0,10.0,5.0,2
534-
2013-05-21 15:45:00,0.0,8.0,5.0,2
535-
2013-05-21 15:50:00,0.0,6.0,4.0,2
536-
2013-05-21 15:55:00,0.0,5.0,3.0,2
537-
2013-05-21 16:00:00,0.0,4.0,3.0,2
538-
2013-05-21 16:05:00,0.0,3.0,2.0,2
539-
2013-05-21 16:10:00,0.0,2.0,2.0,2
540-
2013-05-21 16:15:00,0.0,1.0,1.0,2
541-
2013-05-21 16:20:00,0.0,0.0,1.0,2
542-
2013-05-21 16:25:00,0.0,0.0,1.0,2
514+
2013-05-21 14:05:00,0.0,75.0,30.0,0
515+
2013-05-21 14:10:00,0.0,70.0,28.0,0
516+
2013-05-21 14:15:00,0.0,65.0,27.0,0
517+
2013-05-21 14:20:00,0.0,60.0,25.0,0
518+
2013-05-21 14:25:00,0.0,55.0,23.0,0
519+
2013-05-21 14:30:00,0.0,50.0,22.0,0
520+
2013-05-21 14:35:00,0.0,45.0,20.0,0
521+
2013-05-21 14:40:00,0.0,40.0,18.0,0
522+
2013-05-21 14:45:00,0.0,37.0,17.0,0
523+
2013-05-21 14:50:00,0.0,34.0,15.0,0
524+
2013-05-21 14:55:00,0.0,31.0,13.0,0
525+
2013-05-21 15:00:00,0.0,28.0,12.0,0
526+
2013-05-21 15:05:00,0.0,25.0,11.0,0
527+
2013-05-21 15:10:00,0.0,22.0,10.0,0
528+
2013-05-21 15:15:00,0.0,20.0,9.0,0
529+
2013-05-21 15:20:00,0.0,18.0,8.0,0
530+
2013-05-21 15:25:00,0.0,16.0,7.0,0
531+
2013-05-21 15:30:00,0.0,14.0,7.0,0
532+
2013-05-21 15:35:00,0.0,12.0,6.0,0
533+
2013-05-21 15:40:00,0.0,10.0,5.0,0
534+
2013-05-21 15:45:00,0.0,8.0,5.0,0
535+
2013-05-21 15:50:00,0.0,6.0,4.0,0
536+
2013-05-21 15:55:00,0.0,5.0,3.0,0
537+
2013-05-21 16:00:00,0.0,4.0,3.0,0
538+
2013-05-21 16:05:00,0.0,3.0,2.0,0
539+
2013-05-21 16:10:00,0.0,2.0,2.0,0
540+
2013-05-21 16:15:00,0.0,1.0,1.0,0
541+
2013-05-21 16:20:00,0.0,0.0,1.0,0
542+
2013-05-21 16:25:00,0.0,0.0,1.0,0

‎cloudside/tests/data/teststorm_singular.csv‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -443,32 +443,32 @@ date,rain,influent,effluent,storm
443443
2013-05-21 13:50:00,0.01,90.0,37.0,3
444444
2013-05-21 13:55:00,0.01,85.0,33.0,3
445445
2013-05-21 14:00:00,0.0,80.0,32.0,3
446-
2013-05-21 14:05:00,0.0,75.0,30.0,3
447-
2013-05-21 14:10:00,0.0,70.0,28.0,3
448-
2013-05-21 14:15:00,0.0,65.0,27.0,3
449-
2013-05-21 14:20:00,0.0,60.0,25.0,3
450-
2013-05-21 14:25:00,0.0,55.0,23.0,3
451-
2013-05-21 14:30:00,0.0,50.0,22.0,3
452-
2013-05-21 14:35:00,0.0,45.0,20.0,3
453-
2013-05-21 14:40:00,0.0,40.0,18.0,3
454-
2013-05-21 14:45:00,0.0,37.0,17.0,3
455-
2013-05-21 14:50:00,0.0,34.0,15.0,3
456-
2013-05-21 14:55:00,0.0,31.0,13.0,3
457-
2013-05-21 15:00:00,0.0,28.0,12.0,3
458-
2013-05-21 15:05:00,0.0,25.0,11.0,3
459-
2013-05-21 15:10:00,0.0,22.0,10.0,3
460-
2013-05-21 15:15:00,0.0,20.0,9.0,3
461-
2013-05-21 15:20:00,0.0,18.0,8.0,3
462-
2013-05-21 15:25:00,0.0,16.0,7.0,3
463-
2013-05-21 15:30:00,0.0,14.0,7.0,3
464-
2013-05-21 15:35:00,0.0,12.0,6.0,3
465-
2013-05-21 15:40:00,0.0,10.0,5.0,3
466-
2013-05-21 15:45:00,0.0,8.0,5.0,3
467-
2013-05-21 15:50:00,0.0,6.0,4.0,3
468-
2013-05-21 15:55:00,0.0,5.0,3.0,3
469-
2013-05-21 16:00:00,0.0,4.0,3.0,3
470-
2013-05-21 16:05:00,0.0,3.0,2.0,3
471-
2013-05-21 16:10:00,0.0,2.0,2.0,3
472-
2013-05-21 16:15:00,0.0,1.0,1.0,3
473-
2013-05-21 16:20:00,0.0,0.0,1.0,3
474-
2013-05-21 16:25:00,0.0,0.0,1.0,3
446+
2013-05-21 14:05:00,0.0,75.0,30.0,0
447+
2013-05-21 14:10:00,0.0,70.0,28.0,0
448+
2013-05-21 14:15:00,0.0,65.0,27.0,0
449+
2013-05-21 14:20:00,0.0,60.0,25.0,0
450+
2013-05-21 14:25:00,0.0,55.0,23.0,0
451+
2013-05-21 14:30:00,0.0,50.0,22.0,0
452+
2013-05-21 14:35:00,0.0,45.0,20.0,0
453+
2013-05-21 14:40:00,0.0,40.0,18.0,0
454+
2013-05-21 14:45:00,0.0,37.0,17.0,0
455+
2013-05-21 14:50:00,0.0,34.0,15.0,0
456+
2013-05-21 14:55:00,0.0,31.0,13.0,0
457+
2013-05-21 15:00:00,0.0,28.0,12.0,0
458+
2013-05-21 15:05:00,0.0,25.0,11.0,0
459+
2013-05-21 15:10:00,0.0,22.0,10.0,0
460+
2013-05-21 15:15:00,0.0,20.0,9.0,0
461+
2013-05-21 15:20:00,0.0,18.0,8.0,0
462+
2013-05-21 15:25:00,0.0,16.0,7.0,0
463+
2013-05-21 15:30:00,0.0,14.0,7.0,0
464+
2013-05-21 15:35:00,0.0,12.0,6.0,0
465+
2013-05-21 15:40:00,0.0,10.0,5.0,0
466+
2013-05-21 15:45:00,0.0,8.0,5.0,0
467+
2013-05-21 15:50:00,0.0,6.0,4.0,0
468+
2013-05-21 15:55:00,0.0,5.0,3.0,0
469+
2013-05-21 16:00:00,0.0,4.0,3.0,0
470+
2013-05-21 16:05:00,0.0,3.0,2.0,0
471+
2013-05-21 16:10:00,0.0,2.0,2.0,0
472+
2013-05-21 16:15:00,0.0,1.0,1.0,0
473+
2013-05-21 16:20:00,0.0,0.0,1.0,0
474+
2013-05-21 16:25:00,0.0,0.0,1.0,0

0 commit comments

Comments
 (0)