(subdf['rf_{}_off_peak_z'.format(response_dir)] >= analysis_params['rf_z_thr_abs'])].reset_index() if len(s2_df) > 0: s2_grp = save_f.create_group('{}_{}_{}_{}_ONOFF'.format(date, mid, plane_n, response_dir)) s1_on_grp = save_f.create_group('{}_{}_{}_{}_ON'.format(date, mid, plane_n, response_dir)) s1_off_grp = save_f.create_group('{}_{}_{}_{}_OFF'.format(date, mid, plane_n, response_dir)) for roi_i, roi_row in s2_df.iterrows(): print('\t s2 receptive fields, {}, {} / {} ...'.format(roi_row['roi_n'], roi_i + 1, len(s2_df))) if response_dir == 'pos': _, _, _, srf_on, srf_off, _, _, _, _, _, _, _, _, \ _ = dt.get_everything_from_axon(nwb_f=nwb_f, clu_f=clu_f, plane_n=plane_n, axon_n=roi_row['roi_n'], params=analysis_params) _, rf_on_new = dt.get_rf_properties(srf=srf_on, polarity='positive', sigma=analysis_params['gaussian_filter_sigma_rf'], interpolate_rate=analysis_params['interpolate_rate_rf'], z_thr_abs=analysis_params['rf_z_thr_abs'], z_thr_rel=analysis_params['rf_z_thr_rel']) _, rf_off_new = dt.get_rf_properties(srf=srf_off, polarity='positive', sigma=analysis_params['gaussian_filter_sigma_rf'], interpolate_rate=analysis_params['interpolate_rate_rf'], z_thr_abs=analysis_params['rf_z_thr_abs'],
def process_one_nwb_for_multi_thread(inputs): nwb_path, df_folder, clu_folder, params, columns, save_folder, t0, nwb_i, nwb_f_num, is_overwrite = inputs nwb_fn = os.path.splitext(os.path.split(nwb_path)[1])[0] date, mid, _, _ = nwb_fn.split('_') nwb_f = h5py.File(nwb_path, 'r') plane_ns = dt.get_plane_ns(nwb_f=nwb_f) plane_ns.sort() for plane_n in plane_ns: print('\tt: {:5.0f} minutes, processing {}, {} / {}, {} ...'.format( (time.time() - t0) / 60., nwb_fn, nwb_i + 1, nwb_f_num, plane_n)) roi_df_fn = '{}_{}_{}.csv'.format(date, mid, plane_n) roi_df = pd.read_csv(os.path.join(df_folder, roi_df_fn)) clu_fn = '{}_{}_{}_axon_grouping.hdf5'.format(date, mid, plane_n) clu_f = h5py.File(os.path.join(clu_folder, clu_fn), 'r') axon_ns = clu_f['axons'].keys() axon_ns.sort() axon_df = pd.DataFrame(np.nan, index=range(len(axon_ns)), columns=columns) for axon_i, axon_n in enumerate(axon_ns): roi_lst = clu_f['axons/{}'.format(axon_n)].value if len(roi_lst) == 1: curr_roi_df = roi_df[roi_df['roi_n'] == roi_lst[0]].reset_index() for col in columns: axon_df.loc[axon_i, col] = curr_roi_df.loc[0, col] axon_df.loc[axon_i, 'roi_n'] = axon_n else: axon_properties, _, _, _, _, _, _, _, _, _, _, _, _, _ = \ dt.get_everything_from_axon(nwb_f=nwb_f, clu_f=clu_f, plane_n=plane_n, axon_n=axon_n, params=params, verbose=False) for rp_name, rp_value in axon_properties.items(): axon_df.loc[axon_i, rp_name] = rp_value save_path = os.path.join(save_folder, '{}_{}_{}.csv'.format(date, mid, plane_n)) if os.path.isfile(save_path): if is_overwrite: os.remove(save_path) axon_df.to_csv(save_path) else: raise IOError( 'Axon dataframe file already exists. \npath: {}'.format( save_path)) else: axon_df.to_csv(save_path)