Published
Edited
Aug 22, 2022
13 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plot.plotAPI({
duration: 100,
encoding: {
// color: {},
x : {
field : location === 'dropoff' ? 'x' : 'pickup.x',
transform: 'literal'
},
y : {
field : location === 'dropoff' ? 'y' : 'pickup.y',
transform: 'literal'
},
filter: {
field: "tod",
op: "within",
a: within,
b: time
}
}

})
Insert cell
time
Insert cell
plot = {
d3.select("#plot").selectAll("div").remove()
const plot = new Deepscatter("#plot", width, Math.floor(width * .75))
await plot.plotAPI({
"arrow_table" : plot_data_raw,
"background_color": [45, 0, 75],
"max_points": 4e6,
"alpha": 85,
point_size : 3,
background_color: "#0A1610",
zoom_balance: .5,
duration: 3000,
encoding: {
jitter_radius: {
constant: .02,
method: 'normal'
},
color: {
field: 'tod',
domain: [0, 1440],
range: 'rdbu'
},
x: {
field: 'x',
transform: 'literal'
},
y: {
field: 'y',
transform: 'literal'
}
}
})
return plot
}
Insert cell
client = DuckDBClient.of({coords: FileAttachment("taxi_coords.parquet")})
Insert cell
plot_data_raw = {
insert_data
await client.query("DROP SEQUENCE IF EXISTS serial")
await client.query("CREATE SEQUENCE serial START 1")


return client.query(`SELECT
nextval('serial')::FLOAT ix,
dropoff.x::FLOAT x,
((60 * HOUR(pickup_time) + MINUTE(pickup_time)))::FLOAT tod,
((DAY(pickup_time)))::FLOAT date,
-1 * dropoff.y::FLOAT y,
pickup.x::FLOAT "pickup.x",
-1 * pickup.y::FLOAT "pickup.y",
FROM
trips JOIN taxi_coords.parquet dropoff
ON (dropoff.location_id = trips.DOLocationID) JOIN taxi_coords.parquet pickup ON (pickup.location_id = trips.PULocationID) USING SAMPLE 2000000;`)
}
Insert cell
client
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
arrow = require("apache-arrow@9.0.0")
Insert cell
insert_data = {
const letter = color=="green" ? "l" : "t"
const columns = ["PULocationID", "DOLocationID", `${letter}pep_pickup_datetime as pickup_time`, `${letter}pep_dropoff_datetime as dropoff_time`, `'${color}' AS color`]
await client.query(`CREATE TABLE IF NOT EXISTS "${label}" AS SELECT ${columns.join(", ")} FROM parquet_scan('${fname}')`)
const all_tables = (await client.table("SHOW TABLES")).value.map(d => d['name']).filter(d => d.startsWith('green-') || d.startsWith("yellow-"))
const q = all_tables.map(d => `SELECT * FROM "${d}"`).join("\nUNION\n")
await client.query(`CREATE OR REPLACE VIEW "trips" AS ${q}`)
}
Insert cell
label = `${color}-${year}-${month}`
Insert cell
fname = `https://bmschmidt-cors-observable.herokuapp.com/https://d37ci6vzurychx.cloudfront.net/trip-data/${color}_tripdata_${year}-${("000" + month).slice(-2)}.parquet`
Insert cell
Deepscatter = import('https://benschmidt.org/deepscatter/deepscatter@2.4.0.js').then(d => d.default)
Insert cell
import {DuckDBClient} from '@cmudig/duckdb'
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