Skip to content

Commit 17ad080

Browse files
committed
Add blobs notebook for image rendering
1 parent 83fa4bb commit 17ad080

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"nbsphinx": "hidden"
7+
},
8+
"source": [
9+
"# Vitessce Widget Tutorial"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Visualization of a SpatialData object"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"## Import dependencies\n"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"import spatialdata"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"sdata = spatialdata.datasets.blobs()"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"from os.path import join"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"spatialdata_filepath = join(\"data\", \"blobs.spatialdata.zarr\")"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"sdata.write(spatialdata_filepath)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"sdata.table.uns"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"from vitessce import (\n",
87+
" VitessceConfig,\n",
88+
" ViewType as vt,\n",
89+
" CoordinationType as ct,\n",
90+
" CoordinationLevel as CL,\n",
91+
" SpatialDataWrapper,\n",
92+
" get_initial_coordination_scope_prefix\n",
93+
")"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"## Configure Vitessce\n",
101+
"\n",
102+
"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."
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"vc = VitessceConfig(\n",
112+
" schema_version=\"1.0.16\",\n",
113+
" name='Visium SpatialData Demo (blobs)',\n",
114+
")\n",
115+
"# Add data to the configuration:\n",
116+
"wrapper = SpatialDataWrapper(\n",
117+
" sdata_path=spatialdata_filepath,\n",
118+
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
119+
" image_path=\"images/blobs_image\",\n",
120+
" labels_path=\"labels/blobs_labels\",\n",
121+
" coordinate_system=\"global\",\n",
122+
" coordination_values={\n",
123+
" \"obsType\": \"blob\",\n",
124+
" \"fileUid\": \"my_unique_id\"\n",
125+
" }\n",
126+
")\n",
127+
"dataset = vc.add_dataset(name='Blobs').add_object(wrapper)\n",
128+
"\n",
129+
"# Add views (visualizations) to the configuration:\n",
130+
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
131+
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
132+
"\n",
133+
"vc.link_views_by_dict([spatial, layer_controller], {\n",
134+
" 'imageLayer': CL([{\n",
135+
" \"fileUid\": \"my_unique_id\",\n",
136+
" 'photometricInterpretation': 'BlackIsZero',\n",
137+
" 'spatialLayerOpacity': 0.9,\n",
138+
" 'imageChannel': CL([\n",
139+
" {\n",
140+
" \"spatialTargetC\": 0,\n",
141+
" \"spatialChannelColor\": [255, 0, 0],\n",
142+
" \"spatialChannelOpacity\": 1.0\n",
143+
" }\n",
144+
" ])\n",
145+
" }]),\n",
146+
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
147+
"\n",
148+
"vc.link_views_by_dict([spatial, layer_controller], {\n",
149+
" 'segmentationLayer': CL([{\n",
150+
" 'segmentationChannel': CL([{\n",
151+
" 'spatialChannelVisible': False,\n",
152+
" 'obsType': 'blob',\n",
153+
" }]),\n",
154+
" }]),\n",
155+
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"obsSegmentations\"))\n",
156+
"\n",
157+
"# Layout the views\n",
158+
"vc.layout(spatial | layer_controller);"
159+
]
160+
},
161+
{
162+
"cell_type": "markdown",
163+
"metadata": {},
164+
"source": [
165+
"### Render the widget"
166+
]
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": null,
171+
"metadata": {},
172+
"outputs": [],
173+
"source": [
174+
"vw = vc.widget()\n",
175+
"vw"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
184+
},
185+
{
186+
"cell_type": "code",
187+
"execution_count": null,
188+
"metadata": {},
189+
"outputs": [],
190+
"source": []
191+
}
192+
],
193+
"metadata": {
194+
"kernelspec": {
195+
"display_name": "Python 3 (ipykernel)",
196+
"language": "python",
197+
"name": "python3"
198+
},
199+
"language_info": {
200+
"codemirror_mode": {
201+
"name": "ipython",
202+
"version": 3
203+
},
204+
"file_extension": ".py",
205+
"mimetype": "text/x-python",
206+
"name": "python",
207+
"nbconvert_exporter": "python",
208+
"pygments_lexer": "ipython3",
209+
"version": "3.9.20"
210+
}
211+
},
212+
"nbformat": 4,
213+
"nbformat_minor": 4
214+
}

0 commit comments

Comments
 (0)