-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate TIFF access into vitessce-image-viewer and Improve Metadata Caching #31
Changes from all commits
0c33ec6
76abfd3
733218a
30b71bb
89ece6d
b717735
80a60a6
7927d49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,17 @@ export const source = { | |
height: 141, | ||
width: 206, | ||
tileSize: 256, | ||
// channels: { | ||
// channel_0: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_0", | ||
// channel_1: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_1", | ||
// channel_2: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_2", | ||
// channel_3: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_3", | ||
// }, | ||
channels: { | ||
channel_0: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_0", | ||
channel_1: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_1", | ||
channel_2: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_2", | ||
channel_3: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/single_channel_pyramid/img_pyramid/channel_3", | ||
channel_0: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/tiff-pyramid/vanderbilt_test_0.ome.tiff", | ||
channel_1: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/tiff-pyramid/vanderbilt_test_1.ome.tiff", | ||
channel_2: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/tiff-pyramid/vanderbilt_test_2.ome.tiff", | ||
channel_3: "https://vitessce-vanderbilt-data.storage.googleapis.com/test-data/vanderbilt-data/tiff-pyramid/vanderbilt_test_3.ome.tiff", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting to this data task today. Will do for repeated string. |
||
} | ||
|
||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import loadZarr from './zarr-utils'; | ||
import {loadZarr, getZarrConnections} from './zarr-utils'; | ||
import {loadTiff, getTiffConnections} from './tiff-utils'; | ||
|
||
export {loadZarr} | ||
export {loadZarr, loadTiff, getTiffConnections, getZarrConnections} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {fromUrl, Pool, getDecoder } from 'geotiff/dist/geotiff.bundle.min.js'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it something about their packaging that forces us to reference it this way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. People seem to have trouble with it |
||
|
||
async function loadTile({image, channel, x, y, pool}) { | ||
var tile = await image.getTileOrStrip(x,y, 0, pool) | ||
var dataObj = {} | ||
const is8Bits = image.fileDirectory.BitsPerSample[0]===8 | ||
const is16Bits = image.fileDirectory.BitsPerSample[0]===16 | ||
const is32Bits = image.fileDirectory.BitsPerSample[0]===32 | ||
dataObj[channel] = (is8Bits && new Uint8Array(tile.data)) || | ||
(is16Bits && new Uint16Array(tile.data)) || | ||
(is32Bits && new Uint32Array(tile.data)) | ||
return dataObj | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use semicolons... I know they're not really necessary in JS, but consistency is good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will run prettier/eslint later |
||
} | ||
|
||
export function loadTiff({connections, x, y, z, pool}){ | ||
const configListPromises = Object.keys(connections).map((channel) => { | ||
var image = connections[channel][z] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not use var. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will run prettier/eslint later |
||
return loadTile({image, channel, x, y, pool}) | ||
}) | ||
return Promise.all(configListPromises).then((dataList) => { | ||
const orderedList = [] | ||
const dataObj = Object.assign({}, ...dataList) | ||
Object.keys(dataObj).sort().forEach((key) => { | ||
orderedList.push(dataObj[key]); | ||
}) | ||
return orderedList; | ||
}); | ||
} | ||
|
||
export function getTiffConnections({sourceChannels, maxZoom}){ | ||
const tiffConnections = Object.keys(sourceChannels).map(async (channel) => { | ||
var tiff = await fromUrl(sourceChannels[channel]) | ||
var imageObj = {} | ||
for(var i = 0; i < -maxZoom; i++) { | ||
var image = await tiff.getImage(i) | ||
if(!imageObj[channel]) { | ||
imageObj[channel] = [image] | ||
} else { | ||
imageObj[channel].push(image) | ||
} | ||
|
||
} | ||
return imageObj | ||
}) | ||
return Promise.all(tiffConnections) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import {BaseTileLayer} from '@deck.gl/layers'; | ||
import {Texture2D} from '@luma.gl/webgl' | ||
import GL from '@luma.gl/constants'; | ||
import { COORDINATE_SYSTEM } from 'deck.gl'; | ||
import { XRLayer } from '../xr-layer'; | ||
import {tileToBoundingBox} from './tiling-utils'; | ||
import {getTileIndices} from './tiling-utils'; | ||
import { loadZarr, loadTiff } from './data-utils'; | ||
|
||
const defaultProps = Object.assign({}, BaseTileLayer.defaultProps, { | ||
id: `microscopy-tile-layer`, | ||
pickable: false, | ||
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, | ||
maxZoom: 0, | ||
onViewportLoad: false, | ||
renderSubLayers: (props) => { | ||
const { | ||
bbox: { | ||
west, south, east, north, | ||
}, | ||
} = props.tile; | ||
const { sliderValues, data, colorValues } = props; | ||
const xrl = new XRLayer(props, { | ||
id: `XR-Layer-${west}-${south}-${east}-${north}`, | ||
pickable: false, | ||
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, | ||
rgbData: data, | ||
sliderValues, | ||
colorValues, | ||
bounds: [west, south, east, north], | ||
visible: true, | ||
}); | ||
return xrl; | ||
}, | ||
}); | ||
|
||
export class MicroscopyViewerLayerBase extends BaseTileLayer { | ||
|
||
constructor(props) { | ||
const minZoom = Math.floor(-1 * Math.log2(Math.max(props.imageHeight, props.imageWidth))); | ||
const {sliderValues, colorValues} = props | ||
var orderedSliderValues = [] | ||
var orderedColorValues = [] | ||
Object.keys(sliderValues).sort().forEach(function(key) { | ||
orderedSliderValues.push(sliderValues[key]); | ||
}) | ||
Object.keys(colorValues).sort().forEach(function(key) { | ||
orderedColorValues.push(colorValues[key]); | ||
}) | ||
var diff = 6 - orderedSliderValues.length | ||
for (var i = 0; i < diff; i++) { | ||
orderedSliderValues.push(65535); | ||
} | ||
var diff = 6 - orderedColorValues.length | ||
for (var j = 0; j < diff; j++) { | ||
orderedColorValues.push([0,0,0]); | ||
} | ||
orderedColorValues = orderedColorValues.map(color => color.map(ch => ch / 255)) | ||
const getZarr = ({ x, y, z }) => { | ||
return loadZarr({ | ||
x, y, z: -1 * z, ...props, | ||
}); | ||
} | ||
const getTiff = ({ x, y, z }) => { | ||
return loadTiff({ | ||
x, y, z: -1 * z, ...props, | ||
}); | ||
} | ||
const getTileData = (props.useZarr && getZarr) || | ||
(props.useTiff && getTiff) || | ||
props.getTileData | ||
const overrideValuesProps = Object.assign( | ||
{}, props, { | ||
sliderValues: orderedSliderValues, | ||
colorValues: orderedColorValues, | ||
minZoom, | ||
getTileData, | ||
getTileIndices: (viewport, maxZoom, minZoom) => { | ||
return getTileIndices({ | ||
viewport, maxZoom, minZoom, ...props, | ||
}); | ||
}, | ||
tileToBoundingBox: (x, y, z) => { | ||
return tileToBoundingBox({ | ||
x, y, z, ...props, | ||
}); | ||
}, | ||
} | ||
) | ||
const layerProps = Object.assign({}, defaultProps, overrideValuesProps) | ||
super(layerProps) | ||
} | ||
|
||
} | ||
|
||
MicroscopyViewerLayerBase.layerName = 'MicroscopyViewerLayerBase'; | ||
MicroscopyViewerLayerBase.defaultProps = defaultProps; | ||
Comment on lines
+1
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy and pasted into a new file :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
useZarr
is out, for now? Update docs if so.