def evaluateFileAtThresholds(args):
    file,thresholds,dims,randOrPixel=args
    affTrue,affEst = loadAffs(file,dims)
    nExamples = (affTrue.size)/3
    if(randOrPixel=="rand"):
        pSqErr=-1
        nhood = np.eye(3)
        compTrue = connectedComponents(affTrue,nhood).astype('d',order='F')
    else:
        pSqErr=pixelSquareError(affTrue,affEst) #todo: make this inline

    err,tp,fp = (np.empty([1,len(thresholds)]) for i in range(3))

    for i in range(len(thresholds)):
        threshold = thresholds[i]
        if(randOrPixel=="rand"):
            err[0,i],tp[0,i],fp[0,i],pos,neg = randStatsForThreshold(compTrue,affEst,threshold)  # this might give an error for making pos, neg nan (if(~isnan(pos_)) pos=pos_; end)
            # print threshold,tp[0,i]
        else:
            err[0,i],tp[0,i],fp[0,i],pos,neg = pixelStatsForThreshold(affTrue,affEst,threshold) #todo: pos, neg can be taken out of the loop (put with pSqErr)

    return err,tp,fp,pos,neg,pSqErr,nExamples
from randStats import randIndex
import time

#read in data
t0 = time.clock()
dataRoot = '../testData/000'
dims = [73,73,73]
affTrue, affEst = loadAffs(dataRoot,dims)
affTrue = affTrue.astype(dtype='d',order='F')
nhood = np.eye(3)
thresh=.97
affEst = affEst.astype(dtype='d',order='F')
affEstThresh=(affEst>thresh).astype(dtype='d')

#call connected components
comp = connectedComponents(affEstThresh,nhood).astype(dtype='d',order='F')
compTrue = connectedComponents(affTrue,nhood).astype(dtype='d',order='F')

#set up data for watershed
nhood = -1*np.eye(3)
compE = np.zeros((73,73,73)).astype(dtype='d',order='F')
compT = np.zeros((73,73,73)).astype(dtype='d',order='F')
for x in range(73):
    for y in range(73):
        for z in range(73):
            compE[z,y,x]=comp[x,y,z]
            compT[z,y,x]=compTrue[x,y,z]


watershed = markerWatershed(affEst,nhood,compE,0)
stats = randIndex(compT,watershed)