Public
Edited
Nov 3, 2023
2 stars
Insert cell
Insert cell
Insert cell
ca55 = FileAttachment("ca55-south.csv").csv({ typed: true })
Insert cell
Insert cell
Plot.contour(ca55, {
x: "LONGITUDE",
y: "LATITUDE",
fill: "MAG_IGRF90",
interpolate: "barycentric",
blur: 2
}).plot({
color: { type: "diverging" }
})
Insert cell
Insert cell
m = 200
Insert cell
n = 150
Insert cell
Insert cell
x = d3.scaleLinear(
d3.extent(ca55, (d) => d.LONGITUDE),
[0, m - 1]
)
Insert cell
X = ca55.map((d) => x(d.LONGITUDE))
Insert cell
y = d3.scaleLinear(
d3.extent(ca55, (d) => d.LATITUDE),
[n - 1, 0] // 🎃 reversed because latitude is pointing UP, and SVG is pointing down.
)
Insert cell
Y = ca55.map((d) => y(d.LATITUDE))
Insert cell
V = ca55.map((d) => d.MAG_IGRF90)
Insert cell
Insert cell
gridded = Plot.interpolatorBarycentric()(d3.range(V.length), m, n, X, Y, V)
Insert cell
Insert cell
Insert cell
blurred = d3.blur2({ width: m, height: n, data: gridded }, 1)
Insert cell
Insert cell
contoursg = d3.contours().size([m, n])(blurred.data)
Insert cell
Insert cell
contours = contoursg.map(({ coordinates, ...rest }) => ({
coordinates: coordinates.map((polygon) =>
polygon.map((ring) => ring.map((d) => [x.invert(d[0]), y.invert(d[1])]))
),
...rest
}))
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more