def make(self, key): # fetch behavior and ephys sample rates fs_beh = int((acquisition.BehaviorRecording & key).fetch1('behavior_recording_sample_rate')) fs_ephys = int((acquisition.EphysRecording & key).fetch1('ephys_recording_sample_rate')) # fetch condition time (behavior time base) t_beh = (pacman_acquisition.Behavior.Condition & key).fetch1('condition_time') n_samples = len(t_beh) # make condition time in ephys time base t_ephys, _ = pacman_acquisition.ConditionParams.target_force_profile( key['condition_id'], fs_ephys) # fetch spike rasters (ephys time base) spike_raster_keys = (NeuronSpikeRaster & key).fetch(as_dict=True) # rebin spike raster to behavior time base time_bin_edges = np.append( t_beh, t_beh[-1] + (1 + np.arange(2)) / fs_beh) - 1 / (2 * fs_beh) spike_bins = [np.digitize(t_ephys[spike_raster_key['neuron_spike_raster']], time_bin_edges) - 1 \ for spike_raster_key in spike_raster_keys] spike_bins = [b[(b >= 0) & (b < len(t_beh))] for b in spike_bins] for spike_raster_key, spk_bins in zip(spike_raster_keys, spike_bins): spike_raster_key['neuron_spike_raster'] = np.zeros(n_samples, dtype=bool) spike_raster_key['neuron_spike_raster'][spk_bins] = 1 # get filter kernel filter_key = (processing.Filter & (pacman_processing.FilterParams & key)).fetch1('KEY') filter_parts = datajointutils.get_parts(processing.Filter, context=inspect.currentframe()) filter_rel = next(part for part in filter_parts if part & filter_key) # filter rebinned spike raster neuron_rate_keys = spike_raster_keys.copy() [ neuron_rate_key.update( filter_params_id=key['filter_params_id'], neuron_rate=fs_beh * filter_rel().filt( neuron_rate_key['neuron_spike_raster'], fs_beh)) for neuron_rate_key in neuron_rate_keys ] # remove spike rasters [ neuron_rate_key.pop('neuron_spike_raster') for neuron_rate_key in neuron_rate_keys ] # insert neuron rates self.insert(neuron_rate_keys, skip_duplicates=True)
def proj_rank(self): """Project rank in all child target tables and joins with master.""" target_children = datajointutils.get_parts(ConditionParams.Target) target_ranks = [ dj.U('condition_id', 'condition_rank') & (x & self).proj_rank() for x in target_children ] ranked_self = reduce(lambda x, y: x + y, target_ranks) return ranked_self
def proj_label(self, n_sigfigs: int = 4): """Project label in all child target tables and joins with master.""" target_children = datajointutils.get_parts(ConditionParams.Target) target_labels = [ dj.U('condition_id', 'condition_label') & (x & self).proj_label(n_sigfigs=n_sigfigs) for x in target_children ] labeled_self = reduce(lambda x, y: x + y, target_labels) return labeled_self
def make(self, key): # trial source trial_source = (pacman_processing.BehaviorTrialAlignment & 'valid_alignment') \ * pacman_processing.FilterParams & key # convert raw force signal to Newtons trial_rel = pacman_acquisition.Behavior.Trial & trial_source force_data = trial_rel.process_force(data_type='raw', apply_filter=False, keep_keys=True) # get filter kernel filter_key = (processing.Filter & (pacman_processing.FilterParams & key)).fetch1('KEY') filter_parts = datajointutils.get_parts(processing.Filter, context=inspect.currentframe()) filter_rel = next(part for part in filter_parts if part & filter_key) # filter raw data fs = (acquisition.BehaviorRecording & key).fetch1('behavior_recording_sample_rate') [ frc.update(force_filt_offline=filter_rel().filt( frc['force_raw_online'], fs)) for frc in force_data ] # fetch alignment indices and cast as integers behavior_alignment = (trial_source).fetch('behavior_alignment', order_by='trial') behavior_alignment = list( map(lambda x: x.astype(int), behavior_alignment)) # append key and align raw and filtered forces [ frc.update(force_raw=frc['force_raw_online'][align_idx], force_filt=frc['force_filt_offline'][align_idx]) for frc, align_idx in zip(force_data, behavior_alignment) ] # pop pre-aligned data for f_key in ['force_raw_online', 'force_filt_offline']: [frc.pop(f_key) for frc in force_data] # merge key with force data key = [dict(key, **frc) for frc in force_data] # insert aligned forces self.insert(key)
def make(self, key): # fetch ephys sample rates fs_ephys = int((acquisition.EphysRecording & key).fetch1('ephys_recording_sample_rate')) # fetch condition time (behavior time base) t_beh = (pacman_acquisition.Behavior.Condition & key).fetch1('condition_time') # make condition time in ephys time base t_ephys, _ = pacman_acquisition.ConditionParams.target_force_profile(key['condition_id'], fs_ephys) # fetch raw emg data emg_attributes = (Emg & key).fetch(as_dict=True) # highpass filter and rectify raw emg signals [emg_attr.update(emg_envelope=abs(processing.Filter.Butterworth().filt(emg_attr['emg_signal'], fs_ephys, order=2, low_cut=40))) for emg_attr in emg_attributes]; # remove raw emg signal [emg_attr.pop('emg_signal') for emg_attr in emg_attributes]; # get filter kernel filter_key = (processing.Filter & (pacman_processing.FilterParams & key)).fetch1('KEY') filter_parts = datajointutils.get_parts(processing.Filter, context=inspect.currentframe()) filter_rel = next(part for part in filter_parts if part & filter_key) # smooth rectified emg signals to construct envelope and remove [emg_attr.update( filter_params_id=key['filter_params_id'], emg_envelope=filter_rel().filt(emg_attr['emg_envelope'], fs_ephys) ) for emg_attr in emg_attributes]; # resample emg to behavior time base [emg_attr.update( emg_envelope=np.interp(t_beh, t_ephys, emg_attr['emg_envelope']) ) for emg_attr in emg_attributes]; # insert emg envelopes self.insert(emg_attributes)