Changeset 12986


Ignore:
Timestamp:
03/01/12 15:31:05 (13 years ago)
Author:
neise
Message:
generator now allows for more than one spike .... generator option string changedsvn diff extractor.py | colordiff ! so I had to change it in extractor as well... sorry
Location:
fact/tools/pyscripts/pyfact
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/pyfact/extractor.py

    r12981 r12986  
    128128    """ test the extractors """
    129129    sg = SignalGenerator()
    130     pulse_str = 'len 300 bsl -0.5 noise 0.5 triangle 10 65 8 100'
     130    pulse_str = 'len 300 bsl -0.5 noise 0.5 triangle 65 10 8 100'
    131131    pulse = sg(pulse_str)
    132132    event = []
  • fact/tools/pyscripts/pyfact/generator.py

    r12982 r12986  
    4444
    4545        if 'triangle' in o:
    46             self.triangle_height = float(o['triangle'][0])
    47             self.triangle_pos = float(o['triangle'][1])
    48             self.triangle_rise = int(o['triangle'][2])
    49             self.triangle_fall = int(o['triangle'][3])
     46            self.pulses = []
     47            # append 1st pulse to list of pulses
     48            self.pulses.append( ( float(o['triangle'][0]) , float(o['triangle'][1]), int(o['triangle'][2]), int(o['triangle'][3]) ) )
     49            number_of_pulses_after_1st = (len(o['triangle'])-4)/2
     50            for i in range(number_of_pulses_after_1st):
     51                self.pulses.append( ( float(o['triangle'][2*i+4]) , float(o['triangle'][2*i+5]), int(o['triangle'][2]), int(o['triangle'][3]) ) )
    5052
    5153        if 'spike' in o:
     
    6668            signal[self.step_start:self.step_stop] += self.step_height
    6769        if 'triangle' in self.options:
    68             start = self.triangle_pos - self.triangle_rise
    69             stop = self.triangle_pos + self.triangle_fall
    70             pos = self.triangle_pos
    71             height = self.triangle_height
    72             signal[start:pos] += np.linspace(0., height, self.triangle_rise)
    73             signal[pos:stop] += np.linspace(height, 0. , self.triangle_fall)
     70            for pulse in self.pulses:
     71                pos = pulse[0]
     72                height = pulse[1]
     73                rise = pulse[2]
     74                fall = pulse[3]
     75                start = pos - rise
     76                stop = pos + fall
     77                signal[start:pos] += np.linspace(0., height, rise)
     78                signal[pos:stop] += np.linspace(height, 0. , fall)
    7479        if 'spike' in self.options:
    7580            for spike in self.spikes:
     
    8489        s += ' * bsl:      level (-0.5)\n'
    8590        s += ' * step:     height, start, end\n'
    86         s += ' * triangle: height, position, risingedge, fallingedge\n'
     91        s += ' * triangle: pos height risingedge, fallingedge [pos height ...]\n'
    8792        s += ' * spike:    pos height [pos height ...]\n'
    8893       
     
    121126if __name__ == '__main__':
    122127    """ test the class """
    123     myGenerator = SignalGenerator('len 100 noise 0.3 bsl -2.5 step 20.3 12 24 triangle 10.2 50 10 30 spike 2 50. 20 50')
     128    myGenerator = SignalGenerator('len 400 noise 0.3 bsl -2.5 triangle 50 10.2 10 100 65 10 150 20 180 10 250 10 spike 100 50. 20 50 21 49')
    124129    sig = myGenerator()
    125130    print myGenerator
Note: See TracChangeset for help on using the changeset viewer.