def set_electrode_areas(proj, el_in_gc={}): exp_info = proj._exp_info for i, row in exp_info.iterrows(): name = row['exp_name'] if name not in el_in_gc.keys(): continue exp = blechpy.load_experiment(row['exp_dir']) ingc = el_in_gc[name] if ingc is 'right': el = np.arange(8, 24) elif ingc is 'left': el = np.concatenate([np.arange(0, 8), np.arange(24, 32)]) elif ingc is 'none': el = np.arange(0, 32) else: el = None for rec in exp.recording_dirs: dat = load_dataset(rec) print('Fixing %s...' % dat.data_name) em = dat.electrode_mapping em['area'] = 'GC' if el is not None: em.loc[em['Channel'].isin(el), 'area'] = 'STR' h5io.write_electrode_map_to_h5(dat.h5_file, em) dat.save() return
def clustering(exp): # TODO Actually I now cluster 1 recording at a time if isinstance(exp, str): fd = exp exp = blechpy.load_experiment(fd) if exp is None: exp = blechpy.experiment(fd) dat = blechpy.load_dataset(exp.recording_dirs[0]) clustering_params = dat.clustering_params.copy() clustering_params['clustering_params']['Max Number of Clusters'] = 15 exp.cluster_spikes(custom_params=clustering_params, umap=True) for fd in exp.recording_dirs: dat = blechpy.load_dataset(fd) dat.cleanup_clustering()
def fix_palatability(proj, pal_map=None): '''Goes through all datasets in project and fixes palatability rankings ''' if pal_map is None: pal_map = PAL_MAP exp_dirs = proj._exp_info.exp_dir.to_list() for exp_dir in tqdm(exp_dirs): exp = blechpy.load_experiment(exp_dir) for rd in exp.recording_dirs: dat = load_dataset(rd) dat.dig_in_mapping[ 'palatability_rank'] = dat.dig_in_mapping.name.map(pal_map) h5io.write_digital_map_to_h5(dat.h5_file, dat.dig_in_mapping, 'in') dat.save()
def get_all_units(proj): # Columns: # - exp_name, exp_group, rec_name, rec_group, rec_dir, unit_num, # - electrode, area, single, unit_type all_units = pd.DataFrame(columns=[ 'exp_name', 'exp_group', 'rec_name', 'rec_group', 'rec_dir', 'unit_name', 'unit_num', 'electrode', 'area', 'single_unit', 'regular_spiking', 'fast_spiking' ]) for i, row in proj._exp_info.iterrows(): exp_name = row['exp_name'] exp_group = row['exp_group'] exp_dir = row['exp_dir'] exp = blechpy.load_experiment(exp_dir) for rec_name, rec_dir in exp.rec_labels.items(): if 'preCTA' in rec_name: rec_group = 'preCTA' elif 'postCTA' in rec_name: rec_group = 'postCTA' elif 'Train' in rec_name: rec_group = 'ctaTrain' elif 'Test' in rec_name: rec_group = 'ctaTest' else: # TODO: Make more elegant, ask for input raise ValueError('Rec %s does not fit into a group' % rec_name) dat = load_dataset(rec_dir) units = dat.get_unit_table().copy() units['exp_name'] = exp_name units['exp_group'] = exp_group units['rec_name'] = rec_name units['rec_group'] = rec_group units['rec_dir'] = rec_dir em = dat.electrode_mapping.copy().set_index('Electrode') units['area'] = units['electrode'].map(em['area']) units = units[all_units.columns] all_units = all_units.append(units).reset_index(drop=True) return all_units
def exp_name(ed): exp = load_experiment(ed) return exp.data_name