Public
Edited
Aug 4, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// https://xunli.gitbook.io/jsgeoda/spatial-weights/distance-based-weights
// https://observablehq.com/d/eb57e37649725f96
// geoda = jsgeoda.New()
Insert cell
// encoder = new TextEncoder()
Insert cell
// arrayBuffer = encoder.encode(JSON.stringify(toGeoJSON(data)))
Insert cell
// dataDa = geoda.read_geojson(arrayBuffer)
Insert cell
// act = geoda.get_col(dataDa, "activity")
Insert cell
// geoda.get_numobs(dataDa)
Insert cell
// weights = geoda.getKnnWeights(dataDa, 10)
Insert cell
// redcap = geoda.skater(weights, 10, [act])
Insert cell
// new Set(redcap.clusters)
Insert cell
// activityCluster = Plot.plot({
// // color: {
// // type: "threshold",
// // scheme: "orrd",
// // domain: [0.25, 0.5, 0.75, 0.95, 0.99].map((d) => d3.quantile(activity, d))
// // },
// projection: {
// type: "orthographic",
// rotate: [30, -40]
// },
// marks: [
// Plot.geo(land, { fill: "#333", stroke: "black", strokeWidth: 0.5 }),
// Plot.graticule(),
// Plot.dot(data, {
// x: "lon",
// y: "lat",
// fill: (d, i) => redcap.clusters[i],
// r: 1
// }),
// Plot.sphere({ strokeWidth: 0.5 })
// ]
// })
Insert cell
Insert cell
activity_norm = norm(data.map((d) => d.activity))
Insert cell
lon_norm = norm(data.map((d) => d.lon))
Insert cell
lat_norm = norm(data.map((d) => d.lat))
Insert cell
time_norm = norm(data.map((d) => d.begperiod.getTime()))
Insert cell
points = Array.from({ length: data.length }).map((_, i) => [
(lon_norm[i] * w1) / 2,
(lat_norm[i] * w1) / 2,
(w2 * (activity_norm[i] * (1 - w1))) / 2,
((1 - w2) * (time_norm[i] * (1 - w1))) / 2
])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
activity = data.map((d) => d.activity)
Insert cell
world = (
await fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/land-50m.json")
).json()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
Insert cell
Insert cell
function toGeoJSON(data) {
const features = data.map((d) => ({
type: "feature",
geometry: {
type: "Point",
coordinates: [d.lon, d.lat]
},
properties: {
area_id: d.area_id,
depth: d.depth,
time: d.begperiod,
activity: d.activity
}
}));
return { type: "FeatureCollection", features: features };
}
Insert cell
Insert cell
// jsgeoda = import("https://cdn.skypack.dev/jsgeoda")
Insert cell
// import { meanshift, kernel, distance } from "@fil/mean-shift-clustering"
Insert cell
// kmeans = require("https://bundle.run/kmeans-engine@1.5.0")
Insert cell
// import("https://cdn.skypack.dev/density-clustering@1.3.0?min")
Insert cell
// https://github.com/uhho/density-clustering
clustering = require("https://bundle.run/density-clustering@1.3.0")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more