Published
Edited
Sep 24, 2020
1 fork
2 stars
Insert cell
Insert cell
import { HTTPFileChunkStore } from '@manzt/zarr-js-file-chunk-store'
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chunkstore = await fetch(url + '.zchunkstore').then(res => res.json())
Insert cell
pyramid = {
// Init store
const chunkstore = await fetch(url + '.zchunkstore').then(res => res.json());
const store = new HTTPFileChunkStore(url, chunkstore);

// get pyramidal paths
const rootAttrs = await getJson(store, '.zattrs');
const { datasets } = rootAttrs.multiscales[0];

return Promise.all(
datasets.map(({ path }) => zarr.openArray({ store, path }))
);
}
Insert cell
Insert cell
Insert cell
Insert cell
draw_scan(pyramid[4])
Insert cell
async function draw_scan(z_arr, channels = [0, 1, 3]) {
// Fetch the 2D pixel arrays for each channel
const [r, g, b] = await Promise.all(
channels.map(c => z_arr.getRaw([c, null, null]))
);
// Need to interleave the channels in RGBA buffer...
const rgba = new Uint8ClampedArray(4 * r.data.length).fill(0);
let offset = 0;
for (let i = 0; i < r.data.length; i++) {
rgba[offset] = r.data[i];
rgba[offset + 1] = g.data[i];
rgba[offset + 2] = b.data[i];
rgba[offset + 3] = 255; // alpha
offset += 4;
}
// Create image and draw to canvas
const img = new ImageData(rgba, z_arr.shape[2], z_arr.shape[1]);
const context = DOM.context2d(img.width / 2, img.height / 2);
context.putImageData(img, 0, 0);
return context.canvas;
}
Insert cell
Insert cell
Insert cell
zarr = import('zarr@0.3')
Insert cell
import { table } from '@tmcw/tables'
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