Public
Edited
Aug 14, 2023
Paused
1 star
Insert cell
Insert cell
Insert cell
Insert cell
refUrl = 'https://gist.githubusercontent.com/manzt/102eaa9652e181071d7e2c9fd0cc65d3/raw/5ae948a89c6bc78cbe57196ec8045cd1a988a0ff/LuCa-7color_Scan1.ome.tif_offsets.json'
Insert cell
// references v0
refs = fetch(refUrl).then(res => res.json())
Insert cell
// Initialize ReferenceStore
store = {
// Import `reference-spec-reader` module from CDN
const url = "https://esm.sh/@zarrita/storage/ref";
const { default: ReferenceStore } = await import(url);
return ReferenceStore.fromSpec(refs);
}
Insert cell
zarr = import("https://esm.sh/@zarrita/core")
Insert cell
// Open multiscale Zarr pyramid
pyramid = {
const grp = await zarr.open.v2(store, { kind: "gruop" });
const rootAttrs = await grp.attrs();
return Promise.all(
rootAttrs.multiscales[0].datasets.map(({ path }) =>
zarr.open.v2(grp.resolve(path), { kind: "array" })
)
);
}
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) => ops.get(z_arr, [c, null, null]))
);
console.log(z_arr.store);
// 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
ops = import("https://esm.sh/@zarrita/ndarray")
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