Skip to content

Commit 78d540e

Browse files
committed
Added native python process manager to circumvent issue #6 for now.
1 parent a11ff84 commit 78d540e

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

examples/realspectrum.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121
snippedCounts = hist_raw.Y
2222

2323
# process manager
24-
pm = pkd.core.SimpleProcessManager()
25-
26-
# smooth
27-
sg = pkd.core.SavitzkyGolaySmoother(31)
28-
pm.append(sg)
29-
30-
# peak finding
31-
pm.append(pkd.core.MovingAveragePeakFinder(400))
24+
pm = pkd.core.PySimpleProcessManager(processes=[
25+
pkd.core.SavitzkyGolaySmoother(31),
26+
pkd.core.MovingAveragePeakFinder(400)
27+
])
3228

3329
# process
3430
processed_counts = pm.run(snippedCounts)

peakingduck/core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
from PEAKINGDUCK.core import *
33

44
# python additional
5-
from peakingduck.core.smoothing import *
5+
from peakingduck.core.smoothing import *
6+
from peakingduck.core.process import *

peakingduck/core/process.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# raw C++ bindings library
2+
from PEAKINGDUCK.core import IProcessManager
3+
4+
"""
5+
Add other processes and/or process managers here.
6+
"""
7+
8+
class PySimpleProcessManager(IProcessManager):
9+
"""
10+
Instead of using the C++ SimpleProcessManager
11+
we make a python native version to avoid
12+
ref counting issues
13+
14+
Easy to extend also.
15+
"""
16+
def __init__(self, processes=None):
17+
self.processes = []
18+
if processes:
19+
self.processes = processes
20+
21+
def append(self, process):
22+
self.processes.append(process)
23+
24+
def __len__(self):
25+
return len(self.processes)
26+
27+
def __item__(self, i):
28+
return self.processes[i]
29+
30+
def run(self, data):
31+
newdata = data
32+
for p in self.processes:
33+
newdata = p.go(newdata)
34+
return newdata

0 commit comments

Comments
 (0)