def pulses(self): """Return a list of (start, stop, amp) tuples describing square pulses in the stimulus. """ if self._pulses is None: trace = self.rec['command'] pulses = find_square_pulses(trace) self._pulses = [] for p in pulses: start = trace.index_at(p.global_start_time) stop = trace.index_at(p.global_start_time + p.duration) self._pulses.append((start, stop, p.amplitude)) return self._pulses
def pulses(self, channel='command'): """Return a list of (start_time, stop_time, amp) tuples describing square pulses in the stimulus. """ if self._pulses.get(channel) is None: trace = self.rec[channel] pulses = find_square_pulses(trace) self._pulses[channel] = [] for p in pulses: start = p.global_start_time stop = p.global_start_time + p.duration self._pulses[channel].append((start, stop, p.amplitude)) return self._pulses[channel]
def pulses(self): """Return a list of (start, stop, amp) tuples describing square pulses in the stimulus. """ if self._pulses is None: trace = self.rec['command'] pulses = find_square_pulses(trace) self._pulses = [] for p in pulses: start = trace.index_at(p.global_start_time) stop = trace.index_at(p.global_start_time + p.duration) self._pulses.append((start, stop, p.amplitude)) return self._pulses
def pulses(self, channel=None): """Return a list of (start_time, stop_time, amp) tuples describing square pulses in the specified channel. """ self._check_channel(channel) if self._pulses.get(channel) is None: trace = self.rec[channel] if trace.data[:10].std() > 0: pulses = find_noisy_square_pulses(trace, std_threshold=10) else: pulses = find_square_pulses(trace) self._pulses[channel] = [] for p in pulses: start = p.global_start_time stop = p.global_start_time + p.duration self._pulses[channel].append((start, stop, p.amplitude)) return self._pulses[channel]
def pulses(self, channel=None): """Return a list of SquarePulses found in the given channel of the recording. If there is pulse-width modulation (higher than %s Hz), it will be grouped into a single SquarePulse with lower amplitude. Example: _____|||||_______________|||||_____________|||||____________ <---> <---> <---> The trace shown above has pulse width modulation would return a list of 3 SquarePulses with an amplitude equal to the mean of the trace during the periods indicated by the arrows. The trace shown below (no pulse width modulation) would also return a list of 3 SquarePulses, but with an amplitude of 1. _____ _____ _____ ____| |_____________| |___________| |___________ Parameters: ----------- channel : str | None The channel to analyze pulses from. """ % str(self.pwm_min_frequency) self._check_channel(channel) if self._pulses.get(channel) is None: trace = self.rec[channel] if trace.data[:10].std() > 0: all_pulses = find_noisy_square_pulses(trace) else: all_pulses = find_square_pulses(trace) ## figure out if there is pwm happening pwm = False if len(all_pulses) > 1: for i in range(len(all_pulses) - 1): if all_pulses[i + 1].global_start_time - all_pulses[ i].global_start_time <= self.pwm_min_delay: ## dealing with pwm pwm = True break ## convert pwm pulses into single stimulation pulses if pwm: pulses = [] self._pwm_params[channel] = [] ### make an array of start times starts = np.array([p.global_start_time for p in all_pulses]) ### do a diff on the array - look for points larger than 1/min_frequency breaks = np.argwhere( np.diff(starts) > self.pwm_min_delay ) ## gives indices of the last pulse in a pwm pulse if len(breaks) == 0: ## only one pulse pulse, params = self._create_pulse_from_pwm(all_pulses) pulses.append(pulse) self._pwm_params[channel].append(params) ### take the pulses between large diffs and turn them into one pulse with appropriate duration and amplitude else: start_i = 0 for i, b in enumerate(breaks): pulse, params = self._create_pulse_from_pwm( all_pulses[start_i:b + 1]) pulses.append(pulse) self._pwm_params[channel].append(params) start_i = b + 1 pulse, params = self._create_pulse_from_pwm( all_pulses[start_i:]) pulses.append(pulse) self._pwm_params[channel].append(params) else: self._pwm_params[channel] = None pulses = [ SquarePulse(start_time=p.global_start_time, duration=p.duration, amplitude=1, units='percent') for p in all_pulses ] ### convert from SquarePulse to (start, stop, amplitude) self._pulses[channel] = pulses return self._pulses[channel]