Published
Edited
Dec 14, 2020
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// notice how we are importing "zarr-lite/core'"
zarr = import('https://cdn.skypack.dev/@manzt/zarr-lite/core')
Insert cell
Insert cell
pyramid = {
const store = new zarr.HTTPStore(url); // can be _any_ zarr store
const rootAttrs = await zarr.getJson(store, '.zattrs');
let paths = [];
if ('multiscales' in rootAttrs) {
const { datasets } = rootAttrs.multiscales[0];
paths = datasets.map(d => d.path);
}
const p = paths.map(path => zarr.openArray({ store, path }));
return Promise.all(p);
}
Insert cell
Insert cell
Insert cell
z = pyramid[4]
Insert cell
chunkCoords = c => [0, c, 0, 0, 0]
Insert cell
draw_scan(z)
Insert cell
import { table } from '@tmcw/tables'
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.getRawChunk(chunkCoords(c)))
);
// 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 [height, width] = z_arr.chunks.slice(-2);
const img = new ImageData(rgba, width, height);
const context = DOM.context2d(img.width / 2, img.height / 2, null);
context.putImageData(img, 0, 0);
return context.canvas;
}
Insert cell
z.chunks.slice(-2)
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