Skip to content

Commit 0214d7b

Browse files
committed
Showed how to add custom process
1 parent e6aef22 commit 0214d7b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

examples/processes.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@
1414
pm = pd.core.SimpleProcessManager()
1515

1616
# this causes problems, due to Python ref counting
17-
# comment it out to find out
17+
# don't do this until issue #6 is fixed
1818
#pm.append(pd.core.SavitzkyGolaySmoother(3))
1919

20-
# this also causes issues
21-
#sg = pd.core.SavitzkyGolaySmoother(3)
22-
#pm.append(sg)
23-
#del sg
24-
25-
# this is OK, since it is fro C++
20+
# this is OK, since it is from C++
2621
pm.append(pd.core.MovingAverageSmoother(1))
2722
pm.append(pd.core.MovingAverageSmoother(3))
2823

@@ -31,6 +26,22 @@
3126
sg = pd.core.SavitzkyGolaySmoother(3)
3227
pm.append(sg)
3328

29+
# custom process
30+
class ThresholdCut(pd.core.IProcess):
31+
def __init__(self, threshold):
32+
pd.core.IProcess.__init__(self)
33+
self.threshold = threshold
34+
35+
def go(self, data):
36+
"""
37+
Chop off anything less than the threshold
38+
"""
39+
return data.ramp(self.threshold)
40+
41+
# keep anything above threshold
42+
tc = ThresholdCut(1e3)
43+
pm.append(tc)
44+
3445
# process the data
3546
processeddata = pm.run(data).to_list()
3647

0 commit comments

Comments
 (0)