def draw_network_graph(data_files: Dict[int, File], params: MotionParams, threshold: int = 16000): """Draw neuron functional connection for each session, with neurons colored by the last session. Args: data_files: {day_id: int, data_file: File} params: classify_cells need ["quiet_var", "window_size", "event_thres", "pre_time"] threshold: threshold for motion_corr, single linked cluster distance """ last_day = data_files[max(data_files.keys())] neurons = common_axis([DataFrame.load(x['spike']) for x in data_files.values()]) neuron_rate = last_day.attrs['frame_rate'] final_corr_mat = noise_autocorrelation(load_mat(last_day['response']), neurons[-1], neuron_rate) categories = classify_cells(motion_corr(last_day, neurons[-1], neuron_rate, threshold, params), 0.001) layout = corr_graph.get_layout(final_corr_mat, neurons[-1].axes[0]) for (day_id, data_file), neuron in zip(data_files.items(), neurons): corr_mat = noise_autocorrelation(load_mat(data_file['response']), neuron, neuron_rate) with Figure(join(img_folder, f"network-day-{day_id:02d}.svg")) as ax: corr_graph.corr_plot(ax[0], corr_mat, categories, neuron.axes[0], layout=layout) print('done')
def draw_classify_neurons(data_file: File, neuron_ids: Optional[np.ndarray] = None): lever = load_mat(data_file['response']) neuron = DataFrame.load(data_file['spike']) if neuron_ids is not None: neuron = neuron[search_ar(neuron_ids, neuron.axes[0]), :] neuron_rate = data_file.attrs['frame_rate'] corr = motion_corr(lever, neuron, neuron_rate, 16000, motion_params) good, bad, anti = [corr[x, 0] for x in classify_cells(corr, 0.001)] with Figure(join(img_folder, "good_unrelated_cmp.svg"), (4, 6)) as ax: ax[0].bar((0, 1), [good.mean(), np.r_[bad, anti].mean()], yerr=[_sem(good), _sem(np.r_[bad, anti])])
def draw_neuron_corr(data_files: Dict[int, File], params: MotionParams, fov_id: str = None): neurons = common_axis([DataFrame.load(x['spike']) for x in data_files.values()]) last_day = max(data_files.keys()) lever = load_mat(data_files[last_day]['response']) neuron_rate = data_files[last_day].attrs['frame_rate'] good, bad, anti = classify_cells(motion_corr( lever, neurons[-1], neuron_rate, 16000, params), 0.001) result_list = list() for (day, data_file), neuron in zip(data_files.items(), neurons): lever.center_on('motion') # type: ignore motion_neurons = fold_by(neuron, lever, neuron_rate, True) result_list.append([reliability(motion_neuron) for motion_neuron in motion_neurons.values]) result = np.array(result_list) with Figure(join(img_folder, ("neuron_corr.svg" if fov_id is None else f"{fov_id}.svg"))) as ax: ax[0].plot(list(data_files.keys()), result[:, good])