def populatemytables_core_paralel(arguments, runround): if runround == 1: ephysanal.SquarePulse().populate(**arguments) ephysanal.SweepFrameTimes().populate(**arguments) elif runround == 2: ephysanal.SquarePulseSeriesResistance().populate(**arguments) ephysanal.SweepSeriesResistance().populate(**arguments) elif runround == 3: ephysanal.SweepResponseCorrected().populate(**arguments) elif runround == 4: ephysanal.ActionPotential().populate(**arguments) ephysanal.ActionPotentialDetails().populate(**arguments)
def plot_time_interval(wr_name='FOR04', cellnum=1, timeedges=[0, 10], ylimits_response=None, plotRS=False): subject_id = (lab.WaterRestriction() & 'water_restriction_number = "' + wr_name + '"').fetch('subject_id')[0] key = {'subject_id': subject_id, 'cell_number': cellnum} allsweeps = pd.DataFrame((ephys_patch.Sweep() & key)) sweepstoplot = np.where( np.logical_and( allsweeps['sweep_end_time'] > float(np.min(timeedges)), allsweeps['sweep_start_time'] < float(np.max(timeedges))))[0] df_iv = pd.DataFrame() for sweepnum in sweepstoplot: key['sweep_number'] = sweepnum df_iv = pd.concat([ df_iv, pd.DataFrame((ephys_patch.Sweep() & key) * (ephys_patch.SweepResponse() & key) * (ephys_patch.SweepStimulus() & key) * (ephys_patch.SweepMetadata() & key)) ]) df_IV = pd.DataFrame() for line in df_iv.iterrows(): linenow = line[1] time = np.arange(0, len( linenow['response_trace'])) / linenow['sample_rate'] linenow['time'] = time + float(linenow['sweep_start_time']) df_IV = pd.concat([df_IV, linenow.to_frame().transpose()]) fig = plt.figure() ax_IV = fig.add_axes([0, 0, 2, .8]) ax_stim = fig.add_axes([0, -.6, 2, .4]) for line in df_IV.iterrows(): ax_IV.plot(line[1]['time'], line[1]['response_trace'] * 1000, 'k-') ax_stim.plot(line[1]['time'], line[1]['stimulus_trace'] * 10**12, 'k-') ax_IV.set_xlabel('Time (s)') ax_IV.set_xlim([np.min(timeedges), np.max(timeedges)]) if ylimits_response: ax_IV.set_ylim([np.min(ylimits_response), np.max(ylimits_response)]) ax_IV.set_ylabel('mV') ax_IV.set_title('Response') ax_stim.set_xlabel('Time (s)') ax_stim.set_xlim([np.min(timeedges), np.max(timeedges)]) ax_stim.set_ylabel('pA') ax_stim.set_title('Stimulus') if plotRS: del key['sweep_number'] df_RS = pd.DataFrame((ephysanal.SeriesResistance() * ephysanal.SquarePulse()) & key) needed = (df_RS['square_pulse_start_time'].values > np.min(timeedges)) & (df_RS['square_pulse_start_time'].values < np.max(timeedges)) ax_RS = fig.add_axes([0, -1.2, 2, .4]) ax_RS.plot(df_RS[needed]['square_pulse_start_time'].values, df_RS[needed]['series_resistance'].values, 'ko') ax_RS.set_xlabel('Time (s)') ax_RS.set_ylabel('RS (MOhm)') ax_RS.set_xlim([np.min(timeedges), np.max(timeedges)])
min_current = -40*10**-12 #A min_pulse_time = 0.3 #s integration_window = .04 #sec for cell in cells: if len((lab.Surgery()&'subject_id = {}'.format(cell['subject_id'])).fetch('start_time'))==1: continue # if there is only one surgery, we don't care expression_time = np.diff((lab.Surgery()&'subject_id = {}'.format(cell['subject_id'])).fetch('start_time'))[0].days virus_id = (lab.Surgery.VirusInjection()&'subject_id = {}'.format(cell['subject_id'])).fetch('virus_id')[0] if virus_id == 238: virus = 'Voltron 1' elif virus_id == 240: virus = 'Voltron 2' else: virus = '??' squarepulses = ephysanal.SquarePulse()&cell&'square_pulse_amplitude < {}'.format(min_current)&'square_pulse_length > {}'.format(min_pulse_time) Rins = list() RSs = list() v0s = list() for squarepulse in squarepulses: trace = (ephys_patch.SweepResponse()&squarepulse).fetch1('response_trace') stim = (ephys_patch.SweepStimulus()&squarepulse).fetch1('stimulus_trace') sr = (ephys_patch.SweepMetadata()&squarepulse).fetch1('sample_rate') step_back = int(integration_window*sr) if step_back<squarepulse['square_pulse_start_idx'] and np.abs(np.median(stim[:step_back]))<=max_baseline_current and np.median(trace[:step_back])<max_v0: RS = float((ephysanal.SweepSeriesResistance()&squarepulse).fetch1('series_resistance')) RS_residual = float((ephysanal.SweepSeriesResistance()&squarepulse).fetch1('series_resistance_residual')) baseline_v = np.median(trace[squarepulse['square_pulse_start_idx']-step_back:squarepulse['square_pulse_start_idx']]) Rin_v = np.median(trace[squarepulse['square_pulse_end_idx']-step_back:squarepulse['square_pulse_end_idx']]) dv = Rin_v-baseline_v di = squarepulse['square_pulse_amplitude']