Skip to content

Commit

Permalink
Add blobs notebook for image rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Nov 12, 2024
1 parent 83fa4bb commit 17ad080
Showing 1 changed file with 214 additions and 0 deletions.
214 changes: 214 additions & 0 deletions docs/notebooks/spatial_data_blobs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"# Vitessce Widget Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualization of a SpatialData object"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import dependencies\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import spatialdata"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata = spatialdata.datasets.blobs()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from os.path import join"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spatialdata_filepath = join(\"data\", \"blobs.spatialdata.zarr\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata.write(spatialdata_filepath)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sdata.table.uns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from vitessce import (\n",
" VitessceConfig,\n",
" ViewType as vt,\n",
" CoordinationType as ct,\n",
" CoordinationLevel as CL,\n",
" SpatialDataWrapper,\n",
" get_initial_coordination_scope_prefix\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure Vitessce\n",
"\n",
"Vitessce needs to know which pieces of data we are interested in visualizing, the visualization types we would like to use, and how we want to coordinate (or link) the views."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vc = VitessceConfig(\n",
" schema_version=\"1.0.16\",\n",
" name='Visium SpatialData Demo (blobs)',\n",
")\n",
"# Add data to the configuration:\n",
"wrapper = SpatialDataWrapper(\n",
" sdata_path=spatialdata_filepath,\n",
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
" image_path=\"images/blobs_image\",\n",
" labels_path=\"labels/blobs_labels\",\n",
" coordinate_system=\"global\",\n",
" coordination_values={\n",
" \"obsType\": \"blob\",\n",
" \"fileUid\": \"my_unique_id\"\n",
" }\n",
")\n",
"dataset = vc.add_dataset(name='Blobs').add_object(wrapper)\n",
"\n",
"# Add views (visualizations) to the configuration:\n",
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
"\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'imageLayer': CL([{\n",
" \"fileUid\": \"my_unique_id\",\n",
" 'photometricInterpretation': 'BlackIsZero',\n",
" 'spatialLayerOpacity': 0.9,\n",
" 'imageChannel': CL([\n",
" {\n",
" \"spatialTargetC\": 0,\n",
" \"spatialChannelColor\": [255, 0, 0],\n",
" \"spatialChannelOpacity\": 1.0\n",
" }\n",
" ])\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
"\n",
"vc.link_views_by_dict([spatial, layer_controller], {\n",
" 'segmentationLayer': CL([{\n",
" 'segmentationChannel': CL([{\n",
" 'spatialChannelVisible': False,\n",
" 'obsType': 'blob',\n",
" }]),\n",
" }]),\n",
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n",
"\n",
"# Layout the views\n",
"vc.layout(spatial | layer_controller);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Render the widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vw = vc.widget()\n",
"vw"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.20"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 17ad080

Please sign in to comment.