Changeset 429
- Timestamp:
- 08/25/09 16:48:59 (3 years ago)
- Location:
- branches/interval/src/signals
- Files:
-
- 2 modified
-
analogs.py (modified) (5 diffs)
-
spikes.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/interval/src/signals/analogs.py
r390 r429 80 80 self.signal = numpy.array(signal, float) 81 81 self.dt = float(dt) 82 if t_start is None: 83 t_start = 0 84 self.t_start = float(t_start) 85 self.t_stop = t_stop 86 # If t_stop is not None, we test that the signal has the correct number 87 # of elements 88 if self.t_stop is not None: 89 if abs(self.t_stop-self.t_start - self.dt * len(self.signal)) > 0.1*self.dt: 90 raise Exception("Inconsistent arguments: t_start=%g, t_stop=%g, dt=%g implies %d elements, actually %d" % ( 91 t_start, t_stop, dt, int(round((t_stop-t_start)/float(dt))), len(signal))) 92 else: 93 self.t_stop = self.t_start + len(self.signal)*self.dt 82 self.interval = self.create_intervals(t_start, t_stop, interval) 83 self.init_times() 94 84 95 85 # TODO raise an error if some data is outside [t_start, t_stop] ? 96 # TODO return an exception if self.t_stop < self.t_start (when not empty) 86 if not (self.t_start >= 0) and (self.t_stop >= 0) : 87 raise ValueError("t_start and t_stop should be greater than 0") 97 88 if self.t_start >= self.t_stop: 98 89 raise Exception("Incompatible time interval for the creation of the AnalogSignal. t_start=%s, t_stop=%s" % (self.t_start, self.t_stop)) 90 91 def create_intervals(self, t_start=None, t_stop=None, interval=None): 92 if hasattr(self, 'interval') and t_start is None and t_stop is None and interval is None: 93 interval_out = self.interval.copy() 94 elif interval is not None: 95 # interval is fully defined by the user 96 if type(interval) == Interval: 97 interval_out = interval.copy() 98 else : 99 interval_out = Interval(interval) 100 else: 101 if t_start is None and t_stop is None : 102 try: 103 t_start = numpy.min(self.spike_times) 104 except Exception: 105 print "AnalogSignal error in guessing t_start (first spike), spikes may be empty !" 106 t_start = 0 107 try: 108 t_stop = numpy.max(self.spike_times) 109 except Exception: 110 print "AnalogSignal error in guessing t_stop (last spike), spikes may be empty !" 111 t_stop = t_start+self.dt 112 interval_out = Interval([[t_start, t_stop]]) 113 elif t_start is None and t_stop is not None: 114 try: 115 t_start = numpy.min(self.spike_times) 116 except Exception: 117 print "AnalogSignal error in guessing t_start (first spike), spikes may be empty !" 118 t_start = 0 119 interval_out = Interval([[t_start, t_stop]]) 120 elif t_start is not None and t_stop is not None: 121 interval_out = Interval([[t_start, t_stop]]) 122 elif t_start is not None and t_stop is None: 123 if type(t_start) == float or type(t_start) == int: 124 try: 125 t_stop = numpy.max(self.spike_times) 126 except Exception: 127 print "AnalogSignal error in guessing t_stop (last spike), spikes may be empty !" 128 t_stop = t_start+self.dt 129 interval_out = Interval([[t_start, t_stop]]) 130 else : 131 if type(t_start) == Interval: 132 interval_out = t_start.copy() 133 else : 134 interval_out = Interval(t_start) 135 return interval_out 136 99 137 100 138 def __getslice__(self, i, j): … … 157 195 1100 158 196 """ 159 self. t_start += offset160 self.t_stop += offset 197 self.interval.offset_full(offset) 198 self.init_times() 161 199 162 200 … … 165 203 Return the time parameters of the AnalogSignal (t_start, t_stop, dt) 166 204 """ 205 self.init_times() 167 206 return (self.t_start, self.t_stop, self.dt) 168 207 … … 231 270 result = [] 232 271 for itv in interval.interval_data : 233 result.append(self.signal[ intv[0]/self.dt:intv[1]/self.dt])234 272 result.append(self.signal[(intv[0]-self.t_start)/self.dt:(intv[1]-t_start)/self.dt]) 273 return result 235 274 236 275 def threshold_detection(self, threshold=None, format=None,sign='above'): … … 258 297 cutout = numpy.where(self.signal < threshold)[0] 259 298 260 if len(cutout) <= 0:299 if len(cutout) == 0: 261 300 events = [] 262 301 else: -
branches/interval/src/signals/spikes.py
r428 r429 122 122 t_start = numpy.min(self.spike_times) 123 123 except Exception: 124 print "Spike Listerror in guessing t_start (first spike), spikes may be empty !"124 print "SpikeTrain error in guessing t_start (first spike), spikes may be empty !" 125 125 t_start = 0 126 126 try: 127 127 t_stop = numpy.max(self.spike_times) 128 128 except Exception: 129 print "Spike Listerror in guessing t_stop (last spike), spikes may be empty !"129 print "SpikeTrain error in guessing t_stop (last spike), spikes may be empty !" 130 130 t_stop = t_start+0.1 131 131 interval_out = Interval([[t_start, t_stop]]) … … 134 134 t_start = numpy.min(self.spike_times) 135 135 except Exception: 136 print "Spike Listerror in guessing t_start (first spike), spikes may be empty !"136 print "SpikeTrain error in guessing t_start (first spike), spikes may be empty !" 137 137 t_start = 0 138 138 interval_out = Interval([[t_start, t_stop]]) … … 144 144 t_stop = numpy.max(self.spike_times) 145 145 except Exception: 146 print "Spike Listerror in guessing t_stop (last spike), spikes may be empty !"146 print "SpikeTrain error in guessing t_stop (last spike), spikes may be empty !" 147 147 t_stop = t_start+0.1 148 148 interval_out = Interval([[t_start, t_stop]]) … … 1024 1024 Return the time parameters of the SpikeList (t_start, t_stop) 1025 1025 """ 1026 return (self.interval.t_start(), self.interval.t_stop()) 1026 self.init_times() 1027 return (self.t_start, self.t_stop) 1027 1028 1028 1029 def init_times(self):
