Published unlisted
Edited
May 20, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
padding: 0,
x: XAxisFormat,
y: YAxisFormat,
color: PlotColor,
marks: [
Plot.cell(
AggregatedData,
{
x: (d) => d3.utcDay(d.date),
y: (d) => d3.utcMinute.count(d3.utcDay(d.date), d.date) / TimeResolution,
fill: (d) => d.count,
//inset: 0.5
}
)
],
style: {
//background: (PlotColor.type === "diverging" ? "lightgrey" : undefined)
}
})
Insert cell
Insert cell
Insert cell
Insert cell
StartDate = new Date(Date.UTC(2017, 0, 1))
Insert cell
Url = "https://herringrunner.s3.us-east-1.amazonaws.com/detections_summary.csv.gz"
Insert cell
Data = d3.csvParseRows(await fetch(Url).then((r) => r.text()), (d) => {
d = d.map((x) => +(x || 0)) // coerce everything to numeric

const date = new Date(d[0] * 1000) // convert Unix timestamp to Date
let counts = d.slice(1).concat(Array(10).fill(0)).slice(0, 10) // counts per confidence level
counts = d3.cumsum(counts.reverse()).reverse()
return [date, ...counts]
})
Insert cell
AggregatedData = {
const thresh = Math.trunc((ConfidenceThreshold - 50) / 5)

return Array.from(d3.rollup(
// Filter data to exclude frames with too few detections
d3.filter(Data, (d) => d[thresh + 1] >= DetectionThreshold),
// Aggregate all frames within the group
(v) => ({
date: TimeInterval.floor(v[0][0]), // start of time slice
count: v.length, // number of frames
// Note: for number of _fish_, sum across v[i][thresh+1]
}),
// Form groups based on the timestamp
(d) => TimeInterval.floor(d[0])
), ([key, value]) => value /* discard grouping keys */)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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