def print_tree(event, neighborhood, dataset, wave, c_0, balance, alpha):
    treefile = 'results/' + '_'.join(
        [event, neighborhood, dataset, wave, 'c_0=' + str(c_0), 'balance=' + balance, 'alpha=' + alpha]) + '.tree'
    tree = TreeNode('dummy')
    with open(treefile) as f:
        tree.load(f)
    print str(tree)
def stuff():
    #  events = ['FL','SG','AR','CH']
    #  events = ['SG']
    events = ["AR"]
    #  events = ['FL','SG','FI','CH','AR','SS']
    #  neighborhoods = ['rook','queen','rooktemp']
    #  neighborhoods = ['rook','rooktemp','rooktemplong']
    neighborhoods = ["rook"]
    datasets = ["1DAY"]

    thetas = [0.7]  # theta is the classification parameter

    grid = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
    alphas = [x for x in itertools.product(grid, grid) if sum(x) <= 1]
    #  alphas = [(0.3,0.3),(0.6,0.3),(0.3,0.6)]
    #  alphas = [(0.3,0.3)]

    #  waves = [['0193'],['0171'],['0094']]
    waves = [["0193"]]
    #  balances = ['Mirror','Duplication','Random']
    balances = ["Mirror"]
    c_0Dict = dict([(("AR", "1DAY"), 40), (("SG", "3DAYDEMO"), 9), (("AR", "3DAYDEMO"), 111)])
    X = [x for x in itertools.product(events, neighborhoods, datasets, waves, balances, alphas)]
    for event, neighborhood, dataset, wave, balance, alpha in X:
        alphastr = str(alpha).replace(",", "-").replace("(", "[").replace(")", "]").replace(" ", "")
        wavestr = wave[0]
        c_0 = c_0Dict[(event, dataset)]
        treefile = (
            "results/"
            + "_".join(
                [event, neighborhood, dataset, wavestr, "c_0=" + str(c_0), "balance=" + balance, "alpha=" + alphastr]
            )
            + ".tree"
        )
        Tree = TreeNode("dummy")
        with open(treefile) as f:
            Tree.load(f)

        #  print str(Tree)
        print event, neighborhood, dataset, wave, balance, alpha
        S = Tree.size()
        print "size:", S
        print "balance:", Tree.balance()
        print "splits:", Tree.total_splits_evaluated()
        TBSR = Tree.total_best_split_runtime()
        print "total time:", TBSR
        print "avg time:", TBSR / ((S - 1) / 2)
        print
def stuff():
  treefileA = 'results/AR_rook_1DAY_0193_c_0=40_balance=Mirror_alpha=[0.0-0.0].tree'
  treefileB = 'hopefullyslowerresults/AR_rook_1DAY_0193_c_0=40_balance=Mirror_alpha=[0.0-0.0].tree'
  for treefile in [treefileA,treefileB]:
    Tree = TreeNode('dummy')
    with open(treefile) as f:
     Tree.load(f)
    print treefile
    S = Tree.size()
    print 'size:', S
    print 'balance:', Tree.balance()
    print 'splits:', Tree.total_splits_evaluated()
    TBSR = Tree.total_best_split_runtime()
    print 'total time:', TBSR
    print 'avg time:', TBSR/((S-1)/2)
    print
 theta = 0.7
 alphaSpatial = '[0.3-0.0]'
 alphaSpatiotemp = '0.3-0.4]'
 alphaNonSpatial = '[0.0-0.0]'
 c_0 = cref[e]
 eventClass = e
 dataset = d
 print eventClass,dataset
 headers,matches = SOLARGenImageList.image_event_matches(dataset=d,waves = w)
 print 'matches calculated'
 treefileSpatial = "results/"+"_".join([str(e),str(n),str(d),"-".join(w),'c_0='+str(c_0),'balance='+str(b),'alpha='+str(alphaSpatial)])+".tree"
 treefileNonSpatial = "results/"+"_".join([str(e),str(n),str(d),"-".join(w),'c_0='+str(c_0),'balance='+str(b),'alpha='+str(alphaNonSpatial)])+".tree"
 treeSpatial = TreeNode('dummy')
 treeNonSpatial = TreeNode('dummy')
 with open(treefileSpatial) as f:
   treeSpatial.load(f)
 with open(treefileNonSpatial) as f:
   treeNonSpatial.load(f)
 S_train,S_test, = read_data(e,n,d,w,b) # read the data set
 cells_train, adj = S_train
 cells_test, adj_test = S_test
 counter = 0
 for x in sorted(matches.keys()): # for each image of the data set
   paramsFilename = x[0]
   imageFilename = paramsFilename[:-4]+'_th.png'
   ISpatial = m.imread(imageFilename) # read the image
   INonSpatial = ISpatial.copy()
   outputname = os.path.join(outputFolder,e,os.path.basename(imageFilename)[:-4]+'_'+e+'_'+d+'.png')
   cells_testWeWant = [x for x in cells_test if x['id'][3][0] == paramsFilename] # get the test cells tied to this image
   for x in range(2):
     if x == 0: