def test_radial_profiles(): arr = random_periodic_upsample(128, 16, seed=0) mask = np.zeros(arr.shape, dtype=np.bool_) arr_x = vcalc.cderivative(arr, 'X_DIR') arr_y = vcalc.cderivative(arr, 'Y_DIR') arr_div = np.sqrt(arr_x**2 + arr_y**2) surf = _cp.TopoSurface(arr) rprofs = radial_profiles(surf, threshold=25, expand_regions=1, other_arr=arr_div, mask=mask) arr[mask] = 2 * arr.max() pl.imshow(arr, interpolation='nearest') pl.figure() pl.imshow(arr_div) pl.figure() pl.hold(True) linreg_xy = ([], []) for minmax, (rprof, region) in rprofs.items(): # minmax_flux = arr_div[minmax] pts, fluxes, avg_fluxes, avg_fluxes_errs, avg_dists, avg_dists_errs = \ zip(*rprof) linreg_xy[0].extend(fluxes) linreg_xy[1].extend(avg_fluxes) # fluxes = np.abs(np.array(fluxes) - minmax_flux) # avg_fluxes = np.abs(np.array(avg_fluxes) - minmax_flux) # pl.plot(avg_dists, avg_fluxes, 'd-') pl.plot(avg_dists, avg_fluxes, 'd-') pl.grid() slope, intercept, rval, pval, stderr = stats.linregress(*linreg_xy) print print "slope: %f" % slope print "intercept: %f" % intercept print "rval: %f" % rval print "pval: %f" % pval print "stderr: %f" % stderr import pdb; pdb.set_trace()
def test_arr_full(self): arr = random_periodic_upsample(self.NN, 4, seed=1) for _ in range(4): _set_nbr_height_equal(arr) mesh = ct.make_mesh(arr) def height_func(n): return (arr[n], n) def region_func(r): hs = [height_func(p) for p in r] return max(hs)[0] - min(hs)[0] def region_area_func(r): return len(r) contour_tree = ct.contour_tree(mesh, height_func) def remove_edge_cb(region, interior, leaf): h = height_func(interior)[0] for pt in region: arr[pt] = h ct.prune_regions(contour_tree, region_func=region_area_func, # threshold=(arr.max()-arr.min())/4.0, threshold=3, remove_edge_cb=remove_edge_cb) cpts = ct.critical_points(contour_tree) peaks = cpts.peaks passes = cpts.passes pits = cpts.pits print "peaks + pits - passes = %d" % (len(peaks) + len(pits) - len(passes)) print "len(crit_pts) = %d" % (len(peaks) + len(pits) + len(passes)) print 'tot points covered: %d' % len(contour_tree) coverage = set() regions = ct.get_regions(contour_tree) for r in regions.values(): coverage.update(r) eq_(len(coverage), arr.size) if 0: vis(arr, height_func=height_func, crit_pts=cpts, regions=regions)