def save_nwb(output_path, v, sweep, sweeps_by_type): '''Save a single voltage output result into an existing sweep in a NWB file. This is intended to overwrite a recorded trace with a simulated voltage. Parameters ---------- output_path : string file name of a pre-existing NWB file. v : numpy array voltage sweep : integer which entry to overwrite in the file. ''' output = NwbDataSet(output_path) output.set_sweep(sweep, None, v) sweep_by_type = {t: [ sweep ] for t, ss in sweeps_by_type.items() if sweep in ss } sweep_features = extract_cell_features.extract_sweep_features(output, sweep_by_type) try: spikes = sweep_features[sweep]['spikes'] spike_times = [ s['threshold_t'] for s in spikes ] output.set_spike_times(sweep, spike_times) except Exception, e: logging.info("sweep %d has no sweep features. %s" % (sweep, e.message) )
def save_nwb(output_path, v, sweep, sweep_by_type= None): '''Save a single voltage output result into an existing sweep in a NWB file. This is intended to overwrite a recorded trace with a simulated voltage. Parameters ---------- output_path : string file name of a pre-existing NWB file. v : numpy array voltage sweep : integer which entry to overwrite in the file. ''' output = NwbDataSet(output_path) output.set_sweep(sweep, None, v) if sweep_by_type is not None: sweep_by_type = {t: [sweep] for t, ss in sweeps_by_type.items() if sweep in ss} sweep_features = extract_cell_features.extract_sweep_features(output, sweep_by_type) try: spikes = sweep_features[sweep]['spikes'] spike_times = [s['threshold_t'] for s in spikes] output.set_spike_times(sweep, spike_times) except Exception as e: logging.info("sweep %d has no sweep features. %s" % (sweep, e.args))
class Nwb1Appender(NwbAppender): def __init__(self, nwb_file_name): NwbAppender.__init__(self, nwb_file_name) self.nwbfile = NwbDataSet(self.nwb_file_name) def add_spike_times(self, sweep_spike_times): for sweep_num, spike_times in sweep_spike_times.items(): self.nwbfile.set_spike_times(sweep_num, spike_times)
def write_sweep_response(file_name, sweep_number, response, spike_times): ''' Overwrite the response in a file. ''' logging.debug("writing sweep") write_start_time = time.time() ephds = NwbDataSet(file_name) ephds.set_sweep(sweep_number, stimulus=None, response=response) ephds.set_spike_times(sweep_number, spike_times) logging.debug("write time %f" % (time.time() - write_start_time))
def write_sweep_response(file_name, sweep_number, response, spike_times): ''' Overwrite the response in a file. ''' logging.debug("writing sweep") write_start_time = time.time() ephds = NwbDataSet(file_name) ephds.set_sweep(sweep_number, stimulus=None, response=response) ephds.set_spike_times(sweep_number, spike_times) logging.debug("write time %f" % (time.time() - write_start_time))
def prepare_nwb_output(nwb_stimulus_path, nwb_result_path): """Copy the stimulus file, zero out the recorded voltages and spike times. Parameters ---------- nwb_stimulus_path : string NWB file name nwb_result_path : string NWB file name """ copy(nwb_stimulus_path, nwb_result_path) data_set = NwbDataSet(nwb_result_path) data_set.fill_sweep_responses(0.0) for sweep in data_set.get_sweep_numbers(): data_set.set_spike_times(sweep, [])
def prepare_nwb_output(nwb_stimulus_path, nwb_result_path): '''Copy the stimulus file, zero out the recorded voltages and spike times. Parameters ---------- nwb_stimulus_path : string NWB file name nwb_result_path : string NWB file name ''' output_dir = os.path.dirname(nwb_result_path) if not os.path.exists(output_dir): os.makedirs(output_dir) copy(nwb_stimulus_path, nwb_result_path) data_set = NwbDataSet(nwb_result_path) data_set.fill_sweep_responses(0.0, extend_experiment=True) for sweep in data_set.get_sweep_numbers(): data_set.set_spike_times(sweep, [])
def save_nwb(output_path, v, sweep): '''Save a single voltage output result into an existing sweep in a NWB file. This is intended to overwrite a recorded trace with a simulated voltage. Parameters ---------- output_path : string file name of a pre-existing NWB file. v : numpy array voltage sweep : integer which entry to overwrite in the file. ''' output = NwbDataSet(output_path) output.set_sweep(sweep, None, v) sweep_features = extract_cell_features.extract_sweep_features(output_path, [sweep]) spikes = sweep_features[sweep]['mean']['spikes'] spike_times = [ s['t'] for s in spikes ] output.set_spike_times(sweep, spike_times)
def prepare_nwb_output(nwb_stimulus_path, nwb_result_path): '''Copy the stimulus file, zero out the recorded voltages and spike times. Parameters ---------- nwb_stimulus_path : string NWB file name nwb_result_path : string NWB file name ''' output_dir = os.path.dirname(nwb_result_path) if not os.path.exists(output_dir): os.makedirs(output_dir) copy(nwb_stimulus_path, nwb_result_path) data_set = NwbDataSet(nwb_result_path) data_set.fill_sweep_responses(0.0) for sweep in data_set.get_sweep_numbers(): data_set.set_spike_times(sweep, [])