def write_sorting(sorting: SortingExtractor, save_path: PathType): # if multiple groups, use the NeuroscopeMultiSortingExtactor write function if 'group' in sorting.get_shared_unit_property_names(): NeuroscopeMultiSortingExtractor.write_sorting(sorting, save_path) else: save_path.mkdir(parents=True, exist_ok=True) if save_path.suffix == '': sorting_name = save_path.name else: sorting_name = save_path.stem xml_name = sorting_name save_xml_filepath = save_path / (str(xml_name) + '.xml') # create parameters file if none exists if save_xml_filepath.is_file(): raise FileExistsError(f'{save_xml_filepath} already exists!') xml_root = et.Element('xml') et.SubElement(xml_root, 'acquisitionSystem') et.SubElement(xml_root.find('acquisitionSystem'), 'samplingRate') xml_root.find('acquisitionSystem').find('samplingRate').text = str( sorting.get_sampling_frequency()) et.ElementTree(xml_root).write(str(save_xml_filepath.absolute()), pretty_print=True) # Create and save .res and .clu files from the current sorting object save_res = save_path / f'{sorting_name}.res' save_clu = save_path / f'{sorting_name}.clu' res, clu = _extract_res_clu_arrays(sorting) np.savetxt(save_res, res, fmt='%i') np.savetxt(save_clu, clu, fmt='%i')
def write_sorting(sorting: SortingExtractor, save_path: PathType): # if multiple groups, use the NeuroscopeMultiSortingExtactor write function if 'group' in sorting.get_shared_unit_property_names(): NeuroscopeMultiSortingExtractor.write_sorting(sorting, save_path) else: if not save_path.is_dir(): os.makedirs(save_path) if save_path.suffix == '': sorting_name = save_path.name else: sorting_name = save_path.stem xml_name = sorting_name save_xml_filepath = save_path / (str(xml_name) + '.xml') # create parameters file if none exists if save_xml_filepath.is_file(): raise FileExistsError(f'{save_xml_filepath} already exists!') soup = BeautifulSoup("", 'xml') new_tag = soup.new_tag('samplingrate') new_tag.string = str(sorting.get_sampling_frequency()) soup.append(new_tag) # write parameters file with save_xml_filepath.open("w") as f: f.write(str(soup)) # Create and save .res and .clu files from the current sorting object save_res = save_path / f'{sorting_name}.res' save_clu = save_path / f'{sorting_name}.clu' res, clu = _extract_res_clu_arrays(sorting) np.savetxt(save_res, res, fmt='%i') np.savetxt(save_clu, clu, fmt='%i')