lib/redred.py
def dir_to_dict(sourceDirectory, fileRange = [0,0]):
    """ Generate a dictionary containing info from file name and data"""
    #select all files if range is [0,0]
    if fileRange == [0,0] or fileRange[1]<fileRange[0]:
        fileRange[1] = len(sourceDirectory)
        # pick scans to work on
    fileNames = os.listdir(sourceDirectory)[fileRange[0]:fileRange[1]]

    DataDict = {}
    nGood, nBad = 0,0
    for item in fileNames:
        filepath = sourceDirectory + '//' + item
        filename = os.path.basename(filepath)
        ext = os.path.splitext(filename)[-1].lower()
        #if not os.path.isdir(filepath) and
        if ext == ".mat" and not filename == 't-cal':
            DataDict[item] = file_to_dict(filepath) #returns nothing if file was not datafile.mat
            if DataDict[item]:
                nGood += 1
                DataDict[item]['data'] = import_file(filepath)
            else:
                nBad += 1
    print('Imported '+ str(nGood) + ' Files \n discarded '+ str(nBad) + ' Files')
    return(DataDict)
 Generate a dictionary containing info from file name and data
Generate a dictionary containing info from file name and data
Generate a dictionary containing info from file name and data
def dir_to_dict(sourceDirectory, fileRange = [0,0]):
    if fileRange == [0,0] or fileRange[1]<fileRange[0]:
        fileRange[1] = len(sourceDirectory)
    fileNames = os.listdir(sourceDirectory)[fileRange[0]:fileRange[1]]
    DataDict = {}
    nGood, nBad = 0,0
    for item in fileNames:
        filepath = sourceDirectory + '//' + item
        filename = os.path.basename(filepath)
        ext = os.path.splitext(filename)[-1].lower()
        if ext == ".mat" and not filename == 't-cal':
            DataDict[item] = file_to_dict(filepath) 
            if DataDict[item]:
                nGood += 1
                DataDict[item]['data'] = import_file(filepath)
            else:
                nBad += 1
    print('Imported '+ str(nGood) + ' Files \n discarded '+ str(nBad) + ' Files')
    return(DataDict)
def dir_to_dict ( sourceDirectory , fileRange = [ 0 , 0 ] ) : if fileRange == [ 0 , 0 ] or fileRange [ 1 ] < fileRange [ 0 ] : fileRange [ 1 ] = len ( sourceDirectory ) fileNames = os . listdir ( sourceDirectory ) [ fileRange [ 0 ] : fileRange [ 1 ] ] DataDict = { } nGood , nBad = 0 , 0 for item in fileNames : filepath = sourceDirectory + '//' + item filename = os . path . basename ( filepath ) ext = os . path . splitext ( filename ) [ - 1 ] . lower ( ) if ext == ".mat" and not filename == 't-cal' : DataDict [ item ] = file_to_dict ( filepath ) if DataDict [ item ] : nGood += 1 DataDict [ item ] [ 'data' ] = import_file ( filepath ) else : nBad += 1 print ( 'Imported ' + str ( nGood ) + ' Files \n discarded ' + str ( nBad ) + ' Files' ) return ( DataDict )
Generate a dictionary containing info from file name and data
Generate a dictionary containing info from file name and data
""" Generate a dictionary containing info from file name and data""" #select all files if range is [0,0] # pick scans to work on #if not os.path.isdir(filepath) and #returns nothing if file was not datafile.mat
sourceDirectory
fileRange