def convert(inFileOrFolder, overwrite=False, fileType=None, outputMetadata=False, outputFeedbackChannel=False, multipleGroupsPerFile=False, compression=True): """ Convert the given file to a NeuroDataWithoutBorders file using pynwb Supported fileformats: - ABF v2 files created by Clampex - DAT files created by Patchmaster v2x90 :param inFileOrFolder: path to a file or folder :param overwrite: overwrite output file, defaults to `False` :param fileType: file type to be converted, must be passed iff `inFileOrFolder` refers to a folder :param outputMetadata: output metadata of the file, helpful for debugging :param outputFeedbackChannel: Output ADC data which stems from stimulus feedback channels (ignored for DAT files) :param multipleGroupsPerFile: Write all Groups in the DAT file into one NWB file. By default we create one NWB per Group (ignored for ABF files). :param compression: Toggle compression for HDF5 datasets :return: path of the created NWB file """ if not os.path.exists(inFileOrFolder): raise ValueError(f"The file {inFileOrFolder} does not exist.") if os.path.isfile(inFileOrFolder): root, ext = os.path.splitext(inFileOrFolder) if os.path.isdir(inFileOrFolder): if not fileType: raise ValueError("Missing fileType when passing a folder") inFileOrFolder = os.path.normpath(inFileOrFolder) inFileOrFolder = os.path.realpath(inFileOrFolder) ext = fileType root = os.path.join(inFileOrFolder, "..", os.path.basename(inFileOrFolder)) outFile = root + ".nwb" if not outputMetadata and os.path.exists(outFile): if overwrite: os.remove(outFile) else: raise ValueError(f"The output file {outFile} does already exist.") if ext == ".abf": if outputMetadata: ABFConverter.outputMetadata(inFileOrFolder) else: ABFConverter(inFileOrFolder, outFile, outputFeedbackChannel=outputFeedbackChannel, compression=compression) elif ext == ".dat": if outputMetadata: DatConverter.outputMetadata(inFileOrFolder) else: DatConverter(inFileOrFolder, outFile, multipleGroupsPerFile=multipleGroupsPerFile, compression=compression) else: raise ValueError(f"The extension {ext} is currently not supported.") return outFile
df df = pd.read_csv( '/Volumes/easystore5T/data/DANDI/nwb_lizhou/recieved/lizhou_meta_denormalized.csv' ) src_dir = '/Volumes/easystore5T/data/DANDI/nwb_lizhou/recieved/*/*.abf' src_paths = glob(src_dir) overwrite = False for src_path in tqdm(list(src_paths)): #try: src_fname = os.path.split(src_path)[1] dest_fname = src_fname[:-3] + 'nwb' dest_path = '/'.join(src_path.split('/')[:6] + ['nwb', dest_fname]) abf_num = int(src_fname[:-4]) metadata = get_metadata(abf_num, df) if os.path.isfile(dest_path) and not overwrite: print('skipping {}.'.format(src_fname)) else: print('converting {}.'.format(src_fname)) kwargs = dict() if metadata is None: print('no metadata found for {}.'.format(src_fname)) else: kwargs.update(metadata=metadata) ABFConverter(src_path, dest_path, outputFeedbackChannel=True, **kwargs)