def detect_epochs(self): """ Detect epochs if they are not provided in the constructor """ if "test" not in self.epochs: self.epochs["test"] = ep.get_test_epoch(self.stimulus, self.sampling_rate) if self.epochs["test"]: test_pulse = True else: test_pulse = False epoch_detectors = { "sweep": ep.get_sweep_epoch(self.response), "recording": ep.get_recording_epoch(self.response), "experiment": ep.get_experiment_epoch(self._i, self.sampling_rate, test_pulse), "stim": ep.get_stim_epoch(self.stimulus, test_pulse), } for epoch_name, epoch_detector in epoch_detectors.items(): if epoch_name not in self.epochs: self.epochs[epoch_name] = epoch_detector
def detect_epochs(self): """ Detect epochs if they are not provided in the constructor """ if "test" not in self.epochs: self.epochs["test"] = ep.get_test_epoch(self._stimulus, self.sampling_rate) if self.epochs["test"]: test_pulse = True else: test_pulse = False if "sweep" not in self.epochs: self.epochs["sweep"] = ep.get_sweep_epoch(self._i) if "recording" not in self.epochs: self.epochs["recording"] = ep.get_recording_epoch(self._response) # get valid recording by selecting epoch and using i/v prop before detecting stim self.select_epoch("recording") stim = self.i if self.clamp_mode == "CurrentClamp" else self.v if "stim" not in self.epochs: self.epochs["stim"] = ep.get_stim_epoch(stim, test_pulse) if "experiment" not in self.epochs: self.epochs["experiment"] = ep.get_experiment_epoch(stim, self.sampling_rate, test_pulse)
# Drop failed sweeps: sweeps with incomplete recording or failing QC criteria drop_failed_sweeps(data_set) short_square_table = data_set.filtered_sweep_table( stimuli=data_set.ontology.short_square_names ) short_square_sweeps = data_set.sweep_set(short_square_table.sweep_number) # Select epoch corresponding to the actual recording from the sweeps # and align sweeps so that the experiment would start at the same time short_square_sweeps.select_epoch("recording") short_square_sweeps.align_to_start_of_epoch("experiment") # find the start and end time of the stimulus # (treating the first sweep as representative) stim_start_index, stim_end_index = get_stim_epoch(short_square_sweeps.i[0]) stim_start_time = short_square_sweeps.t[0][stim_start_index] stim_end_time = short_square_sweeps.t[0][stim_end_index] # Estimate the dv cutoff and threshold fraction dv_cutoff, thresh_frac = estimate_adjusted_detection_parameters( short_square_sweeps.v, short_square_sweeps.t, stim_start_time, stim_start_time + 0.001 ) # Build the extractors spfx = SpikeFeatureExtractor( start=stim_start_time, dv_cutoff=dv_cutoff, thresh_frac=thresh_frac )
def test_get_stim_epoch(i, stim_epoch): assert stim_epoch == ep.get_stim_epoch(i)
stimuli=data_set.ontology.ramp_names) ramp_sweeps = data_set.sweep_set(ramp_table.sweep_number) # Select epoch corresponding to the actual recording from the sweeps # and align sweeps so that the experiment would start at the same time ramp_sweeps.select_epoch("recording") ramp_sweeps.align_to_start_of_epoch("experiment") # Select epoch corresponding to the actual recording from the sweeps # and align sweeps so that the experiment would start at the same time ramp_sweeps.select_epoch("recording") ramp_sweeps.align_to_start_of_epoch("experiment") # find the start and end time of the stimulus # (treating the first sweep as representative) stim_start_index, stim_end_index = get_stim_epoch(ramp_sweeps.i[0]) stim_start_time = ramp_sweeps.t[0][stim_start_index] stim_end_time = ramp_sweeps.t[0][stim_end_index] spx = SpikeFeatureExtractor(start=stim_start_time, end=None) sptfx = SpikeTrainFeatureExtractor(start=stim_start_time, end=None) # Run the analysis ramp_analysis = RampAnalysis(spx, sptfx) results = ramp_analysis.analyze(ramp_sweeps) # Plot the sweeps and the latency to the first spike of each sns.set_style("white") for swp in ramp_sweeps.sweeps: plt.plot(swp.t, swp.v, linewidth=0.5) sns.rugplot(results["spiking_sweeps"]["latency"].values + stim_start_time)