s200 = pts.sample(20_000, random_state=0) # a sample for the point statistics
w8 = pdist.analysis.weights(s200, "knn", k=8) # weights for the statistics
y8 = np.log(pdist.vector.area(bld.loc[s200.index])).values # log building area
grid = xr.DataArray(np.zeros((300, 300), np.float32), dims=("y", "x"), # 1 km template around Wichita
coords={"y": 1_640_000 - 500 - 1000 * np.arange(300), "x": -250_000 + 500 + 1000 * np.arange(300)}).rio.write_crs(5070)
checks = { # name: (function, arguments, keyword arguments)
"raster.slope": (pdist.raster.slope, (win,), {}),
"raster.hillshade": (pdist.raster.hillshade, (win,), {}),
"raster.curvature": (pdist.raster.curvature, (win,), {}),
"raster.focal median 9": (pdist.raster.focal, (win, "median"), {"size": 9}),
"raster.focal std 9": (pdist.raster.focal, (win, "std"), {"size": 9}),
"raster.reclassify": (pdist.raster.reclassify, (win,), {"bins": [500, 1000, 1500]}),
"hydrology.flow_direction": (pdist.hydrology.flow_direction, (win,), {}),
"vector.area": (pdist.vector.area, (bld.iloc[:200_000],), {}),
"vector.bounds": (pdist.vector.bounds, (bld.iloc[:200_000],), {}),
"vector.sjoin points in counties": (pdist.vector.sjoin, (pts, ks), {"predicate": "within"}),
"vector.knn k=5": (pdist.vector.knn, (s200,), {"k": 5}),
"bridge.zonal_stats": (pdist.zonal_stats, (counties, dd.gp_raster("ndvi")), {"stats": ["count", "mean", "std"]}),
"bridge.extract_values": (pdist.extract_values, (dd.gp_points(), dd.gp_raster("preci")), {}),
"bridge.rasterize": (pdist.rasterize, (counties, dd.gp_raster("elev")[::10, ::10].compute()), {"column": "x"}),
"analysis.morans_i": (pdist.analysis.morans_i, (y8, w8), {"permutations": 0}),
"analysis.getis_ord_local": (pdist.analysis.getis_ord_local, (y8, w8), {}),
"analysis.kde": (pdist.analysis.kde, (s200, grid), {"bandwidth": 3000}),
}
rows = [] # one row per check
for name, (fn, args, kw) in checks.items(): # each operation
tol = dict(rtol=1e-4, atol=1e-3) if name.startswith(("raster", "analysis.kde")) else dict(rtol=1e-6, atol=1e-3) # float32 rasters; float64 tables (areas in m2)
rep = pdist.check_equivalence(fn, *args, **tol, **kw) # CPU vs GPU
rows.append({"operation": name, "equivalent": rep.ok, "largest |GPU - CPU|": rep.max_abs, "parts compared": len(rep.details)}) # row
eq = pd.DataFrame(rows).set_index("operation") # table
print("all equivalent:", bool(eq.equivalent.all())) # verdict
eq # show