def test_dag_search(conf, method, area = None): import cg_dag if method is None: method = conf.get("search", "method") src_dir = conf.get("dag", "output_dir") if area is None: l_area = pcresult.result_areas(conf) else: l_area = [area] for area in l_area: l_r = pcresult.results_in_area(conf, src_dir, area) result = [] for r in l_r: if method == "log": result = similar_block_log(conf, r.top_dt, r.end_dt, r.area, ignore_same = True) elif method in ("dag_ed", "dag_mcs"): result = cg_dag.similar_block_dag(conf, r.top_dt, r.end_dt, r.area, method, ignore_same = True) else: raise NotImplementedError print r.cond_str() if len(result) > 10: result = ex_sorted(result, key = lambda x: x[1], reverse = False)[:10] for r_found, val in result: print val, r_found.cond_str() print
def heatmap(conf, method, area, fn): def result2data(result, l_label): d_temp = {} for r, dist in result: d_temp[r.get_fn()] = dist return [d_temp[label] for label in l_label] import cg_dag if method is None: method = conf.get("search", "method") if area is None: area = "all" src_dir = conf.get("dag", "output_dir") l_r = pcresult.results_in_area(conf, src_dir, area) l_label = [r.get_fn() for r in l_r] l_result = [] for r in l_r: if method == "log": result = similar_block_log(conf, r.top_dt, r.end_dt, r.area, ignore_same = False) elif method in ("dag_ed", "dag_mcs"): result = cg_dag.similar_block_dag(conf, r.top_dt, r.end_dt, r.area, method, ignore_same = False) else: raise NotImplementedError l_result.append(result2data(result, l_label)) # replace None to max value of whole result mval = max([max(result) for result in l_result]) data = np.array([[mval if i is None else i for i in result] for result in l_result]) # data = np.array(l_result) n = len(l_r) assert data.shape == (n, n) x, y = np.meshgrid(np.arange(n + 1), np.arange(n + 1)) explot.dump(fn + ".temp", (x, y, data)) import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt cm = explot.generate_cmap(["orangered", "white"]) plt.pcolor(x, y, data, cmap = cm) plt.colorbar() plt.savefig(fn)