def runKKFeaturesFromFiles(name, files, nProbes, featuresPerProbe, featuresTim, featuresMask ): """run (as a simple script) all the steps necessary to prepare for running KK""" fetFeatures = [] maskFeatures = {} fM = featuresMask.keys() for c in range(1, nProbes+1): for f in featuresPerProbe: fetFeatures.append(f + str(c)) for f in fM: maskFeatures[f + str(c)] = featuresMask[f] fetFeatures.append('Time in File (1/10000 s)') fetFeatures = tuple(fetFeatures) print fetFeatures featuresToCompute = [] featuresToCompute.extend(fetFeatures) featuresToCompute.extend(featuresTim) #TODO add mean waveforms # create data file handler objects spikeFiles = [] if files[-3:] == 'smr': fileType = 'son' else: fileType = 'nlynx' if fileType == 'son': for fname in files: spikeFiles.append(sonIO.SONfile(fname)) elif fileType == 'nlynx': for fname in files: spikeFiles.append(neuralynx_io.TTFile(fname)) if fileType == 'son': adcMarkChans = spikeFiles[0].channelsOfKind('ADCMarkerChannel') elif fileType == 'nlynx': adcMarkChans = (0,) for chan in adcMarkChans: fname = name + ".peak.1" #principal components file name needed # by klusters spkname = name + ".spk.1" # spike waveform file, needed by # klusters parname = name + ".xml" timname = name + ".tim.1" if fileType == 'son': ttFiles = [] for sp in spikeFiles: ttFiles.append(sonIO.TTFile(sp)) else: ttFiles = spikeFiles computer = computeSpikeFeatures.FeatureComputer(ttFiles, spkname, params=None, interleave=120) computer.setMaskFromFeatures(maskFeatures) computer.computeFeatures(featuresToCompute) features = computer.computedFeatures computeSpikeFeatures.writeFetFile(fname, features, fetFeatures) computeSpikeFeatures.writeTimFile(timname, features) computeSpikeFeatures.makeXMLParFile(spikeFiles, parname, len(featuresPerProbe))
def getAvWaveform(files, clufile, clusterIdx, nProbes, features): """run (as a simple script) all the steps necessary to prepare for running KK""" featuresToCompute = [] for c in range(1, nProbes + 1): for f in features: featuresToCompute.append(f + str(c)) # create data file handler objects spikeFiles = [] if files[0][-3:] == 'smr': fileType = 'son' elif files[0][-5:-2] == 'spk': fileType = 'klusters' else: fileType = 'nlynx' if fileType == 'son': for fname in files: spikeFiles.append(sonIO.SONfile(fname)) elif fileType == 'nlynx': for fname in files: spikeFiles.append(neuralynx_io.TTFile(fname)) elif fileType == 'klusters': print('klusters_io') for fname in files: spikeFiles.append(klusters_io.TTFile(fname)) if fileType == 'son': adcMarkChans = spikeFiles[0].channelsOfKind('ADCMarkerChannel') elif fileType == 'nlynx': adcMarkChans = (0, ) name = files[0][:-4] name = name + "_c_" + clusterIdx + 'wv.mat' print name outfh = pymatfile.pymatfile(name, 'w') if fileType == 'son': ttFiles = [] for sp in spikeFiles: ttFiles.append(sonIO.TTFile(sp)) else: ttFiles = spikeFiles print(ttFiles) computer = computeSpikeFeatures.FeatureComputer(ttFiles, spkname=None, params=None, interleave=120) computer.setMaskFromCluFile(clufile, clusterIdx) computer.computeFeatures(featuresToCompute) features = computer.computedFeatures a = array([]) for f in featuresToCompute: fg = reshape(features[f], (1, len(features[f]))) if len(a): a = concatenate([a, fg], 0) else: a = fg outfh.writeItem(a, 'waveformstd') outfh.close()
def runKKFeaturesFromFiles(name, files, nProbes, featuresPerProbe, featuresTim, featuresMask, featuresMat=None, output='KK', extFeatures=None, realignPeaks=False, shiftTimes=None, startTime=None, stopTime=None): """run (as a simple script) all the steps necessary to prepare for running KK""" fetFeatures = [] maskFeatures = {} if featuresMask is not None: fM = featuresMask.keys() else: fM = [] for c in range(1, nProbes + 1): for f in featuresPerProbe: fetFeatures.append(f + str(c)) for f in fM: if f[-2:] == ': ': for c in range(1, nProbes + 1): maskFeatures[f + str(c)] = featuresMask[f] else: maskFeatures[f] = featuresMask[f] if output == 'KK': fetFeatures.append('Time (Klusters Units)') fetFeatures = tuple(fetFeatures) # print fetFeatures featuresToCompute = [] featuresToCompute.extend(fetFeatures) if output == 'KK': featuresToCompute.extend(featuresTim) #TODO add mean waveforms # create data file handler objects spikeFiles = [] fileType = None if files[0][-3:] == 'smr': fileType = 'son' elif files[0][-3:] == 'ntt': fileType = 'nlynx' elif files[0][-3:] == 'spk': fileType = 'KK' if not fileType: raise ValueError('unrecognized file name ' + files) if fileType == 'son': for fname in files: spikeFiles.append(sonIO.SONfile(fname)) elif fileType == 'nlynx': for fname in files: spikeFiles.append(neuralynx_io.TTFile(fname)) elif fileType == 'KK': for fname in files: spikeFiles.append(klusters_io.TTfile(fname)) if fileType == 'son': adcMarkChans = spikeFiles[0].channelsOfKind('ADCMarkerChannel') elif fileType == 'nlynx' or fileType == 'KK': adcMarkChans = (0, ) for chan in adcMarkChans: spkname = None if output == 'KK': fname = name + ".fet.1" #principal components file name needed # by klusters spkname = name + ".spk.1" # spike waveform file, needed by # klusters parname = name + ".xml" timname = name + ".tim.1" elif output == 'mat': import pymatfile matFname = name + '_features.mat' matf = pymatfile.pymatfile(matFname, 'w') if fileType == 'son': ttFiles = [] for sp in spikeFiles: ttFiles.append(sonIO.TTFile(sp)) else: ttFiles = spikeFiles computer = computeSpikeFeatures.FeatureComputer(ttFiles, spkname, params=None, interleave=120, shiftTimes=shiftTimes, startTime=startTime, stopTime=stopTime) computer.setMaskFromFeatures(maskFeatures) computer.computeFeatures(featuresToCompute, realignPeaks) features = computer.computedFeatures if output == 'KK': computeSpikeFeatures.writeFetFile(fname, features, fetFeatures) computeSpikeFeatures.writeTimFile(timname, features) computeSpikeFeatures.makeXMLParFile(spikeFiles, parname, len(featuresPerProbe), extFeatures) elif output == 'mat': for key in fetFeatures: value = features[key] # print shape(value) matVarname = re.sub(': ', '_', key) matVarname = re.sub(' ', '', matVarname) # print matVarname matf.writeItem(value.astype(float64), matVarname) matf.close()