Published
Edited
Sep 21, 2020
11 stars
Insert cell
Insert cell
{
let canvas = d3.create("canvas").node()
canvas.width = width
canvas.height = height
let ctx = canvas.getContext("2d")
let path = d3.geoPath(projection)
.context(ctx)

ctx.strokeStyle = "black"
ctx.beginPath()
path(states)
ctx.stroke()
let i, p
for(i = 0; i < smokes.length; i++) {
if(smokes[i] < 0.0001) continue;
p = projection([lons[i], lats[i]])
if(!p) continue;
ctx.fillStyle = color(smokes[i])
ctx.fillRect(p[0], p[1], 1, 1)
}
return canvas
}
Insert cell
data = FileAttachment("2026500000100_latlon.nc").arrayBuffer()
Insert cell
reader = new NetCDFReader(data)
Insert cell
reader.variables
Insert cell
lats = reader.getDataVariable("lat")
Insert cell
lons = reader.getDataVariable("lon")
Insert cell
smokes = reader.getDataVariable("Column-integrated_mass_density_UnknownLevelType-200")
Insert cell
smokeExtent = d3.extent(smokes)
Insert cell
d3.bin()(smokes).map(d => [d.x0, d.x1, d.length])
Insert cell
color = d3.scaleSequential(d3.interpolateMagma)
.domain([smokeExtent[1], smokeExtent[0]])
Insert cell
opacity = d3.scaleLinear()
.domain(smokeExtent)
.range([0, 1])
Insert cell
projection = d3.geoAlbersUsa()
.fitSize([width, height], states.features.filter(d => d.properties.name == "California")[0])
Insert cell
us = d3.json("https://unpkg.com/us-atlas@3/counties-10m.json")
Insert cell
states = topojson.feature(us, us.objects.states)
Insert cell
height = 500
Insert cell
d3 = require("d3@6")
Insert cell
topojson = require("topojson-client")
Insert cell
NetCDFReader = require('netcdfjs@1.0.0/dist/netcdfjs.js')
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