~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to pyOpenMS/addons/MSChromatogram.pyx

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
cimport numpy as np
 
2
import numpy as np
 
3
 
 
4
 
 
5
    def get_peaks(self):
 
6
 
 
7
        cdef _MSChromatogram[_ChromatogramPeak] * chrom_ = self.inst.get()
 
8
 
 
9
        cdef unsigned int n = chrom_.size()
 
10
        cdef np.ndarray[np.float32_t, ndim=2] peaks
 
11
        peaks = np.zeros( [n,2], dtype=np.float32)
 
12
        cdef _ChromatogramPeak p
 
13
 
 
14
        cdef libcpp_vector[_ChromatogramPeak].iterator it = chrom_.begin()
 
15
        cdef int i = 0
 
16
        while it != chrom_.end():
 
17
            peaks[i,0] = deref(it).getRT()
 
18
            peaks[i,1] = deref(it).getIntensity()
 
19
            inc(it)
 
20
            i += 1
 
21
 
 
22
        return peaks
 
23
 
 
24
    def set_peaks(self, np.ndarray[np.float32_t, ndim=2] peaks):
 
25
 
 
26
        cdef _MSChromatogram[_ChromatogramPeak] * chrom_ = self.inst.get()
 
27
 
 
28
        chrom_.clear(0) # emtpy vector , keep meta data
 
29
        cdef _ChromatogramPeak p = _ChromatogramPeak()
 
30
        cdef double mz
 
31
        cdef float I
 
32
        cdef int N
 
33
        N = peaks.shape[0]
 
34
 
 
35
 
 
36
        for i in range(N):
 
37
            mz = peaks[i,0]
 
38
            I  = peaks[i,1]
 
39
            p.setRT(mz)
 
40
            p.setIntensity(<float>I)
 
41
            chrom_.push_back(p)
 
42
 
 
43
        chrom_.updateRanges()
 
44